Resize image in PDF using JavaScript
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
>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.

