<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: PDFglyph</title>
    <description>The latest articles on DEV Community by PDFglyph (@pdfglyph).</description>
    <link>https://dev.to/pdfglyph</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4263727%2F75babf88-105c-4117-8b46-8e6d94f32d9c.png</url>
      <title>DEV Community: PDFglyph</title>
      <link>https://dev.to/pdfglyph</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pdfglyph"/>
    <language>en</language>
    <item>
      <title>Generating PDF invoices without running Puppeteer in production</title>
      <dc:creator>PDFglyph</dc:creator>
      <pubDate>Wed, 25 Nov 2026 03:35:47 +0000</pubDate>
      <link>https://dev.to/pdfglyph/generating-pdf-invoices-without-running-puppeteer-in-production-53gc</link>
      <guid>https://dev.to/pdfglyph/generating-pdf-invoices-without-running-puppeteer-in-production-53gc</guid>
      <description>&lt;p&gt;Every side project that needs a PDF ends up in the same place. You search "generate PDF from HTML node", the first answer is Puppeteer, and twenty minutes later you have an invoice coming out of headless Chrome on your laptop. It looks great. You ship it.&lt;/p&gt;

&lt;p&gt;Then production happens.&lt;/p&gt;

&lt;h3&gt;
  
  
  What headless Chrome costs you in production
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Docker image ;&lt;/strong&gt; chromium needs a pile of shared libraries that slim Node images don't ship. You either switch to a fat base image or copy a list of apt packages from an old blog post and hope. My image grew by about 400 MB either way.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The sandbox flags :&lt;/strong&gt; every example tells you to launch with &lt;code&gt;--no-sandbox&lt;/code&gt;. Most of us paste it without reading it. That flag disables Chrome's process isolation, on a process that renders arbitrary HTML, inside your network.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Memory :&lt;/strong&gt; each page is a real browser tab. A handful of concurrent renders and a small VPS starts swapping. On serverless it's worse: cold-starting Chromium adds seconds to every invocation, if the runtime lets you do it at all.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Zombies :&lt;/strong&gt; a render that crashes halfway leaves Chrome processes behind. They pile up quietly until the worker falls over at 3am and you spend a morning learning about process reaping.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rendering drift :&lt;/strong&gt; chromium updates can change how your documents look. If you don't pin the version, an invoice from March and one from April may not match.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can solve all of this. People do. It's just a strange thing to sign up for when what you wanted was an invoice.&lt;/p&gt;

&lt;h3&gt;
  
  
  The actual options
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Keep Puppeteer, but isolate it.&lt;/strong&gt; &lt;br&gt;
Run it as its own service behind a queue, with a browser pool and a strict concurrency limit. This is the right answer at real volume. It's also a small infrastructure project of its own.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;wkhtmltopdf.&lt;/strong&gt; &lt;br&gt;
One binary, no browser to babysit. The catch is the engine: an old WebKit with no modern CSS. No flexbox you can trust, no grid, no JavaScript. The project was archived in 2023. Fine for plain documents, painful for anything designed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;WeasyPrint.&lt;/strong&gt; &lt;br&gt;
The best pure-library option if you're in Python. Excellent print CSS support: page breaks, running headers, page numbers. It executes no JavaScript at all, so templates must be pure HTML and CSS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Managed Chrome.&lt;/strong&gt; &lt;br&gt;
Services that host headless Chrome for you, so you keep your Puppeteer code and drop the ops work. You still pay for browser time, and your renders still share browser workers with other customers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;HTML to PDF APIs.&lt;/strong&gt; &lt;br&gt;
Send HTML, or a template plus JSON, get a PDF back. The tradeoff is that your documents pass through someone else's infrastructure, which is exactly why the boring questions start to matter: where is it hosted, what do they log, what do they keep.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  What I ended up building
&lt;/h3&gt;

&lt;p&gt;Full disclosure: this is the part where I pitch my own thing, feel free to skip it.&lt;/p&gt;

&lt;p&gt;I hit this wall while adding invoicing to a project, looked at the options, and built PDFGlyph: an HTML to PDF API hosted in the EU. You design a template once, raw HTML and CSS with Handlebars placeholders, then POST your data and get the PDF back:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"https://api.pdfglyph.dev/v1/generate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"POST"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Authorization&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sb"&gt;`Bearer ${process.env.PDFGLYPH_API_KEY}`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;templateId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"tmpl_invoice"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;customer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Northwind Ltd"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"INV-2048"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"€1,240.00"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;pdf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Buffer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;arrayBuffer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// write it, return it, or stream it&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two things I cared about as a user of my own product. The preview in the dashboard renders through the same Chromium path as the production API, so the document you tested is the document your users get. And the accounting is honest: a failed call never consumes your quota, and the log tells you what actually failed (a missing variable, a blocked image, a timeout) instead of leaving you with a blank 500.&lt;/p&gt;

&lt;p&gt;On privacy, because invoices are full of personal data: generated PDFs are never stored, request payloads aren't retained unless you opt a template in, and everything runs on EU infrastructure, which made the GDPR conversation with my own users a short one.&lt;/p&gt;

&lt;p&gt;There's a free tier, 50 documents a month with no card, if you want to see whether your templates survive contact with a real renderer: &lt;a href="https://pdfglyph.dev" rel="noopener noreferrer"&gt;https://pdfglyph.dev&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Whichever route you pick, the one thing I'd push on is getting PDF rendering out of your request path and off your app servers. Your future self, the one not debugging Chrome zombies at 3am, says thanks.&lt;/p&gt;

</description>
      <category>node</category>
      <category>webdev</category>
      <category>pdf</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
