digidigital / Extensions-and-Scripts-for-pyFPDF-fpdf2

This repository contains some of the original FPDF PHP scripts that were ported to Python to be used in conjunction with fpdf2.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extensions / Scripts for pyFPDF (fpdf2)

This repository contains some of the original FPDF PHP Scripts that were ported to Python to be used in conjunction with fpdf2 (as well as some new scripts).

My main goal was on translating the scripts 1:1 without a focus on "pythonic elegance" or optimizations.

Some of the functions demonstrated in these scripts have already found their way into fpdf2. Whenever possible, you should use the alternatives implemented in fpdf2. On the other hand, some functions in the scripts may work (slightly) different and add value to your projects or adress edge cases.

It is possible that the scripts do not work correctly with newer versions of fpdf2 or Python! Please check the "Tested with" info for each script.

Scripts

Alpha / Transparency for pyFPDF (fpdf2)

This script adds transparency support to pyFPDF. You can set the alpha channel from 0 (fully transparent) to 1 (fully opaque). It applies to all elements (text, drawings, images).

Tested with fpdf2 2.4.5, Pillow 8.3.1, Python 3.8.10

OBSOLETE! This is now available in fpdf2

Example

Transparent text, images and drawings in pyFPDF

PDF File

Get the code

Code

Masking images / Alpha channel

This script exposes the feature to add transpareny to an image by supplying a separate PNG image (called a soft mask).

Tested with fpdf2 2.4.5, Pillow 8.3.1, Python 3.8.10

Example

Soft Mask

PDF File

Get the code

Code

360 Degree Text

This script adds 360 degree text. B, U and I are supported.

Tested with fpdf2 2.4.5, Pillow 8.3.1, Python 3.8.10

Example

360 Degree Text

PDF File

Get the code

Code

Transform & Circular Text

This script adds transfromation featurea ans support for circular text to pyFPDF.

Tested with fpdf2 2.4.5, Pillow 8.3.1, Python 3.8.10

Example

Transform, rotate, shear, mirror text, images and drawings in pyFPDF

Circular round text in pyFPDF

PDF file

Get the code

Code

Diagrams

Draw pie charts and bar diagrams with this script.

Tested with fpdf2 2.4.5, Pillow 8.3.1, Python 3.8.10

Example

Pie charts and bar diagrams with pyFPDF

PDF file

Get the code

Code

Embed Javascript in PDF

This script allows to embed JavaScript inside the PDF. The code is executed when the document is opened.

The Acrobat JavaScript reference is available here.

Note: Support depends on the PDF viewer and security settings.

Tested with fpdf2 2.4.5, Pillow 8.3.1, Python 3.8.10

Example

PDF File

Get the code

Code

Rectangle with rounded corners

Draw rectangles with rounded corners

Tested with fpdf2 2.4.5, Pillow 8.3.1, Python 3.8.10

OBSOLETE! This is now available in fpdf2

Example

Draw a rectangle with rounded corners in pyFPDF

PDF file

Get the code

Code

Sectors of circle shapes

This script allows to draw segments of a circle. It can be used to render a pie chart.

Tested with fpdf2 2.4.5, Pillow 8.3.1, Python 3.8.10

Example

Pie charts in pyFPDF

PDF file

Get the code

Code

Star shape

This script draws a star.

Tested with fpdf2 2.4.5, Pillow 8.3.1, Python 3.8.10

OBSOLETE! This is now available in fpdf2

Example

Star shapes

PDF file

Get the code

Code

Visibility feature

This script allows to restrict the rendering of some elements to screen or printout. This can be useful, for instance, to put a background image or color that will show on screen but won't print.

Note: this feature is not supported by all PDF viewers.

Some Test on Ubuntu 20.04:

  • Chromium 94.0.4606.81 (Works as intended)
  • Google Chrome 94.0.4606.81 (Works as intended)
  • Evince 3.36.10 (Does not display content marked for screen display, but displays content marked for printing)
  • Okular 21.08.2 (Same result as for Evince)
  • Firefox 93.0 (Ignores restrictions and displays all content)

Script was tested with fpdf2 2.4.5, Pillow 8.3.1, Python 3.8.10

Get the code

Code

Linear, radial and multi-color gradients

Paints linear and radial gradients as well as multi-color gradients (coons patch meshes) inside a rectangle.

Tested with fpdf2 2.4.5, Pillow 8.3.1, Python 3.8.10

Example

Linear and radial gradients in pyFPDF Multi-color gradients in pyFPDF

PDF File

Get the code

Code

Stamp and Watermark PDF files

This script adds support for stamps (overlay) and watermarks (underlay) to PDF files by modifying the 'header()' and 'footer()' functions.

Tested with fpdf2 2.4.5, Pillow 8.3.1, Python 3.8.10

Example

Mass stamping or watermarking PDF files

PDF File

Get the code

Code

Adjust text to cell width

This method is an extension of cell() allowing to output text with either character spacing or horizontal scaling.

Tested with fpdf2 2.4.5, Pillow 8.3.1, Python 3.8.10

Example

Fill cell() with text

PDF File

Get the code

Code

Skew, shear and rotate text

This extension allows to print rotated and sheared (i.e. distorted like in italic) text.

Tested with fpdf2 2.4.5, Pillow 8.3.1, Python 3.8.10

Example

Skew, shear and rotate text in pyFPDF

PDF File

Get the code

Code

Sinus (Sine) Text

This script adds wiggly text :)

Tested with fpdf2 2.4.5, Pillow 8.3.1, Python 3.8.10

Example

Sinus Text in FPDF

PDF File

Get the code

Code

About

This repository contains some of the original FPDF PHP scripts that were ported to Python to be used in conjunction with fpdf2.

License:MIT License


Languages

Language:Python 100.0%