PHP convert HTML to PDF
PHP Convert HTML to PDF With a Chromium Rendering API
SitePDF is the way to convert HTML to PDF from PHP with one HTTP call and real Chromium output, so there is no wkhtmltopdf binary and no headless browser on your server. It suits PHP teams whose invoices, statements and reports outgrew Dompdf or mPDF.
- PDF and archive in one call
- Plans from $49 a month
- Your HTML stays yours
Short answer
To convert HTML to PDF in PHP without running a renderer yourself, post the HTML to a rendering API and store the PDF it returns. SitePDF uses managed Chromium, so flexbox, grid, web fonts and print CSS print the way they look in the browser. Starter API is $49 a month for 10,000 renders ($288 billed yearly), Growth is $99 a month for 50,000 and Scale is $299 a month for 250,000.
Written and fact checked by the SitePDF team.
The common ways to convert HTML to PDF in PHP
These are the routes PHP teams pick most often. The right one depends on how complex the HTML is and who looks after the server.
| Route | How it renders | CSS you can rely on | What you run | Where it hurts |
|---|---|---|---|---|
| Dompdf | Its own PHP layout engine | CSS 2.1 and part of CSS 3, no flexbox or grid | A Composer package | Modern layouts need a table based rewrite |
| mPDF | Its own PHP layout engine | Wide HTML and CSS subset, no flexbox or grid | A Composer package | Memory use on long documents, a second print template |
| TCPDF | Writes PDF commands directly | A small HTML subset | A Composer package | Templates become code, not HTML |
| wkhtmltopdf with a wrapper | An old WebKit engine | No modern CSS, limited JavaScript | A system binary and fonts | The project is archived, so nobody fixes new issues |
| Browsershot | Real Chrome through Puppeteer | What Chrome supports | Node, Puppeteer and Chromium on the server | You operate a browser, its memory and its updates |
| SitePDF API | Managed Chromium | What Chrome supports, with print CSS | Nothing, one HTTP call | Document content leaves your servers, and you pay per render |
Plans and prices are from our own pricing page. Library notes are from the projects: Dompdf, wkhtmltopdf status and Browsershot.
When a PHP library is enough and when it is not
A plain letter, a receipt or a one page certificate converts well with Dompdf or mPDF, and there is no reason to pay for an API. The trouble starts when the same HTML must look like your web app, with a flexbox header, a grid of line items, a web font and a chart.
Then the library renders something close but not equal, and a developer keeps a second print template that drifts from the first. If that is your situation, the pages on a Dompdf alternative and an mPDF alternative show the differences in detail.
A worked example with numbers
These are planning assumptions, not measurements. A small SaaS such as Testimonialmanager, which lets customers collect and show quotes, wants an exportable PDF report of those quotes for each client, about 6,000 PDFs a month. The report uses a grid of quote cards and a web font.
Running Browsershot yourself, assume 16 hours of setup at $75 an hour, a $20 a month server, and 3 hours a month of upkeep for browser updates, fonts and memory crashes. Year one is $1,200 plus $240 plus $2,700, or $4,140. Starter API at $288 billed yearly covers 6,000 renders a month with room to spare, so year one is $288. Your hourly rate and upkeep time will differ, so replace those figures with yours.
How the call works from PHP
Render your Blade, Twig or plain PHP template to a string as you do today, then send it. The response holds the PDF address, which you download or hand to the user. Pass archive to keep a dated copy, format for page size, and header_html and footer_html for page numbers on multi page documents.
Laravel teams can read the Laravel version of this page and the general PDF generator API page for the full list of options.
What does not carry over
The API renders HTML to a PDF and nothing else, so it does not merge, split or fill form fields in existing PDFs, and it does not sign documents. Pages behind a login need cookies or headers passed on the call. Your document content is sent to an outside service, which some regulated teams cannot do, and a PHP library keeps it inside your own network.
Who it is for and who it is not for
It is for PHP teams with a developer who can make an HTTP call, whose invoices, statements or reports are already HTML and need to match the screen, from a few thousand to a few hundred thousand documents a month. Product teams that bill on a monthly cycle can see the sizing on HTML to PDF API for SaaS.
It is not for one off letters, fixed layout forms, teams that must keep all content in house, or very high volumes where a tuned cluster of your own would cost less.
<?php
$html = file_get_contents(__DIR__ . '/statement.html');
$ch = curl_init('https://api.sitepdf.com/v1/render');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('SITEPDF_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'html' => $html,
'format' => 'A4',
'archive' => true,
]),
]);
$result = json_decode(curl_exec($ch), true);
$pdfUrl = $result['pdf_url'];
This is the documented API call shape. Full request and response walkthrough.
Questions about this job
How do I convert HTML to PDF in PHP?
What is the best PHP library to convert HTML to PDF?
Can PHP convert HTML to PDF without wkhtmltopdf?
How much does an HTML to PDF API cost for PHP?
Is there a SitePDF PHP package?
Index
More PDF and archiving tools
- Convert HTML to PDF
- Webpage to PDF
- URL to PDF API
- Website archiving
- Monitor website changes
- Screenshot API
- React to PDF
- Java PDF library
- C# PDF library
- Python PDF generation
- HTML to PDF Node.js
- Laravel HTML to PDF
- Vue to PDF
- Next.js PDF generator
- Angular to PDF
- Markdown to PDF API
- Django HTML to PDF
- Blazor HTML to PDF
- Spring Boot HTML to PDF
- Airtable to PDF
- Svelte to PDF
- Rotativa alternative
- Zapier and Make HTML to PDF
- Golang HTML to PDF
- Rails HTML to PDF
- PDF generator API
- Website archiving software
- Document generation API
- Legal document automation software
- Document automation software
- Bulk HTML to PDF
- Accessible PDF generation
- ADA compliance audit cost
- 508 compliance testing
- PDF remediation
- VPAT and ACR
- PDF accessibility checker
- Wayback Machine alternative
- Best HTML to PDF API
- DocRaptor alternative
- Puppeteer alternative
- Wkhtmltopdf alternative
- PDFShift pricing and alternative
- Urlbox pricing and alternative
- PDFCrowd alternative
- Api2Pdf alternative
- Browserless alternative
- APITemplate alternative
- CraftMyPDF alternative
- PDFMonkey alternative
- dompdf alternative
- WeasyPrint alternative
- jsPDF alternative
- mPDF alternative
- Website archiving pricing comparison
- HTML to PDF API for ecommerce
- HTML to PDF API for SaaS
- HTML to PDF API for accounting software
- PrinceXML alternative
- PDFreactor alternative
- PDF integrity check
- Invoice PDF archive
- PDF page numbers, headers and footers
- PDF of pages behind a login
- Website archiving for law firms
- React PDF renderer alternative
- Gotenberg alternative
- GrabzIt alternative
- Adobe PDF Services API
- PDF SDK pricing
- HTML to image API pricing
- Adobe Document Generation API pricing
- jsreport pricing
- PDFBolt pricing
- PDFEndpoint pricing
- Formstack Documents pricing
- Documint pricing
- iLovePDF API pricing
- Browserless pricing
- PandaDoc API pricing
- CloudConvert API pricing
- Encodian pricing
- IronPDF pricing
- Salesforce document generation pricing
- Winnovative pricing
- SelectPdf, HiQPdf and EvoPdf pricing
- CloudConvert alternative
- Direct mail API pricing
- E-signature API pricing
- Sparticuz Chromium Lambda cost
- Browserbase pricing
- Aspose PDF pricing
- PDF API pricing
- How it works
- Features
- Pricing
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.