pyPdf icon indicating copy to clipboard operation
pyPdf copied to clipboard

internal links not preserved when encrypted

Open iffy opened this issue 15 years ago • 1 comments

Steps to Duplicate:

  1. Obtain a PDF with internal links (you click the link and it takes you to another page in the PDF)
  2. Encrypt the PDF with the function below
  3. Open the PDF and see that the links no longer work.
def encrypt(in_stream, out_stream, user_password, owner_password=None): """ Encrypt an existing PDF file (stream)
    `in_stream`         stream with pdf data
                        open(filename, 'rb')
    `out_stream`        stream where output will be written
                        open(filename, 'wb')
    `user_password`     the password used for limited access
    `owner_password`    the password used for full access (defaults to user_password)

    I copied this from /sm/script/encryptPdf.py
    """
    reader = PdfFileReader(in_stream)
    writer = PdfFileWriter()
    for i in range(reader.getNumPages()):
        writer.addPage(reader.getPage(i))
    writer.encrypt(user_password, owner_password)
    writer.write(out_stream)

iffy avatar May 05 '10 19:05 iffy

The bug seems to be present even when you don't encrypt the pdf. I have used PyPdf for watermarking like the example on the front page. That type of usage breaks internal links too, but I also tried simply iterating pages from input, adding them to output and writing the file out. That breaks internal links as well. My best guess is that PyPdf will simply break internal links under all circumstances. Has someone been able to figure out the root cause to this?

cyberixae avatar Dec 11 '12 16:12 cyberixae