0

I need to write in a new PDF the content of each page.

In 'curr_page' i am saving the PageObject of each Page, but when i try to write it in a new one i receive the error of that "addPage needs an argument". But i am giving it the argument, which should be an PageObject.

Some thoughts?

pdf = PdfFileReader("suenios_lucidos.pdf")

for page in range(pdf.getNumPages() - 210):

    # Write in a pdf each page:
    pdf_writer = PdfFileWriter
    curr_page = pdf.getPage(page)
    pdf_writer.addPage(curr_page)

----> 8 pdf_writer.addPage(curr_page)

TypeError: addPage() missing 1 required positional argument: 'page'

  • You need to replace the line `pdf_writer = PdfFileWriter` with `pdf_writer = PdfFileWriter()`. At the moment you are setting `pdf_writer` to the class `PdfFileWriter` when you want to create an instance of the class `PdfFileWriter` instead. See also https://stackoverflow.com/questions/17534345/typeerror-missing-1-required-positional-argument-self . – Luke Woodward Apr 09 '22 at 13:04

1 Answers1

0

Add ( ) to the PdfFileWriter:

pdf_writer = PdfFileWriter()