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

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Handlebars does not load CSS or create PDFs: it renders a template into HTML. The PDF renderer must then be able to resolve and fetch every linked stylesheet before it prints the page. Give the generated document a usable base URL, make its CSS reachable from the renderer process, wait for resources to load, and account for print-specific styles and PDF options.

How the Handlebars-to-PDF pipeline works

There are two separate jobs in this workflow. First, Handlebars compiles a template and evaluates it with a data context to produce HTML. Second, a renderer such as Puppeteer or WeasyPrint interprets that HTML, resolves its linked resources, applies CSS, and generates a PDF. A stylesheet that appears in a developer’s browser is not necessarily available to a server-side renderer running in a different environment.

  1. Compile and render the Handlebars template with the data for the document.
  2. Include a stylesheet link in the resulting HTML, or add the stylesheet through the renderer’s API.
  3. Ensure the renderer has a valid URL base and can access the stylesheet and any resources it references.
  4. Wait for required stylesheets, fonts, and other assets to load.
  5. Generate the PDF with the intended print styles and background settings.

Make the stylesheet URL resolvable

Prefer an absolute stylesheet URL when the HTML has no stable origin

A link such as <link rel="stylesheet" href="/assets/print.css"> depends on a base URL: the renderer needs to know which host serves /assets/print.css. If the generated HTML is supplied directly rather than loaded from a page with a stable origin, a relative path may have no useful base. In that case, use an absolute URL, for example https://example.test/assets/print.css, or arrange for the document to have a meaningful base.

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

Use a base element when relative URLs are intentional

An HTML <base> element can define how relative URLs in the document are resolved. Put it in the document head and point it at the intended origin or directory. This matters not only for the stylesheet link but also for relative font, image, and other asset URLs referenced by the CSS. A base that fixes the CSS link but leaves the CSS’s own relative asset paths pointing to the wrong place can still produce an incomplete PDF.

#1 Best Overall
Epson EcoTank ET-2800 Wireless Color All-in-One Supertank Printer - Black
  • INNOVATIVE CARTRIDGE-FREE PRINTING — No more dealing with lots of tiny ink cartridges; With this wireless document and photo printer each ink bottle set is equivalent to about 90 individual cartridges²
  • LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; When you choose this combination printer, scanner and copier you can print up to 4,500 pages black/7,500 color³
  • COLOR PRINTING — Up to 2 years of ink in the box4 (and with every replacement ink set) for fewer out-of-ink frustrations
  • ZERO CARTRIDGE WASTE — By using an Epson EcoTank printer you can help reduce the amount of cartridge waste ending up in landfills
  • HOME PRINTER DESIGNED FOR RELIABILITY — The Epson EcoTank ET-2800 All-in-One Supertank Color Printer creates vivid, detailed prints and documents thanks to Micro Piezo Heat-Free Technology; Fire off 10 ISO pages per minute1 to easily finish large jobs
<head>
  <base href="https://example.test/">
  <link rel="stylesheet" href="assets/print.css">
</head>

Use a base only when it reflects where those resources actually live. If the stylesheet and its assets are hosted at different locations, use explicit URLs or configure the renderer’s resource-fetching behavior accordingly.

Puppeteer: load the page, then create the PDF

For a Puppeteer pipeline, load the finished HTML in a page, make sure its linked resources have had an opportunity to load, and then call page.pdf(). Puppeteer’s PDF guide demonstrates navigation with waitUntil: 'networkidle2' before PDF generation. The exact readiness condition should fit the page: an application with ongoing network activity may not become idle, while a page that becomes idle before a late stylesheet or font is ready may still need a more targeted wait.

const html = template(data); // Rendered Handlebars HTML

await page.setContent(html);
await page.addStyleTag({
  url: 'https://example.test/assets/print.css',
});

await page.pdf({
  path: 'output.pdf',
  printBackground: true,
});

This is a pattern, not a complete application: confirm that the browser process can reach the stylesheet URL and that the page has finished loading the resources your document needs. If your setup navigates to a hosted page instead of calling setContent(), use the appropriate page.goto() navigation and readiness option before generating the PDF.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Epson EcoTank Photo ET-8550 Wireless Wide-Format All-in-One Tank Printer
  • CARTRIDGE-FREE PRINTING — Print lab-quality photos, graphics and creative projects; Get vibrant colors and sharp text with Epson's high-accuracy printhead and Claria ET Premium 6-color inks
  • INK BOTTLES — Save on photos1 and creative projects with affordable in-house printing; All-in-one printer allows you to print 4" x 6" photos for about 4 cents each vs. 40 cents with traditional ink cartridges1
  • LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; Printer, scanner and copier lets you print up to 6,200 color pages³
  • PRINT FOR LONGER — Up to 2 years of ink in the box² (and with every replacement ink set) for fewer out-of-ink frustrations with this wireless printer
  • ZERO CARTRIDGE WASTE — Epson EcoTank printer helps reduce the amount of cartridge waste ending up in landfills; Cartridge-free printer uses high-yield ink bottles; Each replacement ink bottle set is equivalent to about 100 individual ink cartridges⁴

Add a stylesheet to an already loaded page

page.addStyleTag() can add a stylesheet link by URL or insert CSS content into the page. Use the URL form when the CSS is hosted and accessible to the browser process; use content when the CSS is already available to your application and you deliberately want to inject it. This avoids relying on a link already being present in the Handlebars output, but it does not remove the need to wait for the stylesheet to be applied before printing.

Check print media and PDF options

Page.pdf() uses the print CSS media type by default. A stylesheet may therefore load successfully while its screen-only rules are not used, or its @media print rules produce a layout different from what you saw in a normal browser tab. Inspect the print rules before treating every visual difference as a loading failure.

Puppeteer’s printBackground option defaults to false. Set it to true if the design depends on CSS background colors or images. Puppeteer also waits for document.fonts.ready by default when creating a PDF; if your application has custom font-loading behavior or uses another renderer, verify font readiness using that renderer’s supported mechanism.

Rank #3
HP Smart Tank 5000 Wireless All-in-One Ink Tank Printer, Scanner, Copier with 2 Years of Ink Included, Best-for-Home, Cartridge-Free, Refillable and AI-Enabled. (5D1B6A)
  • SET IT UP ONCE AND PRINT WITH CONFIDENCE. No complicated maintenance. Just easy, reliable printing you can count on.
  • INK FOR YEARS. NOT MONTHS. Up to 2 years of ink included. Get thousands of pages of cartridge-free printing. More pages, less hassle
  • KEEPS PRINTING WELL AFTER COMPETITORS HAVE QUIT. No complex maintenance. Sharper text, richer colors.[2] Only with HP Smart Tank
  • PREMIUM SUPPORT - Strong technical expertise to solve issues faster
  • THE LAST PRINTER YOU'LL EVER NEED. Enjoy years of refillable, cartridge-free printing.

WeasyPrint: ensure its resource fetcher can reach the CSS

WeasyPrint supports external resources such as stylesheets and documents a URL fetcher for retrieving them. As with a browser-based renderer, the HTML needs a usable base for relative URLs and the renderer process needs access to the requested resources. WeasyPrint accepts file and HTTP URLs, but do not assume that a URL available to your local browser is available to the process that creates the PDF.

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

Check the deployment environment: a local file path must exist and be readable where WeasyPrint runs; an HTTP resource must be reachable from that environment. Authentication and cookies are not supported by default for advanced resource-fetching cases. If a stylesheet requires credentials, investigate whether an appropriate custom URL fetcher is suitable for your application rather than assuming the ordinary request will inherit a browser session.

Diagnose missing or incomplete CSS

  • The stylesheet link is relative and the document has no useful base. Replace it with an absolute URL, serve the generated page from a stable origin, or set a suitable <base> element.
  • The CSS works in your browser but not in production PDF output. Check access from the renderer’s host or container, including network rules, filesystem permissions, authentication, and the renderer’s URL-fetcher configuration.
  • The page looks different only in the PDF. Review @media print rules and remember that Puppeteer PDF generation uses print media by default.
  • Backgrounds disappear. In Puppeteer, enable printBackground: true if backgrounds are part of the intended design.
  • Text uses a fallback font or spacing changes. Confirm that font URLs resolve from the same base as the stylesheet and that the font has loaded before printing. Puppeteer waits for document.fonts.ready by default, but other renderer setups may need explicit readiness checks.
  • A stylesheet works but its images or fonts do not. Inspect URLs inside the CSS as well as the HTML link. Relative URLs in CSS are resolved in relation to the stylesheet location, and each referenced resource must also be available to the renderer.
  • You need to inspect styles from a serialized page. A Chrome Developers example illustrates listening for stylesheet responses and replacing links with captured CSS text before serializing HTML. Treat that as an illustrative technique, not a default production architecture; ensure it handles the page’s complete resource and security requirements.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Keep template-controlled resource URLs safe

Do not treat Handlebars HTML escaping as validation for a dynamic stylesheet URL. Handlebars’ security guidance warns that escaping does not make untrusted data safe in JavaScript, CSS, URLs, or event-handler attributes, and does not prevent a javascript: URL in an href from executing. Validate and restrict resource URLs that template data can control. Prefer an allowlist of expected hosts or known stylesheet paths over accepting arbitrary user-provided URLs.

Rank #4
NDYIN Portable Printers Wireless for Travel, N80 Bluetooth Thermal Printer
  • Wireless Bluetooth Printer: Portable thermal printer compatible with iPhone, Android phones, iPad and tablet computers via Bluetooth. For smartphones, please download the "Nada Print" App. You can also connect to laptops and computers for printing using a USB-C cable. (Note: Laptops and computers can only be connected via USB and require the installation of a driver first. Bluetooth connection is not supported.)
  • No-ink printing: Only supports US Letter and A4 size thermal paper.(Doesn't support regular paper) The no-ink portable thermal printer uses direct thermal technology, requiring no ink, toner or ribbons, making it environmentally friendly, cost-effective and time-saving. The thermal printer package comes with a roll of US Letter thermal printing paper. Note: When installing the paper, remember to switch the paper size switch on APP
  • Clear Print: NDYIN N80 portable thermal printer adopts high-definition printing technology, with a 203DPI resolution to provide you with clear printing results. This mobile printer is compatible with roll paper, folded paper and tattoo transfer paper, supporting printing from your mobile phone PDF, Word, pictures and web pages anytime and anywhere. It is recommended to use our NDYIN thermal paper to achieve good printing quality
  • Portable wireless printer for travel: The thermal printer is equipped with a built-in 1500mAh rechargeable battery, which can print 160 sheets of 8.5" x 11" thermal paper after being fully charged. It weighs only 1.5 pounds and is compact in size. This ink-free portable printer can be easily carried in a backpack or briefcase! It is perfect for business travel, cars, small offices, construction sites, schools and homes. You can print documents, contracts, invoices and boarding passes anytime and anywhere
  • The N80 thermal printer has a wide range of uses. The package includes the N80 printer, a roll of US Letter paper(7m/roll), a user manual, a guide card, a type-C soft cable and a type C adapter. Note: The charging adapter is not included. Special thermal paper is required for use; ordinary paper cannot be used. This ink-free portable thermal printer is suitable for various scenarios such as home, school, travel, office, and outdoor, meeting the printing needs of different groups of people. This tattoo template printer is also compatible with tattoo transfer paper, making it an ideal choice for tattoo art

Or skip the browser setup

If your rendered Handlebars page is published at a URL the service can reach, ScreenshotNeo can capture that page as an image or PDF. It does not replace rendering your Handlebars template or turn raw template data into a PDF: first render and host the page, then capture its URL. For other capture options, see the ScreenshotNeo documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com/invoices/123 -o invoice.pdf

Cookie and consent banners are accepted and removed before capture, along with more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the page verdict and billing status in headers. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients. The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots. Sign up free for 1,000 screenshots a month, with no card required.

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.

Frequently Asked Questions

Does Handlebars need a PDF plugin to include linked CSS?

No. Handlebars renders the HTML; the PDF renderer is responsible for loading the stylesheet and producing the PDF.

Can I use local CSS files instead of hosting a stylesheet?

That depends on the renderer and its resource configuration. The file must be readable from the renderer’s environment, and the document must resolve the path correctly.

Why does the same HTML look different in the browser and PDF?

PDF generation can use print media rules rather than screen rules, and PDF options such as background printing affect the result.

Quick Recap

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.

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