Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fb1a376
Add import/export examples for PDF form data in facades section
andruhovski Feb 8, 2026
0aebf8e
Added samples for import/export Form data
andruhovski Feb 8, 2026
862b5fc
Add sample form outputs in multiple formats
andruhovski Feb 18, 2026
a524ee9
Add examples for exporting and importing PDF form data in facades sec…
andruhovski Feb 18, 2026
0d10cbc
Add examples for filling various PDF form fields in facades section
andruhovski Feb 19, 2026
4236679
Add examples for filling various PDF form fields in facades section
andruhovski Feb 19, 2026
8e1090c
Add examples for flattening and renaming PDF form fields in facades s…
andruhovski Feb 19, 2026
4003aea
Add example for filling fields by name and value in facades section
andruhovski Feb 19, 2026
9a05500
Add examples for reading and inspecting PDF form data in facades section
andruhovski Feb 19, 2026
e902b92
Add examples for managing PDF form fields and retrieving field inform…
andruhovski Feb 19, 2026
c120053
Refactor form editor examples and remove deprecated scripts
AnHolub Feb 23, 2026
6a4cc5f
Remove outdated examples for PDF file editing operations including de…
AnHolub Mar 3, 2026
fa726b9
Add examples for PDF form field management, content editing, page ope…
AnHolub Mar 3, 2026
118279f
Enhance form editor examples by adding input/output parameters and im…
andruhovski Mar 4, 2026
9365b42
Added sample data
andruhovski Mar 4, 2026
f9c9332
Add examples for managing button fields, deleting annotations, and re…
andruhovski Mar 4, 2026
f3edb37
Merge branch '4-add-examples-in-facades-section' of https://github.co…
andruhovski Mar 4, 2026
5e5aad1
Add examples for PDF page management, layout, and splitting operations
AnHolub Mar 4, 2026
260e869
Merge branch '4-add-examples-in-facades-section' of https://github.co…
AnHolub Mar 4, 2026
5bbdce2
Add sample data
andruhovski Mar 4, 2026
ab022fa
Refactor run_all_examples function to simplify argument handling and …
andruhovski Mar 4, 2026
e6ef073
Add examples for adding free text, text, and line annotations to PDF …
andruhovski Mar 4, 2026
635d02d
Remove deprecated annotation examples from the facades section
andruhovski Mar 4, 2026
ac23712
Merge branch '4-add-examples-in-facades-section' of https://github.co…
andruhovski Mar 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ Directory | Description
<a title="Download Examples ZIP" href="https://github.com/aspose-pdf/Aspose.PDF-for-Python-via-.NET/archive/master.zip">
<img src="https://raw.github.com/AsposeExamples/java-examples-dashboard/master/images/downloadZip-Button-Large.png" />
</a>
</p>
</p>


## General PDF Features

- Supports most established PDF standards and PDF specifications.
- Ability to read & export PDFs in multiple image formats including BMP, GIF, JPEG & PNG.
- Ability to read & export PDFs in multiple image formats including BMP, GIF, JPEG & PNG.
- Set basic information (e.g. author, creator) of the PDF document.
- Configure PDF Page properties (e.g. width, height, cropbox, bleedbox etc.).
- Set page numbering, bookmark level, page sizes etc.
Expand Down Expand Up @@ -75,7 +75,7 @@ Below code snippet follows these steps:

1. Create an instance of the HtmlLoadOptions object.
1. Initialize Document object.
1. Save output PDF document by calling Document.Save() method.
1. Save output PDF document by calling Document.save() method.

```python
import aspose.pdf as ap
Expand Down
118 changes: 118 additions & 0 deletions examples/facades_form/exporting_pdf_form_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
from io import FileIO
import sys
from os import path
import aspose.pdf as ap
import aspose.pdf.facades as pdf_facades

sys.path.append(path.join(path.dirname(__file__), ".."))

from config import set_license, initialize_data_dir

# Export Data to XML
def export_pdf_form_data_to_xml(infile, datafile):
"""Export PDF form data to XML file."""
# Create Form object
pdf_form = pdf_facades.Form()

# Bind PDF document
pdf_form.bind_pdf(infile)

# Open XML file as stream
with FileIO(datafile, 'w') as xml_output_stream:
# Export data from PDF form fields to XML
pdf_form.export_xml(xml_output_stream)

# Export Data to FDF
def export_form_data_to_fdf(infile, outfile):
"""Export PDF form data to FDF file."""
# Create Form object
pdf_form = pdf_facades.Form()

# Bind PDF document
pdf_form.bind_pdf(infile)

# Create FDF file stream
with open(outfile, 'wb') as fdf_output_stream:
# Export form data to FDF file
pdf_form.export_fdf(fdf_output_stream)

# Export Data to XFDF
def export_pdf_form_to_xfdf(infile, outfile):
"""Export PDF form data to XFDF file."""
# Create Form object
pdf_form = pdf_facades.Form()

# Bind PDF document
pdf_form.bind_pdf(infile)

# Create XFDF file stream
with open(outfile, "wb") as xfdf_output_stream:
# Export form data to XFDF file
pdf_form.export_xfdf(xfdf_output_stream)

# Export Data to JSON
def export_form_to_json(infile, outfile):
"""Export PDF form field values to JSON file."""
# Create Form object
form = pdf_facades.Form()

# Bind PDF document
form.bind_pdf(infile)

# Create JSON file stream
with FileIO(outfile, 'w') as json_stream:
# Export form field values to JSON
form.export_json(json_stream, indented=True)

# Extract XFA Data
def export_xfa_data(infile, outfile):
"""Export XFA form data."""
# Create Form object
form = pdf_facades.Form()

# Bind PDF document
form.bind_pdf(infile)

with FileIO(outfile, 'w') as stream:
# Export form field values to JSON
form.extract_xfa_data(stream)

def run_all_examples(data_dir=None, license_path=None):
"""Run all import/export form data examples and report status.

Args:
data_dir (str, optional): Input/output directory override.
license_path (str, optional): Path to Aspose.PDF license file.

Returns:
None
"""

set_license(license_path)
input_dir, output_dir = initialize_data_dir(data_dir)

examples = [
("Export Data to XML", export_pdf_form_data_to_xml, "sample_form.xml"),
("Export Data to FDF", export_form_data_to_fdf, "sample_form.fdf"),
("Export Data to XFDF", export_pdf_form_to_xfdf, "sample_form.xfdf"),
("Export Values to JSON", export_form_to_json, "sample_form.json"),
("Export XFA Data", export_xfa_data, "sample_form_xfa.xml"),
]

for name, func, data_file_name in examples:
try:
if (func.__name__ == "export_xfa_data"):
input_file_name = path.join(input_dir, "sample_xfa_form.pdf")
else:
input_file_name = path.join(input_dir, "sample_form.pdf")
output_file_name = path.join(output_dir, data_file_name)
func(input_file_name, output_file_name)
print(f"✅ Success: {name}")
except Exception as e:
print(f"❌ Failed: {name} - {str(e)}")

print("\nAll Export Form Data examples finished.")


if __name__ == "__main__":
run_all_examples()
160 changes: 160 additions & 0 deletions examples/facades_form/filling_form_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Filling PDF Form Fields
# ├── Fill Text Fields
# ├── Fill Check Box Fields
# ├── Fill Radio Button Fields
# ├── Fill List Box / Multi-Select Fields
# ├── Fill Barcode Fields
# └── Fill Fields by Name and Value

from io import FileIO
import sys
from os import path
import aspose.pdf as ap
import aspose.pdf.facades as pdf_facades

sys.path.append(path.join(path.dirname(__file__), ".."))

from config import set_license, initialize_data_dir

# Fill Text Fields
def fill_text_fields(infile, outfile):
"""Fill text fields in PDF form."""
# Create Form object
pdf_form = pdf_facades.Form()

# Bind PDF document
pdf_form.bind_pdf(infile)

# Fill text fields by name
pdf_form.fill_field("name", "John Doe")
pdf_form.fill_field("address", "123 Main St, Anytown, USA")
pdf_form.fill_field("email", "john.doe@example.com")

# Save updated PDF
pdf_form.save(outfile)

# Fill Check Box Fields
def fill_check_box_fields(infile, outfile):
"""Fill check box fields in PDF form."""
# Create Form object
pdf_form = pdf_facades.Form()

# Bind PDF document
pdf_form.bind_pdf(infile)

# Fill check box fields by name
pdf_form.fill_field("subscribe_newsletter", "Yes")
pdf_form.fill_field("accept_terms", "Yes")

# Save updated PDF
pdf_form.save(outfile)

# Fill Radio Button Fields
def fill_radio_button_fields(infile, outfile):
"""Fill radio button fields in PDF form."""
# Create Form object
pdf_form = pdf_facades.Form()

# Bind PDF document
pdf_form.bind_pdf(infile)

# Fill radio button fields by name
pdf_form.fill_field("gender", 0) # Select male option (index 0)
#pdf_form.fill_field("gender", 1) # Select female option (index 1)

# Save updated PDF
pdf_form.save(outfile)

# Fill List Box / Multi-Select Fields
def fill_list_box_fields(infile, outfile):
"""Fill list box and multi-select fields in PDF form."""
# Create Form object
pdf_form = pdf_facades.Form()

# Bind PDF document
pdf_form.bind_pdf(infile)

# Fill list box / multi-select fields by name
pdf_form.fill_field("favorite_colors", "Red")

# Save updated PDF
pdf_form.save(outfile)

# Fill Barcode Fields
def fill_barcode_fields(infile, outfile):
"""Fill barcode fields in PDF form."""
# Create Form object
pdf_form = pdf_facades.Form()

# Bind PDF document
pdf_form.bind_pdf(infile)

# Fill barcode fields by name
pdf_form.fill_field("product_barcode", "123456789012")

# Save updated PDF
pdf_form.save(outfile)

# Fill Fields by Name and Value
def fill_fields_by_name_and_value(infile, outfile):
"""Fill PDF form fields by name and value."""
# Create Form object
pdf_form = pdf_facades.Form()

# Bind PDF document
pdf_form.bind_pdf(infile)

# Fill fields by name and value
fields = {
"name": "Jane Smith",
"address": "456 Elm St, Othertown, USA",
"email": "jane.smith@example.com"
}

names = list(fields.keys())
values = list(fields.values())

result = pdf_form.fill_fields(names, values, [])
print(f"Filled {result} fields by name and value.")

# Save updated PDF
pdf_form.save(outfile)

def run_all_examples(data_dir=None, license_path=None):
"""Run all import form data examples and report status.

Args:
data_dir (str, optional): Input/output directory override.
license_path (str, optional): Path to Aspose.PDF license file.

Returns:
None
"""

set_license(license_path)
input_dir, output_dir = initialize_data_dir(data_dir)

examples = [
("Fill Text Fields", fill_text_fields),
("Fill Check Box Fields", fill_check_box_fields),
("Fill Radio Button Fields", fill_radio_button_fields),
("Fill List Box / Multi-Select Fields", fill_list_box_fields),
("Fill Barcode Fields", fill_barcode_fields),
("Fill Fields by Name and Value", fill_fields_by_name_and_value)
]

for name, func in examples:
try:
input_file_name = path.join(input_dir, f"{func.__name__}_in.pdf")
output_file_name = path.join(output_dir, f"{func.__name__}_out.pdf")
func(input_file_name, output_file_name)

print(f"✅ Success: {name}")
except Exception as e:
print(f"❌ Failed: {name} - {str(e)}")

print("\nAll Fill Form Fields examples finished.")


if __name__ == "__main__":
run_all_examples()
Loading