How to insert pages from one pdf into another?

Hello,

how can I insert one or more pages from one pdf into another on a specific position (in Workflow), without splitting the pdfs? I know the way to split both pdfs based on metadata and merge them as I want, but in case of 5000 pages per pdf that’s not a viable option.

Example:
I have two pdf files. PDF1 has 8 pages, PDF2 has 3 pages. I want to insert page3 from PDF2 into PDF1 after page 2. After that I want to insert page1 from PDF2 into PDF1 after page4, and so on.

Maybe the Alambic API could help, but I don’t understand how to use it (http://help.objectiflune.com/files/EN/alambicedit-api/AlambicEdit.html#bea9162e7252744f50cc962c8538b0d4).

Thanks,
Thomas

Use a Run Script task in Workflow, set its language to JavaScript and copy/paste the following code:

// Open Current Job file as the PDF to modify
var PDF1 = Watch.GetPDFEditObject();
PDF1.Open(Watch.GetJobFileName(),false);

// Open Second PDF file containing the pages to add to the first one
var PDF2 = Watch.GetPDFEditObject();
PDF2.Open("C:\\Test\\PDF3Pages.pdf",false);

// Insert the pages: start from the end so as not to screw up the page indexes
// The PDF library uses 0-based indexing, i.e. the first page in a PDF
// is Page 0
PDF1.Pages().InsertFrom2(PDF2.Pages(),1,1,8);
PDF1.Pages().InsertFrom2(PDF2.Pages(),0,1,4);
PDF1.Pages().InsertFrom2(PDF2.Pages(),2,1,2);
PDF1.Save(false);

PDF1.Close();
PDF2.Close();

Thanks for your answer. It works like a charm!