Git Product home page Git Product logo

pdfformfields's Introduction

pdfformfields

pdfformfields is a Python wrapper around pdftk that lets the user fill in forms from a Python dictionary.

Prerequisites

You need to have pdftk server on your computer installed.

Installing

To install, simply run

pip install pdfformfields

Usage

from pdfformfields import fill_form_fields, generate_dictionary


# Example pdf containing two fields with ids: first_name, last_name
example_input_pdf = "example_input.pdf"

# Use generate_dictionary() with verbose=True to understand the structure
# generate_dictionary(example_input_pdf, verbose=True)

# Use generate_dictionary() without verbose=True to generate a copiable code for the field dictionary onto the console
generate_dictionary(example_input_pdf)

""" The output should be:
rename_me = {
    "first_name": ,
    "last_name": ,
}
"""

# Paste code, rename dictionary, and fill in the values however you like
form_field_dictionary = {
    "first_name": "John",
    "last_name": "Doe",
}

# Output filled in dictionary with the fill_form_fields() function
example_output_pdf = r"example_output.pdf"
fill_form_fields(example_input_pdf, form_field_dictionary, example_output_pdf)

# If you don't want the output to be editable set flatten=True
example_output_pdf_flattened = r"example_output_pdf_flattened.pdf"
fill_form_fields(example_input_pdf, form_field_dictionary, example_output_pdf_flattened, flatten=True)

See complete example.

Bash error

The package did not manage to locate your pdftk command.

Make sure that pdftk server is installed on your system. If it is, try setting the pdftk argument of fill_form_fields to ...

... on Linux:

fill_form_fields(..., pdftk_command="pdftk")

... on Windows:

pdftk_path = os.path.join("path_to_pdftk_server_folder", "bin", "pdftk.exe")
fill_form_fields(..., pdftk_command=pdftk_path)

Built With

Author

  • Nguyen Ba Long

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details

Acknowledgments

  • pypdftk Inspiration: another wrapper around pdftk that does not work under Windows and Python 3.7, which is why this package was created.

pdfformfields's People

Contributors

balonger avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.