我正在尝试将8.5“ x11” pdf裁剪为明信片尺寸为4.25“ x6”,然后将裁剪的pdf上传到在线印刷公司。
我能够使用PyPDF2裁剪pdf。当我打开裁剪的pdf时,它看起来像正确的尺寸,并且在页面属性中,页面尺寸具有正确的尺寸。但是,当我尝试将裁剪的pdf上传到打印机时,出现页面大小为8.5“ x11”的错误。
我在Word中创建了具有正确页面尺寸的测试文档,然后将其导出为pdf,然后可以将其正确上传到打印机Web门户。
裁剪后的文档中保留的原始页面尺寸是什么?如何更改以匹配裁剪后的区域?
我的代码如下:
import PyPDF2
from PyPDF2 import PdfFileReader, PdfFileWriter
# Create a pdf object
pdfFileObj = open('document.pdf', 'rb')
# read the pdf object
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
# create pdf writer object
writerObj = PdfFileWriter()
page = pdfReader.getPage(1)
page.cropBox.setLowerLeft((0, 0))
page.cropBox.setLowerRight((306, 0))
page.cropBox.setUpperLeft((0, 432))
page.cropBox.setUpperRight((306, 432))
# Write the new page
writerObj.addPage(page)
# Create an output pdf
outstream = open('postcardsCropped.pdf', 'wb')
writerObj.write(outstream)
outstream.close()
答案 0 :(得分:0)
如果使用页面对象的scaleTo()方法,它将为您处理更改mediaBox,cropBox,artBox和bleedBox的大小。您只需要在点尺寸中传递新的宽度,高度参数即可。就您而言,应该是
page.scaleTo(4.25*72, 6*72) #1 inch = 72 points.