Skip to main content
Known Participant
October 6, 2022
Question

Javascript to add A4 page to end of odd numbered PDFs

  • October 6, 2022
  • 6 replies
  • 1258 views

Hi, I'm currently using..

 

if (this.numPages % 2) {

    this.newPage();

}

 

..to add a blank to the end of odd numbered documents, this will add an 8.5"x11" page but I'd like to add an A4 insstead, is there a way to specify the page size added?

This topic has been closed for replies.

6 replies

JR Boulay
Community Expert
Community Expert
October 14, 2022

Sorry, you must remove the "-1" to put the new page at the end of the document:

 

if (this.numPages % 2) {this.newPage(this.numPages, 595,842);}

 

A4 size is 21 cm x 29,7 cm, so 595 x 842 is the closest conversion when you need to enter dimensions in points.

 

Acrobate du PDF, InDesigner et Photoshopographe
djbatsAuthor
Known Participant
October 14, 2022

..fab, I imagined this the case, many thanks for all your help with this.

JR Boulay
Community Expert
Community Expert
October 14, 2022

Try this one:

 

if (this.numPages % 2) {this.newPage(this.numPages-1, 595,842);}

Acrobate du PDF, InDesigner et Photoshopographe
djbatsAuthor
Known Participant
October 14, 2022

..thanks for that, this adds a 297mm x 279.4mm to the back,  I'm not sure what the relationship between 595,842 and 297x279 is, so I'm not sure how to tweak these figures to create an A4, 297mm x 210mm page.

JR Boulay
Community Expert
Community Expert
October 6, 2022

"this.newPage(11.6*72, 8.27*72);"

This is not A4 size 😉

 

Use this instead:

this.newPage(this.numPages-1, 595,842)

Acrobate du PDF, InDesigner et Photoshopographe
try67
Community Expert
Community Expert
October 6, 2022

That's more accurate, true...

djbatsAuthor
Known Participant
October 14, 2022

.. many thanks for that, the size is much better but it's not adding to the end of the file, it adds to the beginning and oddly on occasion inserts between other pages. I'm not sure how to modify the script to position the inserted page last.

try67
Community Expert
Community Expert
October 6, 2022

Use this:

this.newPage(11.6*72, 8.27*72);

Bernd Alheit
Community Expert
Community Expert
October 6, 2022

You can specify width and height as parameters of newPage. Look at the documentation of newPage.

djbatsAuthor
Known Participant
October 6, 2022

..instead, not "insstead"