Hi
I’m doing a script that opens a PDF and deletes every page from it other than page 1. The following is a snippet of the script that I’ve done that sort of does this.
tell application "Adobe Acrobat 7.0 Professional"
open preview_file
set page_count to page count
if page_count is greater than 1 then
repeat until page_count is equal to 1
delete last page of document 1
set page_count to page count
end repeat
end if
close document 1 saving yes
end tell
It basically gets the page count and then keeps deleting the last page until the page count = 1. This is fine for smaller PDFs but I’d rather be able to tell it to delete a range of pages in one go, e.g.,
delete (pages 2 thru page_count) of document 1
But it doesn’t seem to work. Does anyone have any ideas on how to do this and if it is possible?
ta!
tell application "Acrobat 6.0.2 Professional"
activate
set docRef to the front document
set PageCount to page count
delete pages docRef first 2 last PageCount
close document 1 saving yes
end tell
Am using this script (which works for me in Acrobat X).
tell application "Acrobat 6.0.2 Professional"
activate
set docRef to the front document
set PageCount to page count
delete pages docRef first 2 last PageCount
close document 1 saving yes
end tell
But when I delete pages, the size of the PDF does not change. So if PDF was 1MB with 30 pages, and I delete 2-29, the resulting PDF is 1 page only but is still 1MB in size.
If I manually go into Acrobat, delete pages 2-29 and manually save. The file is a fraction of the size (as you would expect).
An awfully late answer to your last question, but…
When changes are made to a PDF in Acrobat, it marks the changed stuff internally in the file but does not delete it. You have to do a “Save As…” to have that stuff removed. So when you delete the pages, they aren’t deleted from the file structure but are marked as being deleted so they don’t display or print. Once you Save As, they are actually deleted from the file structure and your file size will shrink accordingly.