Remove 2nd page from PDF input

Hi there,

Is there a simpler way to remove a particular page from a pdf input?

For example if I do folder capture to pick up any PDF files in workflow, now I want to output it back to a folder but without the 2nd page but only the remaining ones as 1 pdf file. How would I do this?

Thank you for any help or steer to the right direction.
Kind regards,
E

Update:

Okay, what I did is added a PDF splitter and have an if branch text condition testing for %i == 1 (second page) and goes to delete and the rest sends to folder with concatenate file turned on.

My question is, is this efficient? Thank you

In case you would like to remove the second page from two page PDF documents you can use a Run Script Workflow plugin instead and apply the following JavaScript code to this Run Script Workflow plugin:

var pdfIn = Watch.GetPDFEditObject();
var pdfOut = Watch.GetPDFEditObject();

pdfIn.Open(Watch.GetJobFileName(), false);
pdfOut.Create(Watch.GetJobFileName() + ".copy.pdf");

// https://help.uplandsoftware.com/objectiflune/en/pres_workflow/2023.1/Workflow/Alambic_API/IPages_Methods.html#InsertFr2
pdfOut.Pages().InsertFrom2(pdfIn.Pages(), 0, 1, 0);

pdfOut.Save(true);

CollectGarbage();

pdfOut.Close();
pdfIn.Close();

var objFso = new ActiveXObject("Scripting.FileSystemObject");

objFso.DeleteFile(Watch.GetJobFileName());
objFso.CopyFile(Watch.GetJobFileName() + ".copy.pdf", Watch.GetJobFileName());

The above JavaScript code is based on the JavaScript code shared via this OL Learn forum post.

NOTE: Make sure to change the Language of the Run Script Workflow plugin to JScript before applying the above JavaScript code.

Actually, the JScript code is much simpler than that:

var pdf = Watch.GetPDFEditObject();
pdf.Open(Watch.GetJobFileName(),false);
pdf.Pages().Delete(1);
pdf.Save(true);
CollectGarbage();
pdf.Close();

This will be much more efficient than the Splitter/Concatenate option, especially for larger PDF files.

2 Likes

Hi @Marten Marten,

Thank you

and @Phil this is much simpler! Im going to try this out and see if checks out :slight_smile:

You guys are awesome!
cheers!