Deleting pages from PDF file through Acrobat automation

Detailed info on Acrobat automation can be found in Interapplication Communication API Reference from Acrobat 8.1 SDK or Acrobat 9.0 SDK at http://www.adobe.com/devnet/acrobat/?navID=downloads. Free registration may be required.

This is sample code. Add error handling and adjust to your requirements as necessary.

#DEFINE PDSaveFull	1	&& Write the entire file.

* Original PDF file
lcPdfFile = "..."
* new PDF file with specified pages deleted
lcNewPdfFile = "..."
 
* Delete 3 pages starting with page 5
lnPage2DelStart = 5
lnPage2DelEnd = lnPage2DelStart + 3
* Acrobat application
loAcroApp = CREATEOBJECT("AcroExch.App")
*loAcroApp.Show()
 
* A view of a PDF document in a window
loAVDoc = CREATEOBJECT("AcroExch.AVDoc")
IF loAVDoc.Open(lcPdfFile, "PDF") == 0
  * Error, cannot open the file
  * Do something ...
ENDIF
 
* The underlying PDF representation of a document
loPDDoc = loAVDoc.GetPDDoc()
* Delete specified pages. The page numbers are zero based
IF loPDDoc.DeletePages(lnPage2DelStart-1, lnPage2DelEnd-1) == 0
  * Error, cannot delete pages
  * Do something ...
ENDIF
 
* Save to new PDF file and close
loPDDoc.Save(PDSaveFull, lcNewPdfFile)                            && PDF document
loPDDoc.Close()
 
* Close PDF view w/o prompt to save
loAVDoc.Close(.T.)
* Close Acrobat. 
loAcroApp.Exit()

Comments

Hi Guys, nice sight... wonderful information. I am looking to hire a consultant to help with a pdf problem.
I would like to use FoxPro Automation to convert an 8.5x11 3 page pdf into a 4 page 11x17 pdf so we can laser print properly.
Anyone take pity and share some of that wonderful knowledge? I can provide samples and much more info if anyone would like to help.

My email is cburkhart@ricklanddirect.com

Thanks very much.... stay Foxy !

Add new comment

Filtered HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.