View Single Post
Old 09-07-2014, 11:03 AM   #5
ksiflhjla8
Connoisseur
ksiflhjla8 can differentiate black from dark navy blueksiflhjla8 can differentiate black from dark navy blueksiflhjla8 can differentiate black from dark navy blueksiflhjla8 can differentiate black from dark navy blueksiflhjla8 can differentiate black from dark navy blueksiflhjla8 can differentiate black from dark navy blueksiflhjla8 can differentiate black from dark navy blueksiflhjla8 can differentiate black from dark navy blueksiflhjla8 can differentiate black from dark navy blueksiflhjla8 can differentiate black from dark navy blueksiflhjla8 can differentiate black from dark navy blue
 
Posts: 59
Karma: 13124
Join Date: Jul 2008
Device: Kobo Aura HD
Yes, if you add a bigger page at the beginning of the pdf, it doesn't crop anymore. I've seen this bug for a long time, though


Python hack to add an empty page with size of biggest page in pdf.
PyPDF2 needed: https://github.com/mstamy2/PyPDF2
Code:
import PyPDF2
import sys

ifile = sys.argv[1]

pdfinput  = PyPDF2.PdfFileReader(open(ifile, "rb"))
pdfoutput = PyPDF2.PdfFileWriter()

print pdfinput.getDocumentInfo()
n = pdfinput.getNumPages()
maxw = 0
maxh = 0
page0 = pdfinput.getPage(0)

for i in range(n):
    page = pdfinput.getPage(i)
    w = page.cropBox.getWidth()
    h = page.cropBox.getHeight()
    if w > maxw: maxw = w
    if h > maxh: maxh = h

print maxw, maxh
firstpage = page0.createBlankPage(None,float(maxw),float(maxh))

print "writing ..."
pdfoutput.addPage(firstpage)
for i in range(n):
    page = pdfinput.getPage(i)
    pdfoutput.addPage(page)

# finally, write "output" to document-output.pdf
outputStream = file("document-output.pdf", "wb")
pdfoutput.write(outputStream)

Last edited by ksiflhjla8; 09-07-2014 at 12:16 PM.
ksiflhjla8 is offline   Reply With Quote