Skip to content

pg_mupdf

Convert HTML to PDF inside PostgreSQL using MuPDF

pg_mupdf · Convert HTML to PDF inside PostgreSQL using MuPDF

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
100343pg_mupdfpg_mupdf2.0UTILMITC

PostgreSQL · 9.4, 9.5, 9.6, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19

Usage

Sources:

pg_mupdf converts HTML into PDF inside the PostgreSQL backend. Upstream tested PostgreSQL 9.4 through 19 and requires MuPDF 1.24 or later.

Basic use

CREATE EXTENSION pg_mupdf;

SELECT octet_length(mupdf('<h1>Report</h1>'::text)) AS pdf_bytes;

The function returns bytea. Read the bytes through a database client to save the file. Upgrade an existing 1.0 installation with ALTER EXTENSION pg_mupdf UPDATE. Version 2.0 accepts both text and bytea. Text is converted to UTF-8 in databases with a declared encoding. Binary input preserves the original bytes.

Runtime behavior

Superusers can limit input parsers with pg_mupdf.document_handlers, which defaults to html,xhtml. The per-call pg_mupdf.memory_limit defaults to 1GB. Setting it to 0 removes the limit. Both overloads grant execution to PUBLIC by default.

Table reader