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.

Use a headless browser to render the HTML string, wait for its JavaScript-generated content to be ready, then print the page to PDF. With Puppeteer, the core sequence is page.setContent(html), an application-specific readiness check, and page.pdf(). Playwright offers the same basic approach. The important detail is that setting the markup does not guarantee that asynchronous scripts, data requests, or charts have finished rendering.

Convert an HTML string to PDF with Puppeteer

Puppeteer accepts HTML markup as a string through Page.setContent(html). Once the page contains the markup, wait for the condition that tells your application its output is ready, then call page.pdf(). The following Node.js example writes a PDF to disk:

const puppeteer = require('puppeteer');

const html = `
<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Report</title>
  </head>
  <body>
    <h1>Monthly report</h1>
    <div id="report-ready"></div>
    <script>
      // Replace this with your real rendering or data-loading logic.
      document.querySelector('#report-ready').textContent = 'Report is ready';
    </script>
  </body>
</html>`;

(async () => {
  const browser = await puppeteer.launch();
  try {
    const page = await browser.newPage();
    await page.setContent(html, { waitUntil: 'load' });
    await page.waitForSelector('#report-ready');
    await page.pdf({ path: 'output.pdf', printBackground: true });
  } finally {
    await browser.close();
  }
})();

The sample selector is illustrative: it works here because the markup contains that element, but your readiness signal should reflect your own application. Puppeteer’s setContent API takes markup and returns a promise. Its PDF guide demonstrates generating a PDF and closing the browser afterward.

When the JavaScript is a separate string

If you have markup and JavaScript in separate variables, put the script into the page before generating the PDF. One straightforward option is to assemble the markup with a script element before calling setContent:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Tengchi RCA to HDMI Converter, AV to HDMI Adapter
  • RCA Female to HDMI Video Converters Adapter : The cable is used to convert analog composite input to HDMI 1080p output, displayed on a 1080p HD TV/TV/monitor.
  • Input ports: 1xRCA Female (Yellow, White, Red), Output ports: 1xHDMI 1.3 1080p. NOT support 3D and 4K, NOT support HDMI Converts to AV
  • AV to HDMI Converter: Plug and Play, Easy to Install and Operate, Powered by External USB Cable. Note: Please hook up the USB power cable (included) to 5V 1Apower source during use (not included power supply ).
  • Support PAL, NTSC3.58, NTSC4.43, SECAM, PAL/M, PAL/N standard TV formats input. For PS2,PS3,Xbox,N64,STB, VHS, VCR, DVD Players and other devices with standard composite AV input.
  • You Will Get : 1x RCA Female TO HDMI Converter, 1xHDMI cable, 1xUSB cable, 1xUser Manual. ONE YEAR WARRANTY - if you are not satisfied for any reason whatsoever, do not hesitate to contact us .
const html = `<!doctype html><html><body><div id="report-ready"></div></body></html>`;
const script = `document.querySelector('#report-ready').textContent = 'Ready';`;
const htmlWithScript = html.replace('</body>', `<script>${script}</script></body>`);

await page.setContent(htmlWithScript, { waitUntil: 'load' });
await page.waitForSelector('#report-ready');
await page.pdf({ path: 'output.pdf' });

This simple concatenation is suitable only when you control the script content. If JavaScript text may contain a closing </script> sequence, or comes from untrusted input, do not insert it into HTML this way: use a browser API intended to add script content and verify the supported overload for the Puppeteer version you use. Puppeteer’s API index includes addScriptTag; the exact API details should be checked against the installed version.

Wait for the rendered result, not just the initial page load

setContent loads the supplied document, but a document’s initial load event is not a universal signal that application work has completed. A script may fetch data, render a chart, or update the DOM after that event. If the PDF is created too early, it can contain an empty chart, placeholder text, or an incomplete report.

Use a condition tied to your application

Prefer a selector, state flag, or other condition your own code sets only after the content needed in the PDF is present. For example, your rendering logic might add a data-ready="true" attribute to a report container after drawing its final content; then wait for that exact condition before printing. This is a pattern, not a built-in guarantee: choose a signal that corresponds to the actual work your page performs.

Rank #2
ABLEWE RCA to HDMI,AV to HDMI Converter, 1080P Mini RCA Composite CVBS Video Audio Converter Adapter Supporting PAL/NTSC for TV/PC/ PS3/ STB/Xbox VHS/VCR/Blue-Ray DVD Players
  • RCA to HDMI Converter: Converts analog RCA composite (Yellow, White, Red) input to HDMI 720P/1080P (60HZ) output,displayed on HDTV/Monitor,which can bring back your childhood memories.
  • Plug to Play: ABLEWE Mini RCA to HDMI converter no extra drivers need, just plug and play,easy to use.Please hook up the USB power cable (included) to 5V power source during use.
  • Wide Compatibility: Support source formats of PAL, NTSC3.58, NTSC4.43, SECAM, PAL/M, PAL/N standard TV. Provide advanced signal processing with great precision, colors, resolutions, and details.
  • Widely Used:Widely applied to PS2,PS3,Xbox,N64, WII, STB, VHS, VCR, DVD Players and other devices with standard composite AV input.
  • Attention & Package:Please ensure to connect this rca to hdmi converter to power source to make it work.Package include:1*RCA to HDMI Converter,1*usb power cable(adapter not included),1*User Manual.

Do not treat network idle as proof of readiness

A quiet network does not necessarily mean a chart or application update has finished, and a page with ongoing connections may never become network-idle. Playwright’s documentation explicitly discourages using networkidle as a general readiness test and recommends assertions to assess readiness instead. Apply the same practical caution when deciding when to print with Puppeteer: wait for the output your application needs.

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

Control PDF appearance with print CSS

Puppeteer and Playwright generate PDFs using print CSS media by default. That means print-specific rules such as @media print can change layout relative to what you see in a normal browser window. Check page breaks, margins, background colors, and hidden elements using the same media mode that will be used for the PDF.

Use screen styles when that is the intended output

If the PDF should reflect screen media rather than print media, Puppeteer lets you emulate screen media before calling page.pdf():

Rank #3
GINGIN AV to HDMI Converter, AV to HDMI Adapter Support 720p/1080p for PS1/PS2/PS3/Xbox 360/WII/N64/SNES/STB/VHS/VCR/Blue-Ray DVD Players
  • Composite to HDMI Converter: Converts analog AV composite (Yellow, White, Red) input to HDMI 720P/1080P (60HZ) output, displayed on smart TV, Projector or HD Display, which bring back your old and cherish memories.
  • Plug to Play: This HDMI Converter no extra drivers need, just plug and play,easy to use. Please hook up the USB Power Cable (included) to 5V power source during use. Note: The Video Converters only support converts AV to HDMI, can't converts HDMI to AV.
  • Widely Used: This composite to hdmi adapter is widely applied to PS1, PS2, PS3, Xbox, N64, Wii, STB, VHS, VCR, DVD Players and other devices with standard composite AV input. Note: It can only be used when PS2 is set to RGB output.
  • Wide Compatibility: This Video Audio Converter Adapter supports source formats of PAL, NTSC3.58, NTSC4.43, SECAM, PAL/M, PAL/N standard TV. Provide advanced signal processing with great precision, colors, resolutions, and details. Important Note: This converter can't improve video quality!
  • Attention & Package: Please ensure to connect this av hdmi converter to power source to make it work. Package include: 1*AV to HDMI Adaptor, 1*USB Power Cable(adapter not included), 1*User Manual.
await page.emulateMediaType('screen');
await page.pdf({ path: 'output.pdf', printBackground: true });

For exact print colors in Puppeteer, its PDF API documentation notes the CSS property -webkit-print-color-adjust. For example, a stylesheet can use * { -webkit-print-color-adjust: exact; } when preserving specified colors is important. Confirm the result in your actual PDF: print rendering can differ from an ordinary screen preview.

Fonts and external assets

Puppeteer’s PDF guide says PDF generation waits for fonts by default. That helps with font readiness, but it does not replace application-specific checks for other asynchronous work. If your HTML references external stylesheets, images, or scripts, make sure they are reachable in the browser context and that the content they affect has finished rendering before printing.

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

Use Playwright if it is already your browser automation library

The corresponding Playwright flow is also page.setContent(html), an explicit readiness check, and page.pdf(). The API documentation states that setContent internally calls document.write(), inheriting that method’s characteristics and behaviors. As with Puppeteer, load the HTML first and do not assume its initial load state means your application has completed later asynchronous rendering.

Rank #4
BD&M RCA to HDMI Converter, AV to HDMI Adapter Supports PAL/NTSC for PS2, PS3, Xbox, VHS, VCR, DVD Players
  • Convert RCA to HDMI Instantly – BD&M RCA to HDMI Converter easily converts analog RCA/composite AV signals to HDMI output, allowing you to connect older devices to modern HDTVs, monitors, and projectors with clear video and audio quality.
  • Wide Device Compatibility – Supports VHS players, VCRs, DVD players, camcorders, retro gaming consoles, and more including PS1, PS2, PS3, Xbox, N64, Wii, and older AV devices with standard RCA output.
  • 1080P HDMI Output – Advanced signal processing delivers stable and sharp video output with support for 720P/1080P HDMI resolution, improving compatibility with modern TVs and displays.
  • Plug & Play Setup – No drivers or software required. Simply connect the RCA cables, HDMI cable, and included USB power cable for quick and easy installation in minutes.
  • Compact & Reliable Design – Lightweight mini converter design makes it perfect for home entertainment setups, retro gaming, travel, or converting old media collections while maintaining stable performance.
const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  try {
    const page = await browser.newPage();
    await page.setContent(html, { waitUntil: 'load' });
    await page.waitForSelector('#report-ready');
    const pdf = await page.pdf();
    // pdf is a buffer; save it or pass it to your application.
  } finally {
    await browser.close();
  }
})();

Playwright’s page.pdf() returns PDF bytes, while Puppeteer’s documented guide shows saving to a path with { path: 'output.pdf' }. Both default to print CSS media. Choose based on the browser automation library and output handling that fit your existing application; the cited documentation does not establish a performance or reliability winner between them. See the Playwright Page API.

Common failures and fixes

Symptom Likely cause What to check
The PDF is blank or shows placeholder content Printing began before JavaScript finished the work that populates the page. Wait for an application-specific selector or readiness signal, then verify that it represents the final content.
A chart or fetched data is missing Initial document loading completed before later rendering or data retrieval. Make the page expose a ready condition after the chart or data is rendered; do not rely only on a generic load or network-idle event.
Colors or layout differ from the browser preview PDF generation uses print CSS media by default. Review print styles and page-break rules, or emulate screen media in Puppeteer before printing if screen styling is intended.
Script content does not run The code may not have been inserted into the document, or it may have been added after the capture step. Ensure the script is present before the readiness check and PDF call. For a separate script string, use a browser script-insertion API and confirm the API overload for your installed version.
External content is absent A linked resource may not be accessible or may not have loaded before printing. Check resource URLs and browser access, then include an app-specific condition for any resource-dependent rendering.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your content is available at a URL, ScreenshotNeo can capture a website as an image or PDF without your application launching and managing a browser. It is URL-based, so it is not a direct replacement for passing an arbitrary, unhosted HTML string to setContent; make the page reachable at a URL if that fits your workflow. Its API supports HTML/CSS to image as well, but the one-call example below captures a URL.

For API setup and options, see the ScreenshotNeo documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Convert to PDF
  • Export or Convert Text, HTML, PNG, JPG, or Camera Pictures to PDFs
  • Unlimited use
  • No ads
  • No personal data taken
  • GDPR compliant
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie or consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and billing status. 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 per month with no card; paid plans start at $5 for 3,000 shots. Sign up for ScreenshotNeo and get 1,000 screenshots a month free, with no card.

Cost and operational considerations

For a self-managed Puppeteer or Playwright workflow, you run the browser and handle its lifecycle; the examples close it in a finally block so it is also closed if page setup or PDF generation throws an error. Your output can be written to a file or, with Playwright’s documented API, retained as returned bytes. The official sources cited here do not provide a benchmark comparing the libraries, nor do they establish a general cost or reliability comparison. Base a choice on your current stack, how you need to handle PDF bytes, and which readiness conditions your application can reliably expose.

Which approach should you use?

  • Use setContent with Puppeteer or Playwright when the input is an in-memory HTML string that your code needs to render directly.
  • Wait for an application-specific signal before printing whenever scripts create or update content asynchronously.
  • Choose print or screen media deliberately, because PDF generation defaults to print styles.
  • Use ScreenshotNeo when the page can be reached by URL and a managed screenshot or PDF capture fits better than running browser automation yourself.

Frequently Asked Questions

Does Playwright’s setContent navigate to a remote URL?

No. It sets page content from the supplied HTML string; use a navigation method when the page you want to capture is hosted at a URL.

Can I use this method when my HTML has no JavaScript?

Yes. The browser can print static markup too; the readiness wait is most useful when scripts or linked resources affect the final output.

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.