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

Adding images #84

Open
cnaccio opened this issue Sep 25, 2024 · 0 comments
Open

Adding images #84

cnaccio opened this issue Sep 25, 2024 · 0 comments

Comments

@cnaccio
Copy link

cnaccio commented Sep 25, 2024

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')

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant