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

Resize image in PDF using JavaScript

New Here ,
Jun 18, 2023 Jun 18, 2023

Hi!

 

I'm familiar with JS in browsers, but reading the doc for Acrobat I couldn't figure out how to do it.

 

I have a PDF with thousands of pages, all page containing a single png and possibly a text field.

How do you select a specific object in JS and resize it?

 

Trying to mimic the selecting image, then dragging from its corner action programatically.

 

Cheers

 

TOPICS
Edit and convert PDFs , How to , JavaScript , PDF
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
LEGEND ,
Jun 18, 2023 Jun 18, 2023

Acrobat JavaScript has no access to the content of pages except

- the text in the page, via text extraction only

- annotations

- form fields

Low level access to page contents would be via the C++ API used to write plug-ins. Detailed study of the PDF specification would be needed to work with the PDFEdit layer. And also the forms layer if your text field is a field, but I suspect it's probably just text.

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
New Here ,
Jun 18, 2023 Jun 18, 2023

Thanks for the answer! I guess I'll have to find another way.

 

Do I have access to the size of the page with JS? If I could expand the page, the image might keep it's size, solving the problem.

 

Or would it be better to import PNGs using JS to a blank PDF (if this is a possibility), would that give it more control on the size of the imported image?

 

Any suggestion would be highly appreciated, as I would use this solution regularly, it's not for a on off occasion. Thanks!

 

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 ,
Jun 18, 2023 Jun 18, 2023
LATEST

>Do I have access to the size of the page with JS?

Yes, using the getPageBox method. Read the methods documentation for more details.

> If I could expand the page, the image might keep it's size, solving the problem.

No, it doesn't work like that. If you expand the page you'll end up with white space around the current contents.

What you can do, though, is create a new page and then use the old one as a watermark on it. That way you could stretch it to fit the size of the new page box.

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