Fill PDF Forms in Python, Rust, Node.js, Go, and C#
Read form fields and fill them programmatically across every supported binding:
Python
from pdf_oxide import PdfDocument
doc = PdfDocument("application.pdf")
# Read existing fields
for field in doc.page(0).form_fields():
print(f"{field.name}: {field.value}")
# Fill fields and save
doc.set_form_field("full_name", "Jane Doe")
doc.set_form_field("email", "jane@example.com")
doc.set_form_field("agree_terms", True)
doc.save("filled-application.pdf")
WASM
import { WasmPdfDocument } from "pdf-oxide-wasm";
const doc = new WasmPdfDocument(bytes);
// Read existing fields
const fields = doc.getFormFields();
for (const field of fields) {
console.log(`${field.name}: ${field.value}`);
}
// Export form data as XFDF
const xfdf = doc.exportFormData("xfdf");
console.log(xfdf);
doc.free();
Rust
use pdf_oxide::editor::{DocumentEditor, EditableDocument, FormFieldValue};
let mut editor = DocumentEditor::open("application.pdf")?;
// Read existing fields
let fields = editor.get_form_fields()?;
for field in &fields {
println!("{}: {:?}", field.name(), field.value());
}
// Fill fields and save
editor.set_form_field_value("full_name", FormFieldValue::Text("Jane Doe".into()))?;
editor.set_form_field_value("email", FormFieldValue::Text("jane@example.com".into()))?;
editor.set_form_field_value("agree_terms", FormFieldValue::Boolean(true))?;
editor.save("filled-application.pdf")?;
Go
package main
import (
"fmt"
"log"
pdfoxide "github.com/yfedoseev/pdf_oxide/go"
)
func main() {
doc, err := pdfoxide.Open("application.pdf")
if err != nil { log.Fatal(err) }
defer doc.Close()
// Read existing fields
fields, _ := doc.FormFields()
for _, f := range fields {
fmt.Printf("%s: %s\n", f.Name, f.Value)
}
// Fill fields on the editor and save
editor, err := pdfoxide.OpenEditor("application.pdf")
if err != nil { log.Fatal(err) }
defer editor.Close()
_ = editor.SetFormFieldValue("full_name", "Jane Doe")
_ = editor.SetFormFieldValue("email", "jane@example.com")
_ = editor.SetFormFieldValue("agree_terms", "Yes")
_ = editor.Save("filled-application.pdf")
}
C#
using PdfOxide;
using (var doc = PdfDocument.Open("application.pdf"))
{
foreach (var f in doc.GetFormFields())
Console.WriteLine($"{f.Name}: {f.Value}");
}
using var editor = DocumentEditor.Open("application.pdf");
editor.SetFormFieldValue("full_name", "Jane Doe");
editor.SetFormFieldValue("email", "jane@example.com");
editor.SetFormFieldValue("agree_terms", "Yes");
editor.Save("filled-application.pdf");
PDF Oxide supports AcroForm fields (text, checkbox, radio, dropdown) and XFA form analysis. MIT licensed, no AGPL restrictions.
Installation
pip install pdf_oxide
Reading Form Fields
List All Fields
Python
from pdf_oxide import PdfDocument
doc = PdfDocument("form.pdf")
for field in doc.page(0).form_fields():
print(f"Name: {field.name}")
print(f" Type: {field.field_type}")
print(f" Value: {field.value}")
print(f" Bounds: {field.bounds}")
print()
WASM
const doc = new WasmPdfDocument(bytes);
const fields = doc.getFormFields();
for (const field of fields) {
console.log(`Name: ${field.name}`);
console.log(` Type: ${field.fieldType}`);
console.log(` Value: ${field.value}`);
}
doc.free();
Rust
let mut editor = DocumentEditor::open("form.pdf")?;
let fields = editor.get_form_fields()?;
for field in &fields {
println!("Name: {}", field.name());
println!(" Type: {:?}", field.field_type());
println!(" Value: {:?}", field.value());
}
Go
doc, _ := pdfoxide.Open("form.pdf")
defer doc.Close()
fields, _ := doc.FormFields()
for _, f := range fields {
fmt.Printf("Name: %s\n Type: %s\n Value: %s\n", f.Name, f.Type, f.Value)
}
C#
using var doc = PdfDocument.Open("form.pdf");
foreach (var f in doc.GetFormFields())
{
Console.WriteLine($"Name: {f.Name}");
Console.WriteLine($" Type: {f.Type}");
Console.WriteLine($" Value: {f.Value}");
}
Field Types
| Type | Description | Example Values |
|---|---|---|
Text |
Single or multi-line text | "Jane Doe" |
Button |
Checkbox or radio button | True / False |
Choice |
Dropdown or list box | "Option A" |
Signature |
Digital signature | (signature data) |
Filling Form Fields
Text Fields
doc = PdfDocument("form.pdf")
doc.set_form_field("first_name", "Jane")
doc.set_form_field("last_name", "Doe")
doc.set_form_field("address", "123 Main St\nApt 4B\nNew York, NY 10001")
doc.save("filled.pdf")
Checkboxes
doc = PdfDocument("form.pdf")
doc.set_form_field("agree_terms", True)
doc.set_form_field("opt_in_newsletter", False)
doc.save("filled.pdf")
Dropdown / Choice Fields
doc = PdfDocument("form.pdf")
doc.set_form_field("country", "United States")
doc.set_form_field("department", "Engineering")
doc.save("filled.pdf")
Batch Form Filling
From a CSV File
Fill the same form template for each row in a CSV:
import csv
from pdf_oxide import PdfDocument
with open("applicants.csv") as f:
reader = csv.DictReader(f)
for i, row in enumerate(reader):
doc = PdfDocument("template.pdf")
for field_name, value in row.items():
doc.set_form_field(field_name, value)
doc.save(f"filled_{i + 1}.pdf")
From a Dictionary
from pdf_oxide import PdfDocument
data = {
"full_name": "Jane Doe",
"email": "jane@example.com",
"phone": "555-0123",
"department": "Engineering",
"start_date": "2025-03-01",
}
doc = PdfDocument("onboarding.pdf")
for name, value in data.items():
doc.set_form_field(name, value)
doc.save("onboarding-filled.pdf")
Export Form Data
Export to FDF
Python
from pdf_oxide import PdfDocument
doc = PdfDocument("filled-form.pdf")
fdf_data = doc.export_fdf()
with open("form-data.fdf", "wb") as f:
f.write(fdf_data)
WASM
const doc = new WasmPdfDocument(bytes);
const fdfData = doc.exportFormData("fdf");
// fdfData is a string or bytes depending on format
doc.free();
Rust
use pdf_oxide::extractors::FormExtractor;
let mut doc = PdfDocument::open("filled-form.pdf")?;
let fields = FormExtractor::extract_fields(&mut doc)?;
let fdf_bytes = FormExtractor::export_fdf(&mut doc, fields)?;
std::fs::write("form-data.fdf", &fdf_bytes)?;
Export to XFDF (XML)
Python
from pdf_oxide import PdfDocument
doc = PdfDocument("filled-form.pdf")
xfdf_data = doc.export_xfdf()
with open("form-data.xfdf", "w") as f:
f.write(xfdf_data)
WASM
const doc = new WasmPdfDocument(bytes);
const xfdfData = doc.exportFormData("xfdf");
console.log(xfdfData);
doc.free();
Rust
let mut doc = PdfDocument::open("filled-form.pdf")?;
let fields = FormExtractor::extract_fields(&mut doc)?;
let xfdf = FormExtractor::export_xfdf(&mut doc, fields)?;
std::fs::write("form-data.xfdf", &xfdf)?;
XFA Forms
Some government and enterprise forms use XFA (XML Forms Architecture) instead of standard AcroForms. PDF Oxide can detect and analyze XFA forms:
from pdf_oxide import PdfDocument
doc = PdfDocument("government-form.pdf")
xfa = doc.has_xfa()
if xfa:
print(f"XFA form detected: {len(xfa.fields)} fields")
for field in xfa.fields:
print(f" {field.name} ({field.field_type})")
See XFA Forms guide for detailed XFA handling.
Encrypted Forms
Fill forms in password-protected PDFs:
Python
from pdf_oxide import PdfDocument
doc = PdfDocument("protected-form.pdf", password="secret")
doc.set_form_field("signature_date", "2025-01-15")
doc.save("signed.pdf")
WASM
const doc = new WasmPdfDocument(bytes);
doc.authenticate("secret");
const fields = doc.getFormFields();
console.log(fields);
doc.free();
Rust
let mut editor = DocumentEditor::open_with_password("protected-form.pdf", "secret")?;
editor.set_form_field_value("signature_date", FormFieldValue::Text("2025-01-15".into()))?;
editor.save("signed.pdf")?;
Password-protected editing support. Go’s
DocumentEditorand C#'sDocumentEditordo not currently expose an authenticate-on-editor entry point. To fill fields in an encrypted PDF from Go or C#, decrypt first with the read-onlyPdfDocument.OpenWithPasswordpath, save an unencrypted copy, then open that copy in the editor.
Related Pages
- Form Data Extraction — full form extraction API
- Form Field Editing — advanced form operations
- XFA Forms — XFA form handling
- Batch Processing — parallel processing patterns