简体   繁体   English

PyPDF2 'PageObject' 未定义

[英]PyPDF2 'PageObject' is not defined

I've been using PyPDF2 (version 1.26.0) to create new PDFs with no problems so far: rotating, cropping pages and more.到目前为止,我一直在使用 PyPDF2(版本 1.26.0)创建新的 PDF,没有任何问题:旋转、裁剪页面等等。

For some reason, the second line throws an error:出于某种原因,第二行抛出了一个错误:

from PyPDF2 import PdfFileWriter, PdfFileReader

page = PageObject.createBlankPage(100, 100)

Being the error the following:错误如下:

NameError: name 'PageObject' is not defined

Why could this be happening?为什么会发生这种情况?

It seems like you aren't importing the PageObject class.您似乎没有导入 PageObject 类。 Python only has access to the things you import. Python 只能访问您导入的内容。 Please add this to the top of your file:请将此添加到您的文件的顶部:

from PyPDF2.pdf import PageObject

I found another way to achieve what I wanted, using PdfFileWriter's "addBlankPage"我找到了另一种方法来实现我想要的,使用 PdfFileWriter 的“addBlankPage”

from PyPDF2 import PdfFileWriter, PdfFileReader
output = PdfFileWriter()
output.addBlankPage(100, 100)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM