Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To make a PDF from an HTML email template, render the completed HTML in a browser engine and use its PDF-printing API. Puppeteer and Playwright both support this workflow. Load the template with its data and styles, choose print or screen media, set the paper and page-break rules, wait for needed assets, and inspect the resulting PDF. This creates a document from the markup; it does not attach or convert a sent email.

Prepare the email template for browser rendering

First produce a complete HTML document with the template data filled in. Include the styles and assets the browser needs to render it. The cited browser APIs explain how to print a page to PDF, but they do not establish email-client compatibility rules or guarantee that remote images will load in every deployment.

For predictable output, use a route in your application that returns the rendered template, or load the complete HTML into the browser page. The example below assumes a route already renders the email with its data and assets. Replace the example URL with that route.

Generate the PDF with Puppeteer

Puppeteer’s page.pdf() generates a PDF using print CSS media. This example waits for the page’s network activity to settle, writes an A4 PDF to disk, includes backgrounds, and prefers any CSS @page size defined by the template. A4 and these options are illustrative; choose settings that fit your intended output.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  try {
    const page = await browser.newPage();
    await page.goto('https://your-rendered-template.example', {
      waitUntil: 'networkidle2',
    });
    await page.pdf({
      path: 'email-template.pdf',
      format: 'A4',
      printBackground: true,
      preferCSSPageSize: true,
    });
  } finally {
    await browser.close();
  }
})();

The documented lifecycle is to navigate to a page, call page.pdf(), and close the browser. Puppeteer’s guide uses networkidle2 in its sample. For its API options and defaults, see the Puppeteer Page.pdf() reference and PDF generation guide.

Use Playwright when it fits your project

Playwright also creates PDFs from a browser page. Its page.pdf() returns a buffer, which you can write to a file or pass to the rest of your application. This example assumes the route renders the completed template.

const { chromium } = require('playwright');
const fs = require('node:fs/promises');

(async () => {
  const browser = await chromium.launch();
  try {
    const page = await browser.newPage();
    await page.goto('https://your-rendered-template.example', {
      waitUntil: 'networkidle',
    });
    const pdf = await page.pdf({
      format: 'A4',
      printBackground: true,
      preferCSSPageSize: true,
    });
    await fs.writeFile('email-template.pdf', pdf);
  } finally {
    await browser.close();
  }
})();

Check your installed Playwright version and browser setup when adapting this example. The Playwright Page.pdf() API reference documents the PDF settings and the returned buffer.

Choose print styling, page size, and layout

Print media or screen media

Both documented APIs use print media for PDF generation by default. If the PDF should match the screen stylesheet instead, explicitly emulate screen media before calling the PDF method. In Playwright, use await page.emulateMedia({ media: 'screen' }); Puppeteer also provides media emulation. Print and screen styles can produce different layouts, so select intentionally rather than assuming the PDF will use the browser’s ordinary screen view.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Paper dimensions, margins, and page breaks

Set the paper standard and geometry for the intended reader or region. Playwright documents Letter as 8.5 × 11 inches and A4 as 8.27 × 11.7 inches. Puppeteer accepts a paper format or explicit dimensions, plus margins and orientation. You can also define print rules in the template with @media print and @page.

When using Puppeteer, preferCSSPageSize: true gives CSS @page sizing priority. Its default is false; without that preference, content is scaled to fit the API-selected paper dimensions. Align CSS page rules and API options to avoid unexpected scaling or page breaks.

Backgrounds and color

Puppeteer’s printBackground defaults to false, so set it to true if the design depends on background colors or images. PDF print rendering may modify colors; the API documentation points to -webkit-print-color-adjust to request exact color rendering. Verify the actual PDF because the output can still depend on the browser and rendering environment.

Fonts, headers, footers, and output control

  • Fonts: Puppeteer’s PDF method waits for fonts by default; its options reference documents waitForFonts: true as the default. Remote fonts or pending assets can still affect timing, so allow for an appropriate timeout in your application.
  • Headers and footers: Both APIs provide header/footer templates. Playwright notes that scripts in those templates are not evaluated and page styles are not visible inside them. Puppeteer documents placeholders including date, title, URL, page number, and total pages.
  • Scale and ranges: The APIs expose scaling and page-range controls. Use them to adjust output deliberately rather than shrinking content until small text becomes hard to read.
  • Result handling: Puppeteer can write the PDF to a path via the path option. Playwright returns a PDF buffer that you can store, stream, or pass to another part of your application.

Inspect the PDF before using it

Generate PDFs using representative short and long template content, then inspect the files rather than assuming a successful API call means a correct document. Check for:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Text wrapping and unexpected page breaks.
  • Missing images or substituted fonts.
  • Content clipped at the page edge or by fixed-height sections.
  • Backgrounds and colors that differ from the intended design.
  • Headers or footers that overlap the template.

A browser-generated PDF confirms how that browser rendered the page; it does not establish that the same markup will look identical in an email client such as Gmail or Outlook. The cited APIs do not promise email-client equivalence.

Puppeteer or Playwright?

Choose based on the browser automation library already used by your application, how you want to handle the output, and which browser version you can operate reproducibly. The documented APIs share the print-media default and let you choose screen media. Puppeteer’s reference demonstrates writing to a file; Playwright’s returns a buffer. The available API documentation does not establish a universal speed or visual-fidelity winner.

Troubleshooting common PDF problems

The PDF uses the wrong layout

Check whether the page is being printed with print media, as it is by default, or whether you explicitly emulated screen media. Review the template’s @media print rules and select the intended media before generating the PDF.

Background colors or images are missing

Enable Puppeteer’s printBackground option if the PDF needs backgrounds. For color differences, review print color adjustment rules, including -webkit-print-color-adjust, and inspect output in the browser version used in production.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Content is scaled or paginated unexpectedly

Compare the API’s paper format, dimensions, margins, and orientation with the template’s @page rules. In Puppeteer, enable preferCSSPageSize if CSS page sizing should take precedence. Review the template’s print-specific page breaks and test with longer content.

Fonts or images are absent

Make sure the rendered page includes the assets and styles needed for a standalone browser rendering, and that required resources are ready before PDF creation. Puppeteer waits for fonts by default, but remote resources can still have environment-specific loading behavior. The cited documentation does not guarantee remote-image availability.

PDF generation hangs or times out

Check whether the page is still waiting on network activity, a remote font, or another asset. The Puppeteer sample uses networkidle2, but an application with ongoing requests may need a different readiness condition. Set and handle timeouts appropriate to your service, and test the route in its deployed environment.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

ScreenshotNeo can capture a URL as a PDF with one GET request; see the ScreenshotNeo API documentation. For example, capture a published template route with cURL:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://your-rendered-template.example -o email-template.pdf

ScreenshotNeo accepts cookie and consent banners like a visitor and removes 60+ known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits cost nothing, and response headers indicate the page verdict and billing status. Its MCP server gives AI agents tools for screenshots, page information, and PDF capture. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free 1,000 screenshots a month with no card.

Frequently Asked Questions

Does making a PDF from an HTML email template send the email?

No. It renders the template markup as a document; sending an email is a separate step.

Can a browser-generated PDF prove how the email will look in an inbox?

No. Browser PDF rendering does not establish identical rendering in email clients.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.