t-houssian / fillpdf

A python library to make filling pdfs much easier
MIT License
134 stars 23 forks source link

fillpdf

https://pypi.org/project/fillpdf/

Documentation:

View The Documentation

GitHub PyPI GitHub last commit Documentation Status Python Python 3.7

Overview

This is a simple package to make filling pdfs much easier. I have delt with a lot projects that involve manipulating pdfs in python. I found no easy solution for writting, or flattening pdfs, so I decided to make a library to make this task much easier. As a young software engineer I kept this library really simple but practicle and am open to any input for the future!

This project primarily builds upon a forked version of pdfrw called pdfrw2.

Function Documentation

import fillpdf
from fillpdf import fillpdfs
get_form_fields (returns the data_dict)
get_form_fields(input_pdf_path, sort=False, page_number=None)
print_form_fields (prints the data_dict)
print_form_fields(input_pdf_path, sort=False, page_number=None)
write_fillable_pdf
write_fillable_pdf(input_pdf_path, output_pdf_path, data_dict, flatten=False)
flatten_pdf
flatten_pdf(input_pdf_path, output_pdf_path, as_images=False)
rotate_page
rotate_page(deg, input_pdf_path, output_map_path, page_number)
place_radiobutton
place_radiobutton(field_name, x, y, input_pdf_path, output_map_path, page_number, width=10, height=10, font_size=12, font_name=None, fill_color=(0.8,0.8,0.8), font_color=(0,0,0)
place_dropdown
place_dropdown(field_name, values, x, y, input_pdf_path, output_map_path, page_number, width=10, height=10, font_size=12, font_name=None, fill_color=(0.8,0.8,0.8), font_color=(0,0,0))
place_text_box
place_text_box(field_name, prefilled_text, x, y, input_pdf_path, output_map_path, page_number, width=10, height=10, font_size=12, font_name=None, fill_color=(0.8,0.8,0.8), font_color=(0,0,0)):
place_image
place_image(file_name, x, y, input_pdf_path, output_map_path, page_number, width=10, height=10)
place_text
place_text(text, x, y, input_pdf_path, output_map_path, page_number, font_size=12, font_name="helv", color=None)
get_coordinate_map
get_coordinate_map(input_pdf_path, output_map_path, page_number=1):
Fonts (For place functions)
{'courier': 'Courier',
'courier-oblique': 'Courier-Oblique',
'courier-bold': 'Courier-Bold',
'courier-boldoblique': 'Courier-BoldOblique',
'helvetica': 'Helvetica',
'helvetica-oblique': 'Helvetica-Oblique',
'helvetica-bold': 'Helvetica-Bold',
'helvetica-boldoblique': 'Helvetica-BoldOblique',
'times-roman': 'Times-Roman',
'times-italic': 'Times-Italic',
'times-bold': 'Times-Bold',
'times-bolditalic': 'Times-BoldItalic',
'symbol': 'Symbol',
'zapfdingbats': 'ZapfDingbats',
'helv': 'Helvetica',
'heit': 'Helvetica-Oblique',
'hebo': 'Helvetica-Bold',
'hebi': 'Helvetica-BoldOblique',
'cour': 'Courier',
'coit': 'Courier-Oblique',
'cobo': 'Courier-Bold',
'cobi': 'Courier-BoldOblique',
'tiro': 'Times-Roman',
'tibo': 'Times-Bold',
'tiit': 'Times-Italic',
'tibi': 'Times-BoldItalic',
'symb': 'Symbol',
'zadb': 'ZapfDingbats'}

Command Line Use

A command line wrapper is available for this tool. Here are the two commands:

extractfillpdf
extractfillpdf input_pdf_path
or
extractfillpdf input_pdf_path -o output_json_path
Or:
insertfillpdf --help or insertfillpdf -h

Will bring up this menu

positional arguments:
  test.pdf              Input PDF file

optional arguments:
  -h, --help            show this help message and exit
  -j test.json, --JSON test.json
                        Input JSON file, if none given, it will be the input file with the JSON
                        extension
  -o test_out.pdf, --output test_out.pdf
                        Output file to write result, if none given, it will be the input file
                        with '_out.pdf' extension'
  --version             show program's version number and exit
  -v, --verbose         set loglevel to INFO
  -vv, --very-verbose   set loglevel to DEBUG

Software Demo Video

Installation

pip install fillpdf 
conda install -c conda-forge poppler

poppler is only needed if you are using the as_images=True mode of the flattenpdf function

Development Environment

Builds upon

Useful Websites

Credit

Future Work

How To Contribute