Simple FPDF
Project description
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
]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file simple-fpdf-0.1.0.tar.gz
.
File metadata
- Download URL: simple-fpdf-0.1.0.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 613b499d0b4c601b9c7c45b052736c9fbf2cc03a51a95efc6c96c598398815a0 |
|
MD5 | 447cd41fb32b5c448f0483510ced7e7a |
|
BLAKE2b-256 | 583e42e49b9c4824cd2090264f22626eb353d3527e3fc35459220edb9f230d3f |