Author Topic: Delete pages from a pdf  (Read 83 times)

MW4

  • Full Member
  • ***
  • Posts: 163
Delete pages from a pdf
« on: December 11, 2018, 04:11:35 pm »
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

  • Tech Support
  • *****
  • Posts: 2689
    • WinBatch
Re: Delete pages from a pdf
« Reply #1 on: December 11, 2018, 05:15:00 pm »
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


MW4

  • Full Member
  • ***
  • Posts: 163
Re: Delete pages from a pdf
« Reply #2 on: December 12, 2018, 01:07:00 pm »
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

  • Tech Support
  • *****
  • Posts: 2689
    • WinBatch
Re: Delete pages from a pdf
« Reply #3 on: December 12, 2018, 01:15:06 pm »
You are not alone.  It kinda goes with the writing-software territory.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


MW4

  • Full Member
  • ***
  • Posts: 163
Re: Delete pages from a pdf
« Reply #4 on: December 27, 2018, 11:38:05 am »
This works fine...a bit clunky but it works.


Code: Winbatch
         

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