October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
HTML to PDF

HTML to PDF in React JS: Browser Print, Puppeteer, Playwright, and React-PDF

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

For a React page that already renders the content you want, the most direct route to PDF is the browser’s print pipeline: add print CSS, then let the user print or use browser automation to save a PDF. For a separately designed document with tightly controlled structure, use @react-pdf/renderer and its PDF-specific components. The right choice depends on whether you need to reuse existing HTML and CSS, generate a file automatically, or build a distinct document layout.

Choose the right way to make a PDF from React

There is no single conversion method that fits every React app. Start with the output and execution location you need:

Approach Best fit Where it runs Main trade-off
Browser print A user wants a PDF of a page already rendered in the app User’s browser The user must invoke the print interface and choose a PDF destination
Puppeteer or Playwright Automatic downloads, batch generation, or server-created PDFs from a web page Headless browser, commonly on a server Requires a browser runtime and careful handling of page readiness and pagination
@react-pdf/renderer A distinct document whose layout you can author specifically for PDF Browser or server Uses its own React primitives and styling model, not arbitrary browser CSS
react-pdf-html Adapting HTML as a starting point for a react-pdf document React-pdf rendering environment HTML and CSS support is bounded by the properties react-pdf supports

Browser printing and headless browser PDFs use a browser’s HTML/CSS rendering model, which makes them natural when the rendered web page is the source of truth. A dedicated React-PDF document is a better fit when you can author a separate document tree and want to control its structure directly.

Let a user save a React page as PDF

For a user-triggered PDF, prepare a print-friendly route or page and call the browser’s print dialog. The user can select “Save as PDF” in the browser’s print interface; available wording and destinations can vary by browser and operating system. MDN’s guide to printing and print CSS explains the browser print model.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#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

Add print-specific CSS

Use @media print to hide controls that do not belong in the document and adjust the layout for paper. Page dimensions, margins, breaks, and color handling should be deliberate rather than inherited from a screen layout.

@media print {
  .no-print,
  nav,
  button {
    display: none !important;
  }

  body {
    margin: 0;
    color: #111;
    background: #fff;
  }

  .report {
    width: auto;
    max-width: none;
  }

  h1,
  h2 {
    break-after: avoid;
  }

  .keep-together {
    break-inside: avoid;
  }
}

@page {
  size: A4;
  margin: 16mm;
}

The @page rule above is an example, not a universal page-size recommendation. Choose page size and margins for the document and the audience. CSS pagination behavior can differ across browsers, and a rule such as break-inside: avoid cannot guarantee that an oversized element will fit on one page.

Wire up the print action

In a React component, a button can call the browser’s built-in print function. Keep the action outside the printed content or hide it with the print rule.

function PrintButton() {
  return (
    <button className="no-print" onClick={() => window.print()}>
      Print or save as PDF
    </button>
  );
}

Before the user prints, make sure the React view has finished loading the data to be included. For pages with charts, images, or custom fonts, inspect a saved PDF rather than assuming that a completed React render means every asset is ready.

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

Generate a PDF automatically with Puppeteer

Puppeteer’s page.pdf() generates PDF output using print CSS media by default. Its guide shows the browser launch, page navigation, and PDF-save flow; it also documents that PDF generation waits for fonts by default. See the Puppeteer PDF generation guide and the Page.pdf() API.

Install Puppeteer in the server-side project that will generate the PDF:

npm install puppeteer

Example server-side script:

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
try {
  const page = await browser.newPage();

  await page.goto('https://your-app.example/reports/123', {
    waitUntil: 'networkidle0',
  });

  await page.pdf({
    path: 'report.pdf',
    format: 'A4',
    printBackground: true,
    margin: {
      top: '16mm',
      right: '16mm',
      bottom: '16mm',
      left: '16mm',
    },
  });
} finally {
  await browser.close();
}

Replace the example URL with a route accessible to the server-side browser, and ensure it can see the right user or report data. If the route requires authentication, provide that access deliberately; do not expose a user’s private data through an unauthenticated PDF URL. The script writes the PDF to a file. In a web server, adapt the flow to return the generated bytes as a download and handle errors and cleanup in the request lifecycle.

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⁴

Wait for application data and assets

A navigation event alone does not prove that asynchronous React data has appeared or that every image has loaded. For reliable output, make the page expose a clear ready condition, then wait for it before calling page.pdf(). For example, the app can render a marker only after the report is ready:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
// In the React page, render this only when the report data is ready:
<div data-pdf-ready="true">
  {/* report content */}
</div>

// In the Puppeteer script, after navigation:
await page.waitForSelector('[data-pdf-ready="true"]');
await page.pdf({ path: 'report.pdf', format: 'A4', printBackground: true });

Use an application-specific ready marker where possible. Network-idle conditions can be unsuitable for pages that keep connections open or continually fetch data. If images or other assets are important, verify that they have loaded before producing the document.

Generate a PDF with Playwright

Playwright’s page.pdf() also uses print CSS media by default. Its API documents the print-color adjustment behavior and how to emulate a different media type; see the Playwright Page API.

Install Playwright in the server-side project and install the required browser binaries according to its setup for your environment:

npm install playwright
import { chromium } from 'playwright';

const browser = await chromium.launch();
try {
  const page = await browser.newPage();
  await page.goto('https://your-app.example/reports/123', {
    waitUntil: 'networkidle',
  });
  await page.waitForSelector('[data-pdf-ready="true"]');

  await page.pdf({
    path: 'report.pdf',
    format: 'A4',
    printBackground: true,
    margin: { top: '16mm', right: '16mm', bottom: '16mm', left: '16mm' },
  });
} finally {
  await browser.close();
}

For a PDF matching screen media rather than print media, the Puppeteer and Playwright documentation provides media-emulation methods. That is a deliberate choice: a document designed for paper often benefits from print-specific styles rather than a literal screenshot of the screen layout.

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

Build a document with @react-pdf/renderer

If the PDF is its own document rather than a copy of an existing page, @react-pdf/renderer provides React primitives such as Document, Page, View, and Text, with a dedicated StyleSheet API. Its official quick start covers setup and rendering in browser and server contexts.

Install the package:

npm install @react-pdf/renderer

A minimal document component looks like this:

import {
  Document,
  Page,
  StyleSheet,
  Text,
  View,
} from '@react-pdf/renderer';

const styles = StyleSheet.create({
  page: { padding: 36, fontSize: 12 },
  heading: { fontSize: 20, marginBottom: 16 },
  section: { marginBottom: 10 },
});

export function ReportPdf({ title, summary }) {
  return (
    <Document>
      <Page size="A4" style={styles.page}>
        <Text style={styles.heading}>{title}</Text>
        <View style={styles.section}>
          <Text>{summary}</Text>
        </View>
      </Page>
    </Document>
  );
}

This example illustrates the separate document model; it does not turn a normal React DOM component and its CSS into a PDF automatically. Choose this approach when a dedicated PDF layout is acceptable and keep the web page and PDF document aligned through shared data and tests, not by assuming they share layout rules.

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.

Can you convert HTML using react-pdf-html?

react-pdf-html adapts HTML into react-pdf components: its project documentation describes mapping block/container nodes to View, inline text to Text, images to Image, and links to Link. It also describes support for style tags and inline styles only for properties that react-pdf supports, along with basic tables and lists. See the project README.

This can save some rewriting if your starting point is HTML, but it is not a full browser engine for arbitrary web pages or CSS. Before depending on it, create a representative sample containing the selectors, styles, images, links, tables, and page breaks your actual output requires, then inspect the resulting PDF.

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

Make layout, colors, fonts, and page breaks predictable

PDF creation is the end of a rendering pipeline, not a guarantee that a web layout will paginate neatly. Plan for the following issues in whichever approach you choose:

  • Paper geometry: set a page size and margins appropriate to the document; check that content does not become cramped or clipped.
  • Pagination: test long tables, headings near the bottom of a page, and elements that should stay together. Break rules are guidance to the renderer, not a promise for content too large to fit.
  • Fonts: verify that the intended fonts are available and rendered before capture. Puppeteer documents waiting for fonts during PDF generation, but the page still needs to load the intended font resources correctly.
  • Images and charts: wait for important assets and check their size and position in the PDF.
  • Backgrounds and colors: print output can alter colors. Puppeteer and Playwright document print color adjustment using -webkit-print-color-adjust; the browser’s printing preferences can also affect the user-triggered print path.
  • Navigation and controls: hide menus, buttons, and interactive-only content with print CSS when they should not appear on paper.
  • Representative inspection: open generated PDFs from short and long data sets, different image counts, and page-boundary cases. A successful API call only means a file was produced, not that the layout is correct.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting common HTML-to-PDF problems

The PDF is blank or missing React content

The page may have been captured before data fetching or client-side rendering finished. Wait for an application-specific ready marker after navigation, and confirm that the server-side browser can access the route and its data.

Styles or backgrounds do not match the screen

PDF APIs generally use print media by default, so @media print rules may replace screen styling. Add or correct print CSS if paper output is intended. If you need screen styles, use the documented media-emulation method for Puppeteer or Playwright. For colors, check print color adjustment and the chosen print settings.

Fonts or images are missing

Check that the page’s font and image URLs are reachable from the browser runtime, not merely from your development browser. Wait for the app’s readiness condition and inspect browser errors or failed resource requests. Font waiting during PDF generation does not fix a broken font URL.

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.

A table or section splits in an awkward place

Add print-specific break rules to headings, rows, or containers where appropriate, then test with realistic long content. Some content cannot be kept together if it is taller than a page; adjust the document structure or allow the break.

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

The generated PDF fails in deployment

Headless browser generation requires an available browser runtime and compatible deployment setup. Confirm browser installation and launch configuration in the target environment, and ensure the process has enough permissions and resources to start it. If managing a browser runtime is unacceptable, prefer a user-triggered browser print flow or a PDF-specific renderer, depending on your output requirements.

Or skip the browser setup

If you need a screenshot or PDF of a web page rather than a React-native document, ScreenshotNeo offers a website screenshot API and MCP server. It can return a screenshot or PDF from one GET request; cookie banners, popups, and chat widgets are removed before the shot, and bot checks, blank pages, and failed loads are not billed. Its MCP server lets AI agents use screenshot tools, and the free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. The request above captures a web page; it does not convert a React component tree into a designed PDF document. Use it when the page URL is the desired input and a page capture or PDF is the desired output.

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

Sign up free for 1,000 screenshots a month, with no card required.

Cost and reliability trade-offs

Browser printing avoids running a PDF service, but relies on a user’s browser and their print interaction. Puppeteer or Playwright can automate output for downloads and server workflows, but your deployment must support a headless browser and your code must handle page access, readiness, and failures. React-PDF moves layout into a document-specific component tree rather than a browser page. The lowest operational burden depends on where the PDF is needed and whether it must be generated automatically.

For reliability, use a stable source of data, wait for the specific content and assets required, close browser instances in cleanup paths, and inspect output after changes to the page, CSS, fonts, or browser runtime. There is no meaningful universal performance figure here: time and resource use depend on the page, assets, browser environment, and number of documents.

Frequently Asked Questions

Can I download a PDF directly from a React button?

Yes. For user-triggered output, call window.print() and let the user choose a PDF destination in the browser’s print interface.

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

Do Puppeteer and Playwright use print styles when creating PDFs?

Yes. Their page.pdf() methods use print CSS media by default; use their documented media-emulation method if you specifically need screen media.

Is react-pdf-html a full replacement for browser rendering?

No. It adapts HTML to react-pdf components, and its CSS support is limited to properties react-pdf supports.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Read next

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.