Skip to content

mPDF alternative

mPDF Alternative for PHP Teams Whose Layouts Outgrow mPDF and Memory Limits

mPDF is the step up most PHP teams take after dompdf, and for a plain invoice it works. The trouble starts with a flexbox or grid layout, a web font, a chart drawn by JavaScript, or a 400 page statement run that hits the PHP memory limit. An mPDF alternative moves the rendering out of PHP: your code sends the HTML, a managed Chromium prints it, and the PDF comes back identical to what Chrome shows.

  • PDF and archive in one call
  • Plans from $49 a month
  • Your HTML stays yours

Short answer

The best mPDF alternative for layouts that must match the browser is a Chromium based renderer called over HTTP. mPDF implements its own HTML and CSS engine inside PHP, so flexbox and grid are not supported, JavaScript never runs, and large documents are limited by the PHP memory limit. It is also licensed under the GPL v2, which matters if you ship it inside closed source software. A rendering API such as SitePDF takes the same HTML, returns a selectable-text PDF and stores a dated copy of every render. Plans start at $49 a month for 10,000 renders.

Written and fact checked by the SitePDF team.

mPDF against a self-hosted Chromium and a rendering API, on what decides the choice

mPDF and Puppeteer are open source. The SitePDF figures come from our pricing page. The rows that usually decide it are the ones about CSS and about what happens at month-end volume.

mPDF Self-hosted headless Chromium SitePDF API
Where it runs Inside your PHP process Your server, with a browser you patch and scale Managed Chromium, one HTTP call
CSS coverage Its own engine, a subset. No flexbox, no grid Full, it is Chrome Full, it is Chrome
JavaScript, charts, web components No Yes Yes, with a wait condition
Output matches the browser Close for simple tables, often not for modern layouts Yes Yes
Right to left and complex scripts Strong, a real mPDF strength Good, depends on fonts installed Good, fonts embedded as subsets
Very large documents Memory grows with pages, tuned through PHP settings Per tab memory, you size the pool Handled outside your PHP workers
License GPL v2 Apache 2.0 (Puppeteer) Commercial API, no library in your codebase
Cost Free Free plus servers and engineering time From $49/mo ($288 billed yearly) for 10,000 renders, $99/mo for 50,000
Dated archive of every render No No Yes. archive=true, 90 days to 7 years by tier

mPDF is the better tool when the document is mostly text and tables, when you need strong right to left or CJK handling, and when nothing may leave your own server.

When mPDF is still the right tool

mPDF is a mature PHP library with good Unicode support, right to left languages, headers and footers, bookmarks and table of contents. If your document is a text and table invoice with a fixed design and the data must never leave your own infrastructure, a library inside PHP is the simpler architecture and a service would be extra moving parts. The mPDF manual lists the supported CSS properties, which is the quickest way to check whether your template fits.

Where mPDF stops for paying customers

Modern CSS. A design that uses flexbox or grid for the header, the totals block or a card layout will not render the same way, because mPDF does not support those layout modes. Teams end up rewriting the template with nested tables just for the PDF, which means two templates to keep in step. The same ceiling is described for the other PHP engine in our dompdf alternative comparison.

JavaScript. mPDF never executes scripts. A chart drawn by Chart.js or a map arrives as an empty box, so the PDF needs a pre-rendered image of every chart.

Memory on big runs. The whole document is built in PHP memory. A monthly statement batch or a long report can exceed memory_limit and kill the worker, and raising the limit for the web tier to fix one job is an uncomfortable trade. Rendering outside PHP keeps those jobs away from your request workers.

The GPL. mPDF is GPL v2. Using it as a server side tool is common, but a team that distributes a product containing it, or whose lawyer has a view on copyleft, often prefers to call an API and keep the library out of the codebase.

The PHP convert HTML to PDF page puts mPDF next to Dompdf, Browsershot and an API.

What moving from mPDF to a rendering API looks like

You stop building the PDF in PHP and start posting HTML. In Laravel that is usually the Blade view you already show on screen, rendered to a string and sent to the API, instead of $mpdf->WriteHTML(). The nested table workaround can be deleted, because Chromium prints the real layout. The Laravel HTML to PDF page shows the swap in a queued job, and the plans and limits lists the plans, and the render call takes page size, margins and a wait condition.

A worked example with numbers

Take a PHP SaaS that sends 20,000 statement PDFs on the first of each month. With mPDF the team keeps a table based PDF template next to the flexbox web view, and a pre-rendered chart image for each statement. Assume, as a planning figure and not a measurement, 12 hours a year to keep the two layouts in step at $100 an hour, which is $1,200, plus one hour of on-call time each month when a large account exceeds the memory limit. Rendering the same web view through an API removes the second template and moves the heavy jobs off your workers. 20,000 renders fit in the Growth plan at $99 a month, or $588 a year when billed yearly at about $49 a month. Replace the hours with your own and the comparison is easy to redo.

Which alternative for which case

Fixed text and table documents, right to left languages, data that stays on your servers: keep mPDF. Layouts built with flexbox, grid or JavaScript: use Chromium. Chromium can run on your own servers, and we put numbers on that in what Playwright costs in production, or it can be called as an API. If you are weighing hosted services, the best HTML to PDF API roundup lists them with prices.

A Laravel controller: render the Blade view you already have, get a selectable-text PDF and an archived copy.
// Replaces $mpdf->WriteHTML(...) in the statement job
$html = view('statements.show', ['statement' => $statement])->render();

$response = Http::withToken(config('services.sitepdf.key'))
    ->asForm()
    ->post('https://api.sitepdf.com/v1/render', [
        'html' => $html,
        'format' => 'A4',
        'archive' => 'true',
    ]);

return $response->json(); // contains the PDF URL

This is the documented API call shape. Full request and response walkthrough.

Questions about this job

What is the best alternative to mPDF?
It depends on the template. For text and table documents, dompdf or TCPDF based libraries are close in scope. For layouts that use flexbox, grid, web fonts or JavaScript, a Chromium based renderer is the better fit, either self-hosted with Puppeteer or Playwright or called as an API.
Does mPDF support flexbox or CSS grid?
No. mPDF uses its own HTML and CSS engine and does not implement flexbox or grid, so those layouts must be rewritten with tables or floats. A Chromium renderer supports both because it is the same engine that draws the page in Chrome.
Does mPDF run JavaScript?
No. mPDF never executes scripts, so charts and dynamic content drawn by JavaScript do not appear. You need pre-rendered images or a headless browser to capture them.
Why does mPDF run out of memory?
mPDF builds the whole document in PHP memory, so long tables, many images and large batches can exceed the memory limit. Splitting the document or raising the limit helps, and rendering outside PHP removes the pressure from your web workers.
Is mPDF free for commercial use?
mPDF is released under the GPL v2. Using it on your own server is common, but distributing software that contains it carries copyleft obligations, so many teams ask their counsel or choose an API instead. Read the license in the mPDF repository for your case.
How much does an mPDF alternative cost?
Open source libraries and self-hosted Chromium cost no license fee but cost servers and maintenance time. SitePDF API plans start at $49 a month for 10,000 renders, or $288 billed yearly, and $99 a month for 50,000 renders.

Index

More PDF and archiving tools

Get started

Render and archive with one API call

A pixel perfect PDF and a dated copy of the page from the same request. Plans from $49 a month, half price billed yearly.

HTML to PDF, in your browser

Buy the plan