Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Adding images #84

@cnaccio

Description

@cnaccio

I couldn't find any documentation on how to annotate/add images to a PDF, but was able to figure it out by reading the code. The following worked for me. Leaving here in case it helps anyone else.

from pdf_annotate import PdfAnnotator, Location, Appearance

# Load a PDF into the PdfAnnotator
annotator = PdfAnnotator('test.pdf')

# Calculate coordinates (open your image in ms word to figure out size in inches, and then multiple by 72 pixels per inch)
x1 = 305.28
y1 = 156.24
x2 = x1 + 282.24
y2 = y1 + 70.56

# Add image to the PDF
annotator.add_annotation(
    'image',
    Location(x1=x1, y1=y1, x2=x2, y2=y2, page=1),
    Appearance(image='test.png')
)

# Save the annotated PDF
annotator.write('output.pdf')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions