[Python] Search/Update Graphics in a PDF

Discussão em 'Python' iniciado por Stack, Junho 22, 2025.

  1. Stack

    Stack Membro Participativo

    Is there any way to search for a graphic in a PDF page?

    For example, I have used the PyFPDF library to generate a PDF with few rectangles and circles (code below). Now I would like to

    • get a list of ellipses that are printed in each page and their location.
    • and update the color of all the circles to blue

    Is there any library which allows this?


    PDF generation with few rectangles and circles:

    Sample PDF generated using code below: Download the PDF

    from fpdf import FPDF

    # Prepare PDF generator
    pdf = FPDF(orientation = 'L', unit = 'in', format = 'A4')
    pdf.add_page()
    pdf.set_fill_color(0, 0, 0)

    # Draw the rectangle
    pdf.rect(x = 1, y = 1, w = 2, h = 2, style = 'S')
    pdf.rect(x = 1.5, y = 1.5, w = 5, h = 1, style = 'S')
    pdf.ellipse(x = 1, y = 4, w = 1, h = 1, style = 'S')
    pdf.ellipse(x = 4, y = 5, w = 1, h = 1, style = 'S')
    pdf.ellipse(x = 9, y = 2, w = 1, h = 1, style = 'F')
    pdf.rect(x = 6, y = 5, w = 2, h = 1, style = 'F')

    # Write to file
    pdf.output("test.pdf")

    Continue reading...

Compartilhe esta Página