python - PyPDF2, Set PDF version -
i'm using pypdf2 1.4, , python 2.7:
how can change pdf version input file output file?
from pypdf2 import pdffilewriter, pdffilereader pypdf2.generic import nameobject, createstringobject input_filename = 'my_input_filename.pdf' # read input pdf file inputpdf = pdffilereader(open(input_filename, 'rb')) info = inputpdf.documentinfo in xrange(inputpdf.numpages): # create output pdf outputpdf = pdffilewriter() # create dictionary output pdf infodict = outputpdf._info.getobject() # update output pdf metadata input pdf metadata key in info: infodict.update({nameobject(key): createstringobject(info[key])}) outputpdf.addpage(inputpdf.getpage(i)) open(output_filename , 'wb') outputstream: outputpdf.write(outputstream)
pypdf2 in current versions can't produce files pdf1.3 header; the official source code : class pdffilewriter(object):
""" class supports writing pdf files out, given pages produced class (typically :class:`pdffilereader<pdffilereader>`). """ def __init__(self): self._header = b_("%pdf-1.3") ...
if legal, considering gives ability feed in >1.3 things, questionable.
if want fix version string in header (i don't know consequences have, assume know more pdf standard do!)
from pypdf2.utils import b_ ... outputpdf._header.replace(b_("pdf-1.3"),b_("pdf-1.5"))
or of like.
Comments
Post a Comment