Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteiTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Read the PNG on the Node.js side, convert its bytes to Base64, build a data:image/png;base64,... URI, render that URI through Handlebars, and pass the resulting HTML to Puppeteer. Chromium cannot resolve a server-side filesystem path from page markup, but it can render an image whose bytes are embedded in the HTML. After the page loads, call page.pdf() to create the PDF.
The complete pattern
The safest general flow is:
- Read the local file with Node.js
fs. - Encode the bytes with
buffer.toString('base64'). - Keep the fixed data-URI prefix in the Handlebars template and interpolate the Base64 payload.
- Compile the template and call
page.setContent(). - Wait for the image to complete, then call
page.pdf().
This keeps the image self-contained in the HTML sent to Chromium. Do not put a Node-only path such as /srv/reports/logo.png in an <img> tag and expect the browser page to read it.
Runnable Node.js example
Install the dependencies
npm install handlebars puppeteer
Save this as make-pdf.js. Replace the example path with an absolute path to your PNG.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
const fs = require('node:fs/promises');
const Handlebars = require('handlebars');
const puppeteer = require('puppeteer');
async function makePdf() {
const imageBytes = await fs.readFile('/absolute/path/to/image.png');
const imageBase64 = imageBytes.toString('base64');
const template = Handlebars.compile(`
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style>
@page { size: A4; margin: 18mm; }
body { font-family: Arial, sans-serif; }
img { display: block; max-width: 100%; height: auto; }
h1 { margin: 0 0 12px; }
</style>
</head>
<body>
<h1>Report</h1>
<img src="data:image/png;base64,{{imageBase64}}" alt="Report image">
</body>
</html>
`);
const html = template({ imageBase64 });
const browser = await puppeteer.launch();
try {
const page = await browser.newPage();
await page.setContent(html, { waitUntil: 'load' });
await page.evaluate(async () => {
const images = Array.from(document.images);
await Promise.all(images.map((image) => image.complete
? Promise.resolve()
: new Promise((resolve) => {
image.addEventListener('load', resolve, { once: true });
image.addEventListener('error', resolve, { once: true });
})));
});
const pdf = await page.pdf({
format: 'A4',
printBackground: true,
preferCSSPageSize: true
});
await fs.writeFile('report.pdf', pdf);
} finally {
await browser.close();
}
}
makePdf().catch((error) => {
console.error(error);
process.exitCode = 1;
});
The page.setContent() call assigns the generated markup to the page. page.pdf() then generates a PDF using print CSS by default. The explicit image wait is useful when the document later contains additional asynchronous image processing; for a simple data URI, the image is normally available immediately.
#1 Best Overall
- 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
Use a different image format correctly
The MIME prefix must match the bytes. For a JPEG, use data:image/jpeg;base64,; for WebP, use data:image/webp;base64,. Do not label arbitrary bytes as PNG. If uploads are untrusted, validate the detected file type and impose a size limit on the server rather than trusting the filename or a caller-supplied MIME label.
Handlebars escaping and data-URI construction
Handlebars HTML-escapes ordinary {{expression}} interpolation. A robust template keeps the fixed markup and prefix in the template and inserts only the Base64 payload:
<img src="data:image/png;base64,{{imageBase64}}" alt="Report image">
After rendering, inspect the HTML during debugging and confirm that the value starts with data:image/png;base64, and contains the expected payload. Base64 normally contains letters, digits, +, /, and =; ordinary interpolation remains the safer default.
You can instead construct a complete URI and use triple-stash syntax, for example <img src="{{{imageDataUri}}}">. Triple-stash emits raw output and disables normal escaping. Use it only when the value has been generated and validated for this exact attribute context. Never pass untrusted text through triple-stash or mark arbitrary input as a Handlebars SafeString.
Validate before rendering
For a production upload pipeline, check the first bytes (the PNG signature is part of the file format), reject unexpectedly large files, and decode or inspect the image with a trusted image library when your threat model requires it. A filename ending in .png is not proof that the content is a PNG.
Control print layout and colors
Puppeteer uses print CSS media for page.pdf(). If your report is designed with screen styles, select screen media before creating the PDF:
Rank #2
- 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⁴
await page.emulateMediaType('screen');
const pdf = await page.pdf({ printBackground: true, format: 'A4' });
When you need print styles, omit emulateMediaType('screen'). Background colors and images are not printed unless you request them with printBackground: true. Chromium may adjust printed colors; CSS using -webkit-print-color-adjust can request more exact color rendering, but the final result still depends on the installed Chromium build.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Use PDF options such as format, margin, landscape orientation, header and footer templates, and page ranges according to the Puppeteer version installed in your project. The API surface and defaults can change, so keep the Puppeteer package version controlled and check its matching API documentation when upgrading.
Size the image deliberately
max-width: 100%; height: auto; preserves the PNG’s aspect ratio while preventing it from overflowing the printable area. If the source is very large, resize it before embedding or constrain its CSS dimensions. Base64 adds approximately one third to the encoded byte representation, and the complete HTML must remain in memory while Handlebars and Chromium process it.
Images in headers and footers
A data URI is a reasonable approach to try in a PDF header or footer. A Puppeteer maintainer wrote in a 2018 issue that “the base64-encoded image should work just fine,” but that statement is historical rather than a guarantee for every current release.
A separate issue opened on April 3, 2025 reports a Base64 header-image failure beginning with Puppeteer 24.4.0. Treat that as a version-specific user report, not proof that all later versions fail. If a logo appears in ordinary page content but disappears from a header or footer, check the exact Puppeteer and Chromium versions and inspect the final header-template HTML in that environment. When the layout allows it, put the logo in the main document body; that avoids special header/footer rendering behavior.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsExample header template
const headerTemplate = `
<div style="font-size:9px;width:100%;text-align:center;">
<img src="data:image/png;base64,${imageBase64}" style="height:18px">
</div>`;
const pdf = await page.pdf({
format: 'A4',
displayHeaderFooter: true,
headerTemplate,
footerTemplate: '<div></div>',
margin: { top: '25mm', bottom: '20mm' }
});
Give the header enough top margin or it may overlap the body. Test this path against the version you deploy rather than assuming behavior from an older issue or a different Chromium binary.
Rank #3
- 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.
Choosing the image source strategy
| Strategy | Where bytes are read | Strength | Important caveat |
|---|---|---|---|
| Base64 data URI in main HTML | Node.js before rendering | Self-contained markup; no browser filesystem access is required | Base64 increases in-memory HTML size |
| Browser-readable local or remote URL | Chromium during page rendering | Smaller HTML when the resource is reliably reachable | Requires correct browser access, URL permissions, and successful loading |
| Base64 in header/footer template | Node.js before PDF generation | Keeps a logo in repeating PDF chrome | Header/footer behavior varies by Puppeteer/Chromium version |
For a local PNG and a deterministic report, the main-body data URI is usually the least surprising option. Use a browser-readable URL only when you intentionally want Chromium to fetch the resource and can control that dependency.
Troubleshooting missing or broken images
The PDF shows a broken image icon or nothing at all
- Verify that
fs.readFile()read the intended file and that the process has permission to read it. - Log the rendered HTML and check the exact
data:image/png;base64,prefix. - Confirm that the bytes are really PNG data and that the Base64 string was not truncated.
- Render the image in ordinary page content before testing a header or footer. This separates data and input problems from special template rendering behavior.
The image is clipped or pushes content onto unexpected pages
- Keep
max-width: 100%andheight: autoon the image. - Check the printable width after margins and the selected paper format.
- Set explicit dimensions when a report must have stable pagination.
Colors or backgrounds differ from the browser preview
- Remember that
page.pdf()uses print media unless you callpage.emulateMediaType('screen'). - Set
printBackground: truewhen backgrounds are part of the design. - Review print-specific CSS and, where needed,
-webkit-print-color-adjust.
The page is captured before a processed image is ready
page.setContent(html, { waitUntil: 'load' }) waits for the document load event, but application code may continue processing afterward. Wait for document.images to complete, a known selector, or an application-specific readiness signal before calling page.pdf(). The example above resolves image load and error events explicitly.
A header logo fails after a Puppeteer upgrade
Check the installed Puppeteer and Chromium versions first. The historical 2018 maintainer comment and the 2025 issue report describe different environments; neither is a universal compatibility guarantee. Move the image into the main page body when a repeating header is not essential.
Free tools Windows power users keep installed
One-click scans. No signup required.
The process runs out of memory
Large PNGs become larger strings and are represented in several places: the original Buffer, the Base64 string, the Handlebars output, and Chromium’s page data. Resize or compress source images, avoid embedding the same huge image repeatedly, process jobs with bounded concurrency, and close every browser in a finally block.
Security and deployment checklist
- Resolve and validate server-side paths; do not let an untrusted caller select arbitrary filesystem files.
- Validate file signatures and enforce upload-size and pixel-count limits appropriate to your service.
- Keep ordinary Handlebars escaping enabled. Use triple-stash only for a value validated for the exact HTML attribute context.
- Pin Puppeteer and its Chromium revision in deployment so PDF output changes are deliberate.
- Always close pages and browsers, including on exceptions.
- Log the input path, detected type, byte length, Puppeteer version, and PDF options needed to reproduce a rendering failure, without logging sensitive image contents.
Or skip the browser setup
If what you actually need is a screenshot of a public webpage rather than a PDF containing your own local PNG, ScreenshotNeo provides a single HTTP request instead of a Puppeteer installation. Its API accepts cleanup options that remove cookie-consent banners, newsletter popups, and chat widgets before capture; each step can be turned off. Only clean shots are billed: bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the result with X-Page-Verdict and X-Billed headers.
For the API parameters and all capture options, see the ScreenshotNeo documentation. A one-call example is:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo also offers an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. Every plan includes the full feature set, including full-page capture with lazy images loaded, CSS-selector element capture, dark mode, device presets and custom viewports, retina scale, PDF controls, custom CSS and JavaScript, clicks, waits, request blocking, headers, cookies, user agents, authorization, timezone and geolocation, transparent backgrounds, resizing, chosen-TTL caching, signed links, asynchronous webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification.
Rank #4
- 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
The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; Growth is $15 for 15,000, Pro is $39 for 60,000, Scale is $99 for 250,000, and Business is $249 for 1,000,000. Yearly billing gives two months free. If that fits your workflow, sign up for the free plan.
FAQ
Does converting the PNG to Base64 modify the original file?
No. The example reads the file into memory and encodes those bytes for transport inside HTML. The source file remains unchanged.
Can the same generated HTML be used for a browser preview and a PDF?
Yes. Handlebars produces ordinary HTML; you can send that string to a browser preview or to Puppeteer. The PDF-specific differences come from print media, page size, margins, and PDF options.
Is a data URI required for every image in a report?
No. It is the most direct way to carry a server-local file into browser-rendered markup. A browser-readable URL is another option when you deliberately provide a reachable resource and accept its loading dependencies.
Recommended Free Tools
Frequently Asked Questions
Does converting the PNG to Base64 modify the original file?
No. The file is read and encoded in memory; its contents on disk are unchanged.
Can the same Handlebars output be used for a browser preview and a PDF?
Yes. It is ordinary HTML. PDF-specific differences come from print media, page dimensions, margins, and PDF options.
Is a data URI required for every image in a report?
No. It is the simplest way to carry a server-local file into Chromium; a reliably reachable browser URL is another valid strategy.
The Bottom Line
Read the PNG in Node.js, embed its Base64 bytes in a correctly typed data URI, render that URI with Handlebars, wait for the image, and then call Puppeteer’s page.pdf(). Keep the image in main page content for the most predictable result, and verify the installed version before relying on data-URI images in PDF headers or footers.
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.

