[Info-vax] Modifying PDF files.

Jan-Erik Soderholm jan-erik.soderholm at telia.com
Sun Aug 28 17:16:31 EDT 2011


Damn, wrong button and posted to soon...
Text added below.
Sorry...
Jan-Erik.


-------------------------------------------------------------
Jan-Erik Soderholm wrote 2011-08-28 23:08:

I think someone some months ago asked about making
changes to PDF files. Such as merging two files
or extracting a few pages or something.

I today had the need to extract two pages (page 17 and 18)
from a 43 page 15 MB PDF file to save bandwith when downloaded
from my site. It was this PDF from "AP Products" :
http://www.ap-products.com/pdf/HEADER/Headers-Set-07-2008.pdf

Now, I think you have guessed it, the Python port for VMS has
a nice PDF tool PyPdf alread installed. I made a quick script
from the examples on: "http://pybrary.net/pyPdf/" and it worked
at the first try. I got this 2 page 1 MB PDF file :
http://jescab2.dyndns.org/pub_docs/14_pin_header.pdf

using this Python script (or rather command file) :

----------------------------------------------------------------
$ python

from pyPdf import PdfFileWriter, PdfFileReader

output = PdfFileWriter()

input1 = PdfFileReader(file("HEADERS_SET_07_2008.PDF", "rb"))

output.addPage(input1.getPage(16))
output.addPage(input1.getPage(17))

outputStream = file("14_PIN_HEADER.PDF", "wb")
output.write(outputStream)
outputStream.close()
----------------------------------------------------------------

Note that PyPdf seems to count pages from "0", so I had to
specifiy 16 and 17 for page 17-18.

Anyway, quite OK for 8 lines of code, I think.

Jan-Erik.









More information about the Info-vax mailing list