Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Javascript to add A4 page to end of odd numbered PDFs

Community Beginner ,
Oct 06, 2022 Oct 06, 2022

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?

TOPICS
Edit and convert PDFs , How to , JavaScript
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 06, 2022 Oct 06, 2022

..instead, not "insstead"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 06, 2022 Oct 06, 2022

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 06, 2022 Oct 06, 2022

Use this:

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 06, 2022 Oct 06, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 06, 2022 Oct 06, 2022

That's more accurate, true...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 14, 2022 Oct 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 14, 2022 Oct 14, 2022

What script does you use?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 14, 2022 Oct 14, 2022

Hi, I was using 

if (this.numPages % 2) {

    this.newPage();

}

which added to the end but was not A4, then Ive tried 

 

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

 

..am I missing part of the script?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 14, 2022 Oct 14, 2022

Hi, I have it to the end using

 

if (this.numPages % 2) {

this.newPage(11.62*72, 8.70*72);

}

 

is it just a case of tweaking (11.62*72, 8.70*72 to get an A4 size?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 14, 2022 Oct 14, 2022

Try this one:

 

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


Acrobate du PDF, InDesigner et Photoshopographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 14, 2022 Oct 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 14, 2022 Oct 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.

 

Capture_2210141437.png


Acrobate du PDF, InDesigner et Photoshopographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 14, 2022 Oct 14, 2022
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines