Skip to main content

xfdfgen is a Python library for creating xfdf files that can be used to populate pdf form fields.

Project description

xfdfgen

xfdfgen is a Python library for creating xfdf files that can be used to populate pdf form fields.

Installation

Use the package manager pip to install xfdfgen.

pip install xfdfgen

Usage

from xfdfgen import Xfdf

pdf_document_name = 'example_document.pdf'
dictionary_of_fields= {
    'first_name': 'foo',
    'last_name': 'bar'
}

document = Xfdf(pdf_document_name, dictionary_of_fields)

output_path = 'example_out.xfdf'
document.write_xfdf(output_path)

pdf_document_name should match the name of the document containing the form fields you want to fill in.

The keys of the dictionary_of_fields are the form field ids in the document. To find them, you can use Adobe Acrobat, pdftk, or PDFescape if you don't want to install anything.

The output can be imported with various programs/libraries, such as pdftk, Foxit Reader, Adobe Acrobat, and pypdftk.

Alternatively, you can use pdfformfields which this package was created for. pdfformfields is capable of reading in the metadata of the pdf and filling in the form for you.

To view the xfdf file in a more human readable format, use

document.pretty_print()

which should output

<?xml version="1.0" ?>
<xfdf xml:space="preserve" xmlns="http://ns.adobe.com/xfdf/">
	<f href="example_pdf.pdf"/>
	<fields>
		<field name="first_name">
			<value>foo</value>
		</field>
		<field name="last_name">
			<value>bar</value>
		</field>
	</fields>
</xfdf>

An example is included in the example folder.

Compatibility

This package has been tested on Windows 10 using Python 3.7

License

Apache License 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for xfdfgen, version 0.4
Filename, size File type Python version Upload date Hashes
Filename, size xfdfgen-0.4.tar.gz (3.1 kB) File type Source Python version None Upload date Hashes View
Filename, size xfdfgen-0.4-py3-none-any.whl (7.6 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page