-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PdfFileWriter addBookmark DictionaryObject issue #264
Comments
The support for cloning and editing seems to be rudimentary at best. The error you get is because the PDF file contains an Outlines tree, which is represented as a
Worse, all indirect references that link the tree nodes together are still pointing to the reader that was cloned from. The objects themselves are not part of the writer's
|
So write to BytesIO, add the bookmark, then write to outputStream, correct? |
Okay, this almost worked, so let me tell you what I did to make it work. First, I put your getOutlineRoot code in below everything in getOutlineRoot except the return:
I then added the new.write(BytesIO()) code to my script (after importing BytesIO from io):
It wrote the test bookmark fine. But when I un-commented the bookmark swapping code in the original post to create the swapped nested bookmarks, it couldn't do the parent.addChild function, since it was being passed a unicode string and not the bookmark object itself. So back in pdf.py I altered the addBookmark text in two ways. I created an exception for a root level bookmark to write as originally written, but otherwise, I had it drill down the outline until it found the bookmark it was looking for and then wrote the child bookmark. The new recursive function (defined inside of the addBookmark definition, just below the parameter explanation:
And the rewritten parent section at the bottom of the addBookmark defnition:
If you have any questions, please ask. |
@LightningMan711 Do you know if there is anything left to do for this one? What exactly is the issue? |
I assume the issue was solved. Please comment if it still exists with recent |
Still have this issue with pypdf 3.15.5 https://pastebin.com/AgnYe8zu Line 51
|
Please open a new issue with example code and a reproducing PDF file as well as the full traceback. |
I have a bookmark level swapping program that I wrote using PdfFileMerge but I would like to use PdfFileWriter instead, since it allows me to target bookmarks to a specific area on the page, which is how the original, unswapped bookmarks are targeted.
I tried using the revision of cloneDocumentFromReader at this link to retain the original tree (which for my purposes needs to be done) and while that worked fine (no empty pages), addBookmark when given a dummy bookmark (and not all the data I really want to pass) throws an error.
The code:
The error I get is this:
It appears that the addBookmark code is expecting a TreeObject but parent is a DictionaryObject .
The addBookmark method works fine when there are no existing bookmarks. It's only when there is an existing tree that this is an issue, and, as you recall, that is the point, to retain the original bookmarks.
Any help would be appreciated.
The text was updated successfully, but these errors were encountered: