Add a Single page PDF to a single and multipage PDF using Javascript in PresWorkflow

Hi, I need to add a single page PDF (back page) to every other page in a PDF file. Some of the PDF files are single pages and some are variable, regardless they all need the backer page added after every page.

Ex. single page PDF would have a single backer page added (1 page = 2)
Ex. multi page PDF would get a backer page after every page (5 pages = 10 backers)

Go to your Section Sheet Configuration and tick the Duplexing while the 3 sub choices unticked.

Setup the Master Page front and Master Page back to what you’d like. Also make sure that Allow content on is set to Front only.

Hi, because of the volume of records I need to do this with javascript (using the External Script plugin) and have seen some examples on the user community, (see below) however not sure how to use the example below for my document.

// 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(“D:\KPM-\ExampleJobs[customer path]\Invoice_ReverseSideText_Apr2022_INSERT.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(),0,1,1);
PDF1.Save(false);
PDF1.Close();
PDF2.Close();

Yep, that example is slightly incomplete. Use the following code:

// Open PDF in which pages are added
var PDF1 = Watch.GetPDFEditObject();
PDF1.Open(Watch.GetJobFileName(),false);
var totalPages = PDF1.Pages().Count();

// Open PDF containing the page to add
var PDF2 = Watch.GetPDFEditObject();
PDF2.Open("C:\\Test\\OnePage.pdf",false); // Set the path and name to the proper file

// Loop backward through all pages, starting from the end, and add the page
for(var i = totalPages; i>0; i--){
  PDF1.Pages().InsertFrom2(PDF2.Pages(),0,1,i);
}

// Clean up
PDF1.Save(false);
PDF1.Close();
PDF2.Close();

works like a charm Phil…thanks for the quick response and assistance with this post…much appreciated!