โ† Back to Blog

HTML and Markdown to PDF: Professional Conversion for Reports and Documentation

FlipFiles Pro ยท June 2026 ยท 8 min read

Developers, technical writers, and content teams regularly need to produce PDF documentation from HTML or Markdown sources. Whether you are generating customer-facing reports, technical documentation, invoices from HTML templates, or converting Markdown notes to shareable PDFs, the quality of the conversion matters. WeasyPrint, the library behind FlipFiles Pro's HTML/Markdown to PDF conversion, is the most capable open-source tool available for this purpose.

Why HTML to PDF Is Harder Than It Appears

A browser renders HTML on screen in a continuous flow โ€” pages are as long as the content requires. A PDF is fixed-page โ€” content must be divided into pages of a fixed size, with page breaks occurring at appropriate points. Page numbers, headers, and footers must be added. Fonts must be embedded. Images must be positioned correctly on each page. This translation from continuous flow to paginated output is what makes HTML-to-PDF conversion technically complex.

What WeasyPrint Supports

WeasyPrint is a CSS-based PDF generation library that implements a significant subset of the CSS Paged Media standard โ€” the specification that defines how web content should be converted to printed pages. It supports:

  • Full CSS2.1 and most CSS3 (Flexbox, Grid, custom properties)
  • CSS Paged Media โ€” page size, margins, headers, footers, page numbers via CSS
  • Embedded fonts (web fonts loaded from URLs or local files)
  • SVG images (rendered as vectors in the PDF)
  • Tables with proper page break handling
  • Automatic table of contents generation from heading elements

Adding Page Numbers via CSS

WeasyPrint supports CSS @page rules for adding page numbers, headers, and footers. Include this CSS in your HTML to add page numbers:

@page {
  margin: 20mm;
  @bottom-right {
    content: "Page " counter(page) " of " counter(pages);
    font-size: 10pt;
    color: #666;
  }
}

Markdown to PDF Workflow

FlipFiles Pro converts Markdown to PDF through an intermediate HTML step. The Markdown is first converted to HTML using the Python Markdown library (with table, fenced code block, and TOC extensions enabled), then WeasyPrint renders the HTML to PDF with a professional stylesheet applied.

The default FlipFiles Pro Markdown stylesheet produces output with:

  • A4 pages with 20mm margins
  • Readable 11pt body text with 1.6 line height
  • Blue heading styles (matching the FlipFiles brand)
  • Styled code blocks with monospace font and grey background
  • Table styling with header rows and alternating row colours
  • Automatic page breaks before major headings

Common Use Cases

  • Technical documentation โ€” API docs, developer guides, README files converted to PDF for distribution
  • Report generation โ€” Data reports generated as HTML with charts (Chart.js, D3) converted to PDF for stakeholder distribution
  • Invoice and receipt generation โ€” HTML invoice templates with dynamic data converted to PDF for professional billing
  • Knowledge base articles โ€” Markdown-written knowledge base content exported as PDF for offline sharing

Try it free

5 free jobs/month. All 145 tools. No credit card.

Start Free โ†’
๐Ÿ”’
Privacy commitment
Files uploaded to FlipFiles Pro are permanently deleted within 30 minutes. We never store or share your files. For zero-upload tools, visit FlipFiles.io.