Forum Discussion
How to create a fillable PDF form?
You can design the page in Word first if that feels easier, then use PyMuPDF to add the fillable fields to the exported PDF. Word handles the labels and layout; the script adds the interactive parts.
Leave blank spaces for the answers, export the document as template.pdf, and install PyMuPDF:
python -m pip install pymupdf
Save this as add_fields.py:
import pymupdf
doc = pymupdf.open("template.pdf")
page = doc[0]
def add_field(name, rect, checkbox=False, multiline=False):
field = pymupdf.Widget()
field.field_name = name
field.rect = pymupdf.Rect(rect)
field.field_type = (
pymupdf.PDF_WIDGET_TYPE_CHECKBOX
if checkbox else pymupdf.PDF_WIDGET_TYPE_TEXT
)
field.border_width = 1
field.border_color = (0, 0, 0)
if not checkbox:
field.text_font = "Helv"
field.text_fontsize = 11
if multiline:
field.field_flags = pymupdf.PDF_TX_FIELD_IS_MULTILINE
page.add_widget(field)
add_field("fullname", (150, 100, 520, 125))
add_field("email", (150, 145, 520, 170))
add_field("phone", (150, 190, 520, 215))
add_field("updates", (50, 250, 66, 266), checkbox=True)
add_field("accessibility", (50, 285, 66, 301), checkbox=True)
add_field("comments", (50, 350, 520, 480), multiline=True)
doc.save("registration-fillable.pdf")
doc.close()
Run python add_fields.py. Replace the example rectangles with positions matching your template; coordinates are measured from the top-left, with 72 points per inch.
This is useful for adding fields without rebuilding an existing design. PyMuPDF is available under AGPL or a commercial licence, so check the licensing if you’re incorporating it into an application. Recipients only need a PDF reader that supports filling and saving forms.