Copy link to clipboard
Copied
Hi helpful legends,
I am using Acrobat Pro DC (version 2021.005.20058).
I am trying to automate a process to make cover images from a folder of PDFs. I want an action that will process each PDF within a given folder to extract page 1, convert that to JPEG and save in a different folder.
I have been poking around the interwebz for a while tonight but my understanding of javascript is close to zero so I'm hitting a wall. I can see that this should be possible, but I can't make it work.
I have found a script that extracts page 1 and saves it to the same folder as a PDF:
this.extractPages(0, 0, this.path.replace(/\.pdf$/i, "_p1.pdf"));
I also found a separate action that converts PDFs to JPEGs. I can do those sequentially and get the job done, but it requires a bit of fiddling around with sorting files to process only the ones I want into JPEGs.
I would love to get an all-in-one script that would convert page 1 into a jpeg in one action, so I can share an easy-to-use solution with my colleagues.
Any wonderful coders out there who can help? Thank you so much!
Copy link to clipboard
Copied
One possible way of doing it is to delete all the other pages in the file, and then save the only remaining page (which is the first page from the original file) as a JPEG. You can do it like this:
if (this.numPages>1) this.deletePages(1, this.numPages-1);
this.saveAs({cPath: this.path.replace(".pdf", "_p1.jpg"), cConvID: "com.adobe.acrobat.jpeg"});
this.dirty = false;
If you run it as a part of an Action then you could use it on multiple files, and since there's no save command added to it, the original files will remain in tact.
Edited: Full code added, for future reference.
Copy link to clipboard
Copied
One possible way of doing it is to delete all the other pages in the file, and then save the only remaining page (which is the first page from the original file) as a JPEG. You can do it like this:
if (this.numPages>1) this.deletePages(1, this.numPages-1);
this.saveAs({cPath: this.path.replace(".pdf", "_p1.jpg"), cConvID: "com.adobe.acrobat.jpeg"});
this.dirty = false;
If you run it as a part of an Action then you could use it on multiple files, and since there's no save command added to it, the original files will remain in tact.
Edited: Full code added, for future reference.
Copy link to clipboard
Copied
@try67, thank you so much for helping me with this! This solution is close, which is making me very excited. There are a couple of issues still:
Is there any way to tweak it to get those outcomes? I can't ask users to sit there and click 'No' 63 times every time they run this 🙂
Thank you again so much. I cannot tell you how much time and tedious manual effort this will save if we can get it to work! Really appreciate your help.
Copy link to clipboard
Copied
1. Add this:
this.dirty = false;
Copy link to clipboard
Copied
Thank you so much @Bernd Alheit, that does indeed fix issue #1. Yay!
Now the only issue is it not handling 1-page documents. This is not a dealbreaker as I could just use the plain 'Convert PDF to JPEG' action on those. It would just be neater to have one action to rule them all when creating cover images.
Copy link to clipboard
Copied
2. Add this to the start of the code:
if (this.numPages>1)
Copy link to clipboard
Copied
You'll find an Action for extracting the first page of a document here:
https://acrobatusers.com/actions-exchange/
Copy link to clipboard
Copied
Thank you so much everyone for your contributions! It is so exciting to have this solved. This is going to really help my team's workflow and I am incredibly grateful to you all. THANK YOU.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now