Create a blank barcoded PDF to stamp over original input PDF with variable number of pages per record

Hi all

I have an issue where I have a large PDF that contains records with a variable number of pages (around 2200 pages in total). It is always an even number as we have to print duplex, so 2 pages for record 1, 6 pages for record 2, 4 pages for record 3 and so on. The requirement is to print an incremental sequenced barcode on each record set on the odd numbered pages per record. No problem, except that for what ever reason it takes many, many hours to process, time we don’t have.

The workaround for this issue is as below, thanks to hamelj, taken from another post:

"If the incoming file is very big, you could use the “stamping method” which consists of having your PDF as the data but not the background. The resulting new PDF (out of PlanetPress) would be the same amount of pages as the original but with only your OMR code and other changes on empty sheets. Then using a script, you actually stamp (merge one PDF on the other) to the original one.

Set MyOriginalPDF = Watch.GetPDFEditObject
MyOriginalPDF.Open Watch.GetJobFileName, False
MyOriginalPDF.MergeWith "My_Barcoded_Document.pdf"
MyOriginalPDF.Save False

All good there, except that because I’m using the input PDF as the data but not the background, the output PDF only creates 2 pages per record (as it is set to duplex). Therefore I’m left with an output PDF that is less pages than the original input PDF and thus cannot use the stamping method to overlay the original without some additional scripting.

Apparently this could possibly be done using some other functions below, however I’m a novice when it comes to scripting so if anyone has any code that could help it would be much appreciated

The function to use would be Merge2 (to stamp the new PDF pages on the original one) with a combination of InsertFrom2 (to insert the blank page from the new PDF into the original one). The definition of these functions can be found in the Alambic API.

The big problem using a script seems to be to know where the record changes, so what amount of pages of the input PDF belongs to a record.

So why not just having an OMR PDF (“My_Barcoded_Document.pdf”) which has the same amount of pages as the input PDF, so exactly matching the records of the original PDF?

I am currently working on a script (for an in house project) that will allow the stamping method to work with unequal number of pages between the source and newly (barcode) created PDF. As soon as my testing are done, I will post the code here.

The would be great. I appreciate it

Just found you a solution for your page number problem due to not using a background.

  • In your datamapper, add a javascript field that will use the following code: steps.totalPages.toString();
  • In your Template, add a section with nothing on it.
  • Add a control script that will handle the blank pages (the new section)

Here is the script (you might need to adapt it. Mine was that the barcode was on the first PDF page of a set.)

var section2 = merge.template.contexts.PRINT.sections[“Section 2”];
section2.enabled = false;
if(record.fields.Field > 1){

for (var i = 0; i < record.fields.Field-1; i++) {
       var cloneSection = section2.clone();
       cloneSection.enabled = true;
       section2.addAfter(cloneSection);
}

}

With this, the number of pages of the incoming and outgoing PDF will be the same, thus being elligible to the stamping method.