Simple FPDF
A simplified version of the FPDF package.
Aim of this package
This package aims to make it easier to generate a PDF, without concerning yourself with the difficulties of keeping track of the (x,y) position inside the document.
A simple row-column system is used to generate a PDF and insert text. Since this extends the FPDF package, all the FPDF functionalities are still included.
Getting started
Install
Install with pip.
pip install simple-fpdf
Import
Import the package and SimpleFPDF.
from simple_fpdf import SimpleFPDF
How to use
Initialize SimpleFPDF
SimpleFPDF is initialized the same as a normal FPDF. You can also use the width and height parameters. If no format, width or height is specified, A4 will be used.
pdf = SimpleFPDF(orientation='P', unit='mm', format="A4")
pdf = SimpleFPDF(orientation='P', unit='mm', width=210, height=297)
Defining the rows and columns
SimpleFPDF makes use of a simple row-column system where all the rows on the page have an equal height. Before adding a page, you need to define how many rows a page will have, and how many columns these rows will contain.
page_1_rows = [
{ 'columns' : 1 }, # row 1, has one column
{ 'columns' : 1 }, # row 2, has one column
{ 'columns' : 2 }, # row 3, has two columns
{ 'columns' : 3 } # row 4, has three columns
]
Adding a page
Add a page using the known .add_page() method. This method expects a new parameter: rows.
Rows need to be an array with the row definitions as specified above.
pdf.add_page(rows=page_1_rows)
Writing text
Once you have a page and their rows and columns, you can simply start writing text to it using .write_text(). This function takes three required parameters: row, column and txt.
Optionally, you can also specify the page by giving its number. If no page is given, the current page is used.
pdf.write_text(txt='This is my heading', row=1)
pdf.write_text(txt='This is my second row', row=2)
pdf.write_text(txt='This is my thirth row, first column', row=3, column=1)
pdf.write_text(txt='This is my thirth row, second column', row=3, column=2)
pdf.write_text(txt='This is my fourth row, first column', row=4, column=1)
pdf.write_text(txt='This is my fourth row, second column', row=4, column=2)
pdf.write_text(txt='This is my fourth row, thirth column', row=4, column=3)
Output
Generate the pdf using the .output() method.
pdf.output('my_pdf.pdf')
Advanced settings
Since SimpleFPDF aims to be as simple as possible, not much customisation is possible. There are a few settings you can use.
top-margin
You can specify the top-margin for a row. This will add a margin to the top of a row, using the unit specified at creation.
rows = [
{ 'columns' : 1, 'top-margin' : 30 }, # row 1, has one column and a top-margin of 30mm
{ 'columns' : 1 }, # row 2, has one column
{ 'columns' : 2, 'top-margin' }, # row 3, has two columns and a top-margin of 15mm
{ 'columns' : 3 } # row 4, has three columns
]
Metadata
Release files for simple-fpdf 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| simple-fpdf-0.1.0.tar.gz | 16.0 kB | Without provenance | Details for simple-fpdf-0.1.0.tar.gz |
Release files / simple-fpdf-0.1.0.tar.gz
| Download URL | simple-fpdf-0.1.0.tar.gz |
|---|---|
| Size | 16.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
613b499d0b4c601b9c7c45b052736c9fbf2cc03a51a95efc6c96c598398815a0
|
|
BLAKE2b-256 checksum How to use checksums |
583e42e49b9c4824cd2090264f22626eb353d3527e3fc35459220edb9f230d3f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.9.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.13 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.4
|
Security for simple-fpdf 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.