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

Need Javascript for shrinking document

Explorer ,
Apr 15, 2024 Apr 15, 2024

Copy link to clipboard

Copied

Is there a way to achieve shrinking the appearance of a pdf document using javascript? I am bascially trying to achieve the function available in the Add Header and Footer action (shown below) in javascript instead of the action.  I looked in the Adobe Acrobat API reference guide but only see examples related to making pdf fit to page. I am using Windows 10 and Adobe Acrobat Pro.

 

suemo22_0-1713195706579.png

 

TOPICS
JavaScript

Views

635

Translate

Translate

Report

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 ,
Apr 15, 2024 Apr 15, 2024

Copy link to clipboard

Copied

Yes, there is a way to do this. There is no functionality in the Acrobat JavaScript model for directly scaling page content. But there are a couple of techniques. Both button fields and watermarks scale images. The watermark technique is the simplest, but like most complex operations in JS, it has a weirdness.

 

Create a new page of the desired size. The page dimensions must of course maintain the original aspect ratio. Then use the watermark function to place the source page content over new page.  The issue with this technique is that watermarks are also OCG layers. To use this technique to scale all pages in a document will require renaming the OCG layer.

 

You can read about OCGs and the watermark function here:

http://acrobatusers.com/tutorials/create_use_layers

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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
Explorer ,
Apr 15, 2024 Apr 15, 2024

Copy link to clipboard

Copied

Thank you for your reply. I will look into this. Out of curiousity, is there an action that accomplishes this? I know the "Add Header and Footer" action accomplishes this but the downfall is that it removes any existing header and footer, which I don't want it to do. Thanks in advance.

 

Sue

Votes

Translate

Translate

Report

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 ,
Apr 15, 2024 Apr 15, 2024

Copy link to clipboard

Copied

Any built-in function that might do something useful as a side affect is not reliable for performing that side affect as your main use of the fuction.  So no, I don't know of any other Acrobat feature that might scale pages nor would I suggest using one if I did. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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 ,
Apr 15, 2024 Apr 15, 2024

Copy link to clipboard

Copied

Scaling can also be achieved using the Preflight tool, which can be triggered using a script. However, it has to be a fixed size. It can't automatically decide what size to scale the pages to based on the white margins of the page, like the Add Header and Footer tool can.

Votes

Translate

Translate

Report

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 ,
Apr 15, 2024 Apr 15, 2024

Copy link to clipboard

Copied

Good one, I always forget about preflight. Yeah Callas!!

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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
Explorer ,
Sep 20, 2024 Sep 20, 2024

Copy link to clipboard

Copied

decided to post questions elsewhere.

Votes

Translate

Translate

Report

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 ,
Sep 21, 2024 Sep 21, 2024

Copy link to clipboard

Copied

There is a way to shrink documents with a script. In fact there are two ways. However, it's not a single function. 

A script can be written to create a new PDF with pages resized in any way. 

 

In both methods, the script first creates a new PDF with blank pages. Then do one of two things.

 

Method #1 -  Place button fields on each page of the new PDF that are the exact size of the desired shrink.

     ** Load the pages of the source PDF as images into the buttons. 

     ** then flatten the PDF.

 

Method #2 -  Add the pages of the source PDF to the Pages of the new PDF as watermarks. 

 

  

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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
Explorer ,
Sep 22, 2024 Sep 22, 2024

Copy link to clipboard

Copied

LATEST

Hello,

I appreciate you sharing these methods. However, I am not allowed to add a page to each document in the batch. I have to maintain the integrity of the page as it is a legal file. Thanks for trying.

 

Sue

Votes

Translate

Translate

Report

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