Draw elements

PyPDFForm enables drawing elements on a PDF, which is useful when a widget is missing from your PDF form or when you need to add text or images.

This section of the documentation will use this PDF as an example.

Understanding the PDF coordinate system is necessary for this section.

All optional parameters will have a comment # optional after each of them.

NOTE: Avoid drawing elements that overlap with form widgets, as widgets take precedence and will cover drawn elements.

Draw text

from PyPDFForm import PdfWrapper

pdf = PdfWrapper("sample_template.pdf").draw_text(
    text="random text",
    page_number=1,
    x=300,
    y=225,
    font="your_registered_font",    # optional
    font_size=12,   # optional
    font_color=(1, 0, 0)    # optional
)

with open("output.pdf", "wb+") as output:
    output.write(pdf.read())

Draw image

from PyPDFForm import PdfWrapper

pdf = PdfWrapper("sample_template.pdf").draw_image(
    image="sample_image.jpg",
    page_number=1,
    x=100,
    y=100,
    width=400,
    height=225,
    rotation=0  # optional
)

with open("output.pdf", "wb+") as output:
    output.write(pdf.read())