simple_pdf

PDF Generation with Multi-Engine Support for Eiffel

Service Layer v1.0.0 MIT

Overview

simple_pdf provides HTML-to-PDF conversion for Eiffel applications using multiple rendering engines. Convert HTML strings, files, or URLs to PDF with full control over page size, orientation, and margins.

All Windows binaries are bundled - no separate installation required. Choose between wkhtmltopdf (default, bundled) or Chrome/Edge (best CSS support) for rendering.

API Integration

simple_pdf is part of the simple_* API hierarchy:

FOUNDATION_API (core utilities: json, uuid, base64, validation, etc.)
       ↑
SERVICE_API (services: jwt, smtp, sql, cors, cache, websocket, pdf)
       ↑
APP_API (full application stack)

Using via SERVICE_API or APP_API

If your project uses simple_service_api or simple_app_api, you automatically have access to simple_pdf - no additional ECF entry needed:

local
    api: SERVICE_API
    doc: SIMPLE_PDF_DOCUMENT
do
    create api.make
    -- Using convenience method
    doc := api.html_to_pdf (build_report_html)
    -- Or get the PDF generator for more control
    doc := api.new_pdf.page ("Letter").landscape.from_html (report_html)
    if doc.is_valid then
        doc.save_to_file ("report.pdf")
    end
end

Standalone Installation

For projects that only need PDF functionality:

<library name="simple_pdf" location="$SIMPLE_EIFFEL/simple_pdf/simple_pdf.ecf"/>

Quick Start

Installation

<library name="simple_pdf" location="$SIMPLE_EIFFEL/simple_pdf/simple_pdf.ecf"/>

Basic Usage

local
    pdf: SIMPLE_PDF
    doc: SIMPLE_PDF_DOCUMENT
do
    create pdf.make
    doc := pdf.from_html ("<h1>Hello World</h1>")
    doc.save_to_file ("output.pdf")
end

With Page Settings (Traditional)

create pdf.make
pdf.set_page_size ("Letter")
pdf.set_orientation ("Landscape")
pdf.set_margins ("1in")

doc := pdf.from_url ("https://example.com")
doc.save_to_file ("website.pdf")

Fluent API

Chain configuration calls for concise, readable code:

create pdf.make
doc := pdf.page ("Letter").landscape.margin_all ("1in").from_url ("https://example.com")
doc.save_to_file ("website.pdf")

Fluent API

The fluent API allows chaining configuration calls in a single expression:

Fluent Features

FeatureDescription
page (size)Set page size (A4, Letter, Legal)
portraitSet portrait orientation
landscapeSet landscape orientation
margin_all (margin)Set all margins to same value
margin_top/bottom/left/rightSet individual margins
margins (top, bottom, left, right)Set all four margins
with_wkhtmltopdfSwitch to wkhtmltopdf engine
with_chromeSwitch to Chrome engine

Fluent API Examples

Basic report with Letter size, landscape:

create pdf.make
doc := pdf.page ("Letter").landscape.from_html (report_html)
doc.save_to_file ("report.pdf")

Website capture with custom margins:

create pdf.make
doc := pdf.page ("A4").portrait.margin_all ("15mm").from_url ("https://example.com")

Using Chrome for complex CSS:

create pdf.make
doc := pdf.with_chrome.page ("Letter").margins ("1in", "1in", "0.75in", "0.75in").from_html (styled_html)

Document with different top/bottom margins:

create pdf.make
doc := pdf.page ("A4").margin_top ("30mm").margin_bottom ("20mm").margin_left ("25mm").margin_right ("25mm").from_file ("template.html")

Quick A4 portrait (defaults):

create pdf.make
doc := pdf.from_html ("<h1>Simple PDF</h1>")  -- Uses A4 portrait by default

Comparison

Traditional (5 lines):

create pdf.make
pdf.set_page_size ("Letter")
pdf.set_orientation ("Landscape")
pdf.set_margin_top ("25mm")
pdf.set_margin_bottom ("25mm")
doc := pdf.from_html (report_html)

Fluent (2 lines):

create pdf.make
doc := pdf.page ("Letter").landscape.margins ("25mm", "25mm", "20mm", "20mm").from_html (report_html)

Features

Multi-Engine

wkhtmltopdf (bundled) or Chrome/Edge headless

HTML to PDF

Convert strings, files, or URLs to PDF

Text Extraction

Extract text from existing PDFs via pdftotext

Bundled Binaries

No external installation required on Windows

Using Chrome for Best CSS

-- Chrome/Edge provides best CSS rendering
create pdf.make_with_engine (create {SIMPLE_PDF_CHROME})
doc := pdf.from_html (complex_css_html)
doc.save_to_file ("styled.pdf")

Text Extraction

local
    reader: SIMPLE_PDF_READER
    text: STRING
do
    create reader.make
    if reader.is_available then
        text := reader.extract_text ("document.pdf")
        -- Or specific pages
        text := reader.extract_pages ("document.pdf", 1, 5)
    end
end

Engine Availability Check

local
    engines: SIMPLE_PDF_ENGINES
do
    create engines
    print (engines.report)
    -- Shows which engines are available
end

API Reference

SIMPLE_PDF (Main API)

make

create pdf.make

Create PDF generator with default wkhtmltopdf engine.

Ensure

default_page_size: page_size.same_string ("A4")

make_with_engine (a_engine: SIMPLE_PDF_ENGINE)

create pdf.make_with_engine (create {SIMPLE_PDF_CHROME})

Create PDF generator with specified rendering engine.

Conversion Features

FeatureDescription
from_html (html)Convert HTML string to PDF
from_file (path)Convert HTML file to PDF
from_url (url)Convert URL to PDF

Page Settings

FeatureDescription
set_page_size (size)A4, Letter, Legal, etc.
set_orientation (orient)Portrait or Landscape
set_margins (margin)Set all margins (e.g., "10mm")
set_margin_top/bottom/left/rightIndividual margins

Engine Management

FeatureDescription
is_availableCheck if engine is ready
use_wkhtmltopdfSwitch to wkhtmltopdf engine
use_chromeSwitch to Chrome/Edge engine

SIMPLE_PDF_DOCUMENT (Result Object)

FeatureDescription
is_validTrue if PDF was generated successfully
error_messageError details if generation failed
save_to_file (path)Save PDF to file
contentRaw PDF bytes
as_base64PDF as base64 string

SIMPLE_PDF_READER (Text Extraction)

FeatureDescription
extract_text (path)Extract all text from PDF
extract_page (path, page)Extract text from single page
extract_pages (path, first, last)Extract text from page range
extract_text_raw (path)Extract without layout

Architecture

SIMPLE_PDF_ENGINE (deferred)
    |-- SIMPLE_PDF_WKHTMLTOPDF (default, bundled)
    |-- SIMPLE_PDF_CHROME (Chrome/Edge headless)

SIMPLE_PDF (main API - delegates to engine)
SIMPLE_PDF_DOCUMENT (result object)
SIMPLE_PDF_READER (text extraction via pdftotext)
SIMPLE_PDF_ENGINES (availability reporter)

Bundled Binaries

BinaryVersionSizePurpose
wkhtmltopdf.exe0.12.6~40MBPDF generation
wkhtmltox.dll0.12.6~40MBwkhtmltopdf library
pdftotext.exe24.08.0~57KBText extraction
Poppler DLLs24.08.0~22MBpdftotext dependencies

Binary Sources

ComponentSourceLicenseDownload
wkhtmltopdf wkhtmltopdf.org LGPL v3 GitHub Releases
Poppler (pdftotext) freedesktop.org GPL v2+ poppler-windows

Updating Binaries

wkhtmltopdf: Download from GitHub releases, extract and replace wkhtmltopdf.exe, wkhtmltox.dll in bin/.

Poppler: Download from poppler-windows, extract Library/bin/ contents to bin/.

Note: wkhtmltopdf 0.12.6 (2020) is the final release. No longer actively maintained but stable and widely used.