Skip to main content

Convert HTML (with CSS, SCSS, icons, and images) to PDF with async/threaded support

Project description

RapidHtml2Pdf

Convert HTML (with CSS, SCSS, icons, and images) to PDF with async and threaded support.

Features

  • Parse and inline HTML, CSS/SCSS, and inline, internal external stylesheets
  • Embed images, fonts (including Font Awesome, Google Fonts) as base64
  • Asynchronous asset fetching for performance
  • Dynamic single-page fitting to avoid blank pages
  • CLI command h2p for easy usage

Installation

pip install h2p
# Then install Playwright browsers:
python -m playwright install

Usage

Synchronous

from RapidHtml2Pdf import html_to_pdf, PDFOptions

html = '<html><body><h1>Hello PDF</h1></body></html>'
options = PDFOptions(fit_to_one_page=True)
html_to_pdf(html, 'output.pdf', options)

Asynchronous

import asyncio
from RapidHtml2Pdf import html_to_pdf_async, PDFOptions

async def main():
    html = '<html><body><h1>Async PDF</h1></body></html>'
    options = PDFOptions(fit_to_one_page=False)
    await html_to_pdf_async(html, 'async_output.pdf', options)

asyncio.run(main())

CLI

RapidHtml2Pdf input.html output.pdf --fit-to-one-page

Configuration

Customize options via PDFOptions:

Option Type Default Description
page_size str A4 Paper size (A4, Letter, etc.)
orientation str portrait portrait or landscape
margins dict top/bottom/left/right = 10mm Margins in mm
fit_to_one_page bool True Auto-fit content to a single page if possible

Development & Testing

git clone https://github.com/Xyhercode/h2p.git
cd RapidHtml2Pdf
pip install -e .
pytest

CI Workflow

Continuous integration runs on push and PR, testing on Linux, Windows, and macOS with Python 3.8 & 3.11, builds distributions.

License

MIT © RAKESH SHARMA

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rapidhtml2pdf-0.1.5.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rapidhtml2pdf-0.1.5-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file rapidhtml2pdf-0.1.5.tar.gz.

File metadata

  • Download URL: rapidhtml2pdf-0.1.5.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.6

File hashes

Hashes for rapidhtml2pdf-0.1.5.tar.gz
Algorithm Hash digest
SHA256 e305b49034406f648d786733fba469b45f5298a5f9b2d7a6b7eaf35a342ef16d
MD5 96dfa8fa3a70e56b5404437625e90bb7
BLAKE2b-256 8bf19a47309083df82d51ffb038ba237d831a63d16ad01075704655f04c8c743

See more details on using hashes here.

File details

Details for the file rapidhtml2pdf-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: rapidhtml2pdf-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.6

File hashes

Hashes for rapidhtml2pdf-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 84fa490cfc53557baaf378f92f71cb2278da37849fe6a5c61e936219ae470a9b
MD5 6cd3d0415f78d0d230d3c28e40e208d4
BLAKE2b-256 a178e53f51a03ed1b43764b03f121a952e2d413f54e72df0c5114a8a0fd6636c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page