
Security News
OpenGrep Restores Fingerprinting in JSON and SARIF Outputs
OpenGrep has restored fingerprint and metavariable support in JSON and SARIF outputs, making static analysis more effective for CI/CD security automation.
https://pypi.org/project/fillpdf/
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.
import fillpdf
from fillpdf import fillpdfs
get_form_fields(input_pdf_path, sort=False, page_number=None)
fillpdfs.get_form_fields('blank.pdf')
print_form_fields(input_pdf_path, sort=False, page_number=None)
fillpdfs.print_form_fields('blank.pdf')
write_fillable_pdf(input_pdf_path, output_pdf_path, data_dict, flatten=False)
data_dict = {'Address1 Text Box': '500 West Main Street',
'Driving License Check Box': 'Yes',
'Language 1 Check Box': 'Off',}
fillpdfs.write_fillable_pdf('blank.pdf', 'new.pdf', data_dict)
flatten_pdf(input_pdf_path, output_pdf_path, as_images=False)
fillpdfs.flatten_pdf('new.pdf', 'newflat.pdf')
rotate_page(deg, input_pdf_path, output_map_path, page_number)
fillpdfs.rotate_page(90, 'new.pdf', 'template-3.pdf', 1)
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)
fillpdfs.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(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))
fillpdfs.place_dropdown('dropField-1', ("Frankfurt", "Hamburg", "Stuttgart", "Hannover", "Berlin", "München", "Köln", "Potsdam",), 0, 0, 'sample_pdf.pdf', 'template-3.pdf', 1, width=100, height=20, font_size=16)
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)):
fillpdfs.place_text_box('form text', 'textfield-1', 0, 0, 'sample_pdf.pdf', 'template-3.pdf', 1, width=100, height=20, font_size=16)
place_image(file_name, x, y, input_pdf_path, output_map_path, page_number, width=10, height=10)
fillpdfs.place_image('mush.png', 50, 50, 'template-2.pdf', 'template-3.pdf', 1, width=200, height=200)
place_text(text, x, y, input_pdf_path, output_map_path, page_number, font_size=12, font_name="helv", color=None)
fillpdfs.place_text('Yo', 50, 50, 'template-2.pdf', 'template-3.pdf', 1)
get_coordinate_map(input_pdf_path, output_map_path, page_number=1):
fillpdfs.get_coordinate_map('template.pdf', 'template-2.pdf')
{'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'}
A command line wrapper is available for this tool. Here are the two commands:
extractfillpdf input_pdf_path
or
extractfillpdf input_pdf_path -o output_json_path
extractfillpdf blank.pdf
or
extractfillpdf blank.pdf -o data.json
insertfillpdf -j input_json_path -o output_pdf_path input_pdf_path
insertfillpdf -j blank.json -o new.pdf blank.pdf
extractfillpdf --help or extractfillpdf -h
Will bring up this menu
positional arguments:
test.pdf Input pdf file
optional arguments:
-h, --help show this help message and exit
-o test.json, --output test.json
Output file to write result, if none given, it will be the input file
with the JSON extension
--version show program's version number and exit
-v, --verbose set loglevel to INFO
-vv, --very-verbose set loglevel to DEBUG
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
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
Fork the project
Add your changes
Open a pull request
Once pull request is approved I'll merge in the code and push new version to pypi
If you want to be a maintainer contact me
FAQs
A Library to fill and flatten pdfs
We found that fillpdf demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
OpenGrep has restored fingerprint and metavariable support in JSON and SARIF outputs, making static analysis more effective for CI/CD security automation.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.