-
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
Add add_outlines method for PdfWriter #1048
Comments
There are a couple of things PyPDF2 knows which could be what you're thinking of:
I'm uncertain how those three relate to each other / what you're looking for. Can you give it a try with an example document and share your knowledge? |
@MartinThoma thanks for the reply. It's probably still nice to make it possible with PyPDF.
? The example of PDF with table of contents If I do "read all pages and write them to another file", table of contents disappear. Yes, it's like that "outlines" is what I was looking for. Let me try... Probably worth updating documentation page if it works that way. |
Please open a discussion / other issues for other topics - many people might read the issues; we need to keep it focused. |
@MartinThoma OK, please ignore the comment about document, it's different. >>> reader.outlines
[{'/Title': 'Unnumbered Section', '/Page': IndirectObject(9, 0), '/Type': '/XYZ', '/Left': 133.768, '/Top': 451.62, '/Zoom': <PyPDF2.generic.NullObject object at 0x7f5057bbaf20>}, {'/Title': 'Unnumbered Section', '/Page': IndirectObject(9, 0), '/Type': '/XYZ', '/Left': 133.768, '/Top': 451.62, '/Zoom': <PyPDF2.generic.NullObject object at 0x7f5057bbaf20>}, {'/Title': 'Second Section', '/Page': IndirectObject(1, 0), '/Type': '/XYZ', '/Left': 133.768, '/Top': 628.33, '/Zoom': <PyPDF2.generic.NullObject object at 0x7f5057bbafe0>}] However I can't find any |
You can add bookmarks: from PyPDF2 import PdfReader, PdfWriter
def add_outlines_as_bookmark(writer, outline):
if not isinstance(outlines, list):
page_nb = 0 # I don't know how to get the page number
writer.add_bookmark(outline.title, page_nb, None)
else:
for o in outline:
add_outlines_as_bookmark(writer, o)
if __name__ == "__main__":
reader = PdfReader("example.pdf")
writer = PdfWriter()
for page in reader.pages:
writer.add_page(page)
for outlines in reader.outlines:
add_outlines_as_bookmark(writer, outlines)
with open("out.pdf", "wb") as fp:
writer.write(fp) Are bookmarks different from outlines? I agree that something like |
The PDF Reference uses the term "Outline" but recognizes "Bookmarks" as a synonymous term. From PDF Reference version 1.6 page 554 (section 8.2.2):
Something that seems to be contributing to the confusion is that within the Further contributing to the confusion, most PDF reference software refers to these objects as "Bookmarks". For example, a screenshot from the Adobe Acrobat: I've created a new issue (#1098) concerning this problem. |
See #1156 |
I have tried PyPDF2 for some PDF manipulation and it works brilliantly!
However, my output file doesn't keep table of contents.
Code Example
What I do is not much difference from reading and writing file with all pages and metadata like here in example of removing duplication https://pypdf2.readthedocs.io/en/latest/user/file-size.html#removing-duplication
How would your feature be used?
The text was updated successfully, but these errors were encountered: