Delete pages from a pdf

Started by MW4, December 11, 2018, 04:11:35 PM

Previous topic - Next topic

MW4

I have a need to delete every 3rd-6th page of a pdf.

So if it is six pages to start it will end as a two pager (1&2), and if it is 18 pages, end up as a six pager ( 1 & 2, 7 & 8,  13 & 14 ), PDF could be any length of 6x

My question is two pronged... 

1. setting a control structure to set what pages to delete 

2. how to delete the pages in the pdf itself.

Any direction would be greatly appreciated.


td

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

MW4

Yeah, I saw that before posting, but couldn't get it working for my use.

I wanted to see if someone else had already gone down this road before I started a trial and error...mostly error process. :)

td

You are not alone.  It kinda goes with the writing-software territory.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

MW4

This works fine...a bit clunky but it works.


Code (winbatch) Select


adobe = ObjectCreate("AcroExch.app")      ; create an application object
PDF = ObjectCreate("AcroExch.pdDoc")

PDFFileName = "Y:\Data\Test\PDFS\a.pdf"
t1 = PDF.open(PDFFileName)

PDF_NumPages = PDF.GetNumPages()
message("pages",PDF_NumPages)

if PDF_NumPages == 6
t1 = PDF.DeletePages (2,5)  ;Delete Pages 3 to 6 (index starts at 0)
t1 = PDF.save(1,"Y:\Data\Test\PDFS\a.pdf")
endif

if PDF_NumPages == 12
t1 = PDF.DeletePages (2,5)  ;Delete Pages 3 to 6 (index starts at 0)
t1 = PDF.save(1,"Y:\Data\Test\PDFS\a.pdf")
t1 = PDF.DeletePages (4,7)  ;Delete Pages 5 to 8 (index starts at 0)
t1 = PDF.save(1,"Y:\Data\Test\PDFS\a.pdf")
endif

if PDF_NumPages == 18
t1 = PDF.DeletePages (2,5)  ;Delete Pages 3 to 6 (index starts at 0)
t1 = PDF.save(1,"Y:\Data\Test\PDFS\a.pdf")
t1 = PDF.DeletePages (4,7)  ;Delete Pages 5 to 8 (index starts at 0)
t1 = PDF.save(1,"Y:\Data\Test\PDFS\a.pdf")
t1 = PDF.DeletePages (6,9)  ;Delete Pages 7 to 10 (index starts at 0)
t1 = PDF.save(1,"Y:\Data\Test\PDFS\a.pdf")
endif

PDF.close

adobe.exit; exit the application

adobe = ""      ; close the application object
FirstPDF = ""      ; close the application object