Bookmark in pdf
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2024 09:20 PM
I am creating a pdf using pyspark and trying to make bookmarks for each table in the pages. All the bookmarks end up pointing to the first table in the first page. Please help me out here.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2024 09:57 AM - edited 11-23-2024 10:01 AM
@Sudic29 can you please share more about what you have implemented so far?
This requires dynamically tracking the page number during the PDF creation process. Example in python:
from PyPDF2 import PdfReader, PdfWriter
def add_bookmarks_to_pdf(input_path, output_path, bookmarks):
# Open the PDF file
reader = PdfReader(input_path)
writer = PdfWriter()
# Add pages to the writer and create bookmarks
for i, page in enumerate(reader.pages):
writer.add_page(page)
if i in bookmarks:
writer.add_named_destination(bookmarks[i], i)
# Write the output PDF with bookmarks
with open(output_path, 'wb') as f:
writer.write(f)
# Example bookmarks: {page_number: "Bookmark Name"}
bookmarks = {
0: "Table 1",
1: "Table 2",
2: "Table 3"
}
add_bookmarks_to_pdf("input.pdf", "output.pdf", bookmarks)
What have you accomplished in PySpark?