简体   繁体   中英

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.

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. Python only has access to the things you import. 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"

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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