โ† Back to Blog

Automate PDF Generation from HTML: Developer Guide

Generating PDFs programmatically is one of the most common โ€” and most painful โ€” tasks in web development. HTML-to-PDF conversion libraries are notoriously inconsistent. Let's fix that with a simple API call.

The Problem with PDF Generation

If you've ever tried generating PDFs in code, you know the pain:

Our API uses Playwright with Chromium, giving you the same rendering quality as Chrome's "Print to PDF" โ€” via a single GET request.

Quick Start

curl "https://tools.f5rvoice.com/api/v1/pdf?url=https://example.com&apikey=YOUR_KEY" -o page.pdf

Parameters

Parameter Default Description
url required Web page URL to convert
format A4 Page size: A4, Letter, A3, Legal
landscape false Landscape orientation
printBackground true Include background colors/images

Generate Invoice PDF

import requests

# Your invoice is a hosted HTML page
invoice_url = "https://myapp.com/invoice/12345"

response = requests.get("https://tools.f5rvoice.com/api/v1/pdf", params={
    "url": invoice_url,
    "format": "A4",
    "apikey": "YOUR_KEY"
})

with open("invoice_12345.pdf", "wb") as f:
    f.write(response.content)

Landscape Report

curl "https://tools.f5rvoice.com/api/v1/pdf?url=https://myapp.com/report&landscape=true&format=Letter&apikey=YOUR_KEY" -o report.pdf

Use Cases

  1. Invoice generation โ€” Convert HTML invoices to downloadable PDFs
  2. Report automation โ€” Schedule weekly dashboard exports as PDFs
  3. Contract generation โ€” Merge dynamic data into HTML templates, export as PDF
  4. Receipt emails โ€” Attach auto-generated PDF receipts to order confirmations
  5. Certificate generation โ€” Create completion certificates with dynamic names/dates

Tips for Best Results

CSS Print Styles

Add @media print CSS to your HTML for optimal PDF output:

@media print {
  .no-print { display: none; }
  body { font-size: 12pt; }
  @page { margin: 2cm; }
}

Page Breaks

Control pagination with CSS:

.page-break { page-break-after: always; }
h2 { page-break-after: avoid; }
table { page-break-inside: avoid; }

Conclusion

Stop wrestling with PDF libraries. Our API converts any web page to a high-quality PDF using the same engine as Google Chrome. Perfect for invoices, reports, certificates, and any document automation.

Try it free โ€” 100 requests/month โ†’

Ready to try WebTools API?

Get 100 free requests per month. No credit card required.

Get Free API Key โ†’