PDF File Generation using Python

Available Python PDF Libraries

Basic Requirements

class PDF(FPDF):  
def header(self)
def footer(self)
# add roboto-bold font with unicodefpdf.add_font(‘roboto-bold’, ‘Roboto/Roboto-Bold.ttf’, uni=True)# set roboto-bold 15 ( font size)fpdf.set_font(‘roboto-bold’, ‘B’, 15)
# add Colors of frame, background and textfpdf.set_draw_color(34,139,34)
fpdf.set_fill_color(0, 0, 0)
fpdf.set_text_color(255, 255, 255) or self.set_text_color(128)
# Thickness of frame (1 mm)
fpdf.set_line_width(1)
# add text
fpdf.cell(30, 9, ‘text, 1, 1, ‘C’, 1)
# add adjusted centered multi cell
fpdf.multi_cell(30, 6, ‘text’, 0, ‘C’, 0)
# Line break
fpdf.ln(10)
# set margins
fpdf.set_margins(0, 0, 0)
# set x,y coordinationfpdf.set_xy(2, 5)# Position at 1.5 cm from bottomfpdf.set_y(-15)
# draw a rectanglefpdf.rect(x: float, y: float, w: float, h: float, style = ‘’)# add ellipsefpdf.ellipse(x=20, y=30, w=40, h=40,style=’F’)# add a triangle, it supports also other polygon typescoords = ((p1, p2), (p3, p2), (p4, p5))fpdf.polygon(coords, fill=True)# add linefpdf.line(100,0,0,100)
# add imagefpdf.image(file_path_name, x = None, y = None, w = 100, h = 100, type = ‘’, link = ‘’)
# add a pagefpdf.add_page(orientation=’’)
# add page breakfpdf.set_auto_page_break(auto=False)

Use Cases

Generating PDF reports from Excel Files

Placing Images into PDF Page

Adding Two Column Texts

Adding Texts on Custom Designed Pages

Creating Pure Art-Oriented Pages

Creating Book Chapters

Creating Custom Calendar

Summary

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Enhancing Istio Operations with Kong Istio Gateway

Legacy Modernization | Time to reinvent the Wheel

Top 30 Product Manager job interview questions I have ever been asked [2020–2022]

Adding two matrixes with different row numbers.

New Rewards with Pulse Farms on Ref Finance

Build Long Lasting Relationships: What To Look For.

How to Build a Telemedicine App?

how to build a telemedicine app post

Commits Made During the Coding Period

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
cem akpolat

cem akpolat

More from Medium

Getting started with Playwright | Scraping a basic webpage with Playwright in Python.

Python Scripting with GDAL

How to Upload Files to SharePoint Using Python

Discover Your Day Of Birth Using Python