cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Bookmark in pdf

Sudic29
New Contributor

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.

1 REPLY 1

VZLA
Databricks Employee
Databricks Employee

@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? 

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group