-1

I am trying to open PDF's that have an opening password and when I try to open them it tells me that the password is incorrect, however, when I validate manually the password is correct, could you please help me?

This is my code:

def remove_pdf_password(input_path, output_path, password):
    pdf_reader = PyPDF2.PdfReader(input_path)

    print(input_path)
    pdf_writer = PyPDF2.PdfWriter()
    pdf_reader.decrypt('9127621')

    for page_num in range(len(pdf_reader.pages)):
        pdf_writer.add_page(pdf_reader.pages[page_num])

    with open(output_path, 'wb') as output_file:
        pdf_writer.write(output_file)
    print("Contraseña eliminada y PDF guardado en", output_path)

I validate manually the password is correct.

Robert
  • 7,394
  • 40
  • 45
  • 64
  • Do any of these command-line decryption tools work? https://superuser.com/questions/734779/command-line-decrypting-of-pdf-given-a-document-open-password I ask because it's possible to run command line programs from Python. – Nick ODell Aug 31 '23 at 20:52

0 Answers0