我正在尝试从 PDF 文件中提取特定页面,并将其保存为不同的文件名。遵循此处提供的代码: https ://www.youtube.com/watch?v=W6Gt57b3Pp4&t=219s
from PyPDF2 import PdfFileReader, PdfFileWriter
pdf_file_path = "oranges.pdf"
file_base_name = pdf_file_path.replace(".pdf","")
pdf = PdfFileReader(pdf_file_path) #Creating PDF instance
pages = [0,2,4]
pdfwriter = PdfFileWriter() #Creating pdfWriter instance
print
for page_num in pages:
pdfwriter().addPage(pdf.getPage(page_num))
with open("{0}_subset".format(file_base_name),'wb') as f:
pdfwriter.write(f)
f.close
但是我在第 12 行收到了这个错误: TypeError: 'PdfFileWriter' object is not callable 我应该如何解决这个错误?