-
-
Notifications
You must be signed in to change notification settings - Fork 195
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
Read page numbers from outline "action" #310
Comments
Well, each object that you get when iterating over the outline root is an
I believe that libqpdf recently added (In the meantime, I can also suggest using |
Thanks for the answer. In the above example I'm currently using PdfFileReader.getDestinationPageNumber() from PyPDF2 to get this info, but since it's not maintained I felt it was time to try and convert to something else. Will have a look at qpdf and pymupdf and if it may be an option. |
Yes, the outline code unfortunately doesn't handle actions at this time, only outline entries explicitly defined with a page destinations. Actions can be a lot of things other than going to a page. |
That the object doesn't implement if '/D' in item.action:
dest = item.action.D
# assuming a direct destination
assert isinstance(dest, pikepdf.Array)
page_obj = dest[0]
page_index = pikepdf.Page(page_obj).index
print(page_index) |
Thanks, haven't really understood all of how to work with pikepdf yet but this is atleast one step closer :) After trying your code snippet I can conclude that its not a direct destination but an indirect one. When printing pikepdf.Dictionary({
"/D": "0",
"/S": "/GoTo"
}) Is it possible to look up the "/D" value somewhere within pikepdf in this case? Cause I'm guessing it can be resolved to a "/Page" entry somewhere. |
Yes, it should be possible to resolve the indirect/named destination to a direct one. I suppose the document has a name tree at named_dest = item.action.D
assert isinstance(named_dest, pikepdf.Dictionary)
name_mapping = pikepdf.NameTree(pdf.Root.Names.Dests)
direct_dest = name_mapping[named_dest]
page = pikepdf.Page(direct_dest[0])
print(page_obj.index) |
Thank you so much for your help! Will test your code when I get a chance, seems to support indirect destinations? If it doesnt work I atleast now know where to look :) |
I'm trying to figure out how to extract the page number of an OutlineItem when
<Action>
is returned, since this feature doesn't seem to be implemented yet (?).Is there a workaround until it's implemented? Any idea of when that might be?
Is it possible to access the "raw" Pdf outline somehow to look for the
/Page
entry?Take outlines.pdf as an example:
returns:
The text was updated successfully, but these errors were encountered: