Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk5 min

How to Export a React Page to PDF After Data Loads

Wait for the request and React render to finish before exporting. Learn how to coordinate react-to-print, style the printed component, and choose a direct PDF or server-rendered workflow.

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.

Wait until the data request has finished and React has rendered the data-backed page, then start the PDF flow. For a user-controlled Save as PDF workflow, print the React component with react-to-print. If you need an automatic PDF download with no print dialog, use a separate PDF-generation workflow instead: react-to-print does not directly download a PDF from its print preview.

Choose how the PDF should be created

Route What happens Use it when
Browser print The browser opens its print interface; the user can choose Save as PDF. The print dialog and its settings are acceptable.
Client-side PDF generation Your application passes prepared content to a separate PDF-generation library. You need an application-controlled file-generation flow rather than the browser print preview.
Server-rendered document A server builds the document from React-rendered content and a PDF pipeline. The document should be produced on the server, or its content is better prepared there.

The appropriate route depends on the required user experience and layout. The cited documentation does not establish a general performance or fidelity winner among these approaches.

Wait for the data and the React render

A completed network request and a committed React update are related but distinct. A state setter schedules an update; it does not mean the corresponding DOM is already present. The simplest safe approach is to keep export disabled until loading finishes and the data is available. If you must change state immediately before printing, coordinate that update with the Promise returned by onBeforePrint.

Example: fetch data, then print the rendered report

This component keeps the print button unavailable while the request is pending. Its onBeforePrint returns a Promise that resolves from an effect after React commits a final print-preparation update. Replace the example endpoint and response shape with your application’s API.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
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
import { useEffect, useRef, useState } from "react";
import { useReactToPrint } from "react-to-print";

export function ReportPage() {
  const contentRef = useRef(null);
  const [report, setReport] = useState(null);
  const [status, setStatus] = useState("loading");
  const [error, setError] = useState("");
  const [printReady, setPrintReady] = useState(false);
  const [resolveBeforePrint, setResolveBeforePrint] = useState(null);

  useEffect(() => {
    const controller = new AbortController();

    async function loadReport() {
      try {
        const response = await fetch("/api/report", {
          signal: controller.signal,
        });
        if (!response.ok) {
          throw new Error(`Report request failed: ${response.status}`);
        }
        const data = await response.json();
        setReport(data);
        setStatus("ready");
      } catch (err) {
        if (err.name !== "AbortError") {
          setError(err.message || "Could not load the report.");
          setStatus("error");
        }
      }
    }

    loadReport();
    return () => controller.abort();
  }, []);

  useEffect(() => {
    if (printReady && resolveBeforePrint) {
      resolveBeforePrint();
      setResolveBeforePrint(null);
      setPrintReady(false);
    }
  }, [printReady, resolveBeforePrint]);

  const print = useReactToPrint({
    contentRef,
    onBeforePrint: () =>
      new Promise((resolve) => {
        setResolveBeforePrint(() => resolve);
        setPrintReady(true);
      }),
  });

  if (status === "loading") return <p>Loading report…</p>;
  if (status === "error") return <p role="alert">{error}</p>;

  return (
    <main>
      <button type="button" onClick={print} disabled={!report}>
        Print or save as PDF
      </button>
      <article ref={contentRef} className="report-print-area">
        <h1>{report.title}</h1>
        <p>{report.summary}</p>
        {/* Render the rest of the data-backed report here. */}
      </article>
    </main>
  );
}

The example uses the contentRef API shape shown by the project documentation; check the README for the installed react-to-print version if its API differs. If no last-minute React state change is needed, the Promise-based preparation can be omitted: wait for status to become ready, then invoke printing.

Print the intended component, not the surrounding application

Attach the ref to the exact report or page region to export. Keep print-specific styles on elements inside that region: styles inherited only from an unprinted ancestor may not be present in the print DOM. Use print media CSS to remove controls and adjust the layout.

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⁴
@media print {
  .report-print-area {
    color: #000;
    background: #fff;
  }

  button,
  .screen-only {
    display: none !important;
  }

  h1,
  h2 {
    break-after: avoid;
  }

  .report-section {
    break-inside: avoid;
  }
}

Test the actual report in the target browser. Long tables, page breaks, fonts, images, orientation, browser print settings, and print-CSS support can affect the result; identical layout across browsers is not guaranteed by the project documentation.

When the PDF must download without print preview

The react-to-print README says the library does not directly download a PDF without the Print Preview window. Its documented alternative is to use a custom print handler and pass the gathered content to a separate PDF-generation library. Treat that as a distinct implementation: verify that the library you choose supports your content, fonts, images, pagination, and required output, because the cited sources do not compare PDF libraries or establish one best choice.

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.
Rank #3
HP Smart Tank 5000 Ink Tank Printer | 2 Years of Ink Included | All-in-One
  • 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.

Server-rendered React output and suspended data

If you generate the document on a server, choose the rendering API based on how the data and Suspense boundaries behave. React’s prerender API waits for suspended data before resolving and is intended for static server-side generation. By contrast, renderToStaticMarkup produces non-interactive HTML and has limited Suspense support: if a component suspends, it emits the fallback immediately. They are not interchangeable when the document requires pending Suspense content.

Troubleshooting export timing and layout

  • The PDF or preview is missing data: Start export only after the request is complete and the data-backed UI is rendered. If you set print-only state in the pre-print callback, return a Promise and resolve it after the update commits.
  • The print button remains unavailable: Check the request’s loading and error paths, and verify that successful responses populate the state used by the readiness condition.
  • Styles disappear in print: Put relevant styles on the printed component or its descendants rather than relying on an ancestor outside the print DOM. Check print media rules and browser print settings.
  • Pages split awkwardly or images are absent: Inspect the actual content in the target browser, including long tables, page-break rules, image loading, fonts, and orientation. Adjust the print layout and retest; the cited documentation does not promise uniform output across browsers.
  • A server render shows a Suspense fallback: Check whether the chosen API waits for suspended data. renderToStaticMarkup emits a fallback when a component suspends; React documents prerender for waiting on suspended data.
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 the page is publicly reachable and its data is available when captured, ScreenshotNeo can return a page screenshot or PDF from one GET request. Its wait-for-selector, delay, and network-idle options can help with a page that loads asynchronously; use an appropriate ready selector when possible. This captures a URL, rather than rendering a private in-memory React component, so ensure the target page is accessible and contains the intended data.

Rank #4
Sale
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

cURL example, using a URL that you control and can capture:

Quick Recap

Bestseller No. 3
HP Smart Tank 5000 Ink Tank Printer | 2 Years of Ink Included | All-in-One
HP Smart Tank 5000 Ink Tank Printer | 2 Years of Ink Included | All-in-One
PREMIUM SUPPORT - Strong technical expertise to solve issues faster; THE LAST PRINTER YOU'LL EVER NEED. Enjoy years of refillable, cartridge-free printing.
$189.99
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 output and capture options. Cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. An MCP server lets AI agents take screenshots. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up free for 1,000 screenshots a month, with no card.

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.

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.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

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.