HTML and Text to PDF using Python

The Data science world has evolved with visualization techniques, but it's of no use if we can not generate reports at the end of the day. We can generate patterns but now its time to store them in the more representable form for the coming generations.

Photo by Isaac Smith on Unsplash

PDFGEN

Installation and Requirements

pip install pdfgen

Usage

import pdfgenasync def f():
## FOR WEBITES
await pdfgen.from_url('http://google.com', 'out.pdf')

## FOR HTML FILES
await pdfgen.from_file('test.html', 'out.pdf')

## FOR TEXT FILES
await pdfgen.from_string('Hello!', 'out.pdf')
import pdfgenpath = 'Path where you want to store output file'
await pdfgen.from_string('Hello!', path)

Options

Source: https://www.npmjs.com/package/pdfgen

Format options

## Initializing an option dictionary
options = {
'format': 'Letter', ## format of the paper
'margin': { ## margin in the pdf
'top': '0.75in',
'right': '0.75in',
'bottom': '0.75in',
'left': '0.75in',
},
'pageRanges': '1-5,8', ## pages which needed to be printed
}
## "option" used in sytax :
pdfgen.sync.from_url('http://google.com', 'out.pdf', options=options)

Just a Little more appreciation

Data Scientist at HiLabs| Enthusiastic ML practitioner | IIT Kanpur | Drama Lover | Subscribe https://www.youtube.com/channel/UCqq_T7ktsZO62k7CaibgQvA