How to Print and Download a Full-Size React Component as a PDF
Print a complete React component without clipping, control page breaks, and download a PDF with browser APIs or a programmatic pipeline.

To print a full-size React component, render it inside a dedicated root, remove height and overflow constraints in print CSS, hide controls, set @page hints, wait for assets, then call window.print() or react-to-print. The browser print dialog can save the result as a PDF.
If your application must download a file without opening print preview, use a PDF generator such as jsPDF with html2canvas, or send the page to a server-side PDF service. Those approaches trade some CSS fidelity and selectable text for download control.
1. Build a printable React component
Keep the printable content in its own element and attach a ref. Buttons, navigation, and application chrome should sit outside that element or receive a print-only class.
import { useRef } from 'react';
export function ReportPage() {
const printRef = useRef<HTMLDivElement>(null);
return (
<main>
<button className='no-print' onClick={() => window.print()}>
Save as PDF
</button>
<div ref={printRef} className='print-root'>
<LargeReport />
</div>
</main>
);
}
function LargeReport() {
return (
<article className='report'>
<header>
<h1>Quarterly usage report</h1>
<p>January–March 2026</p>
</header>
<section className='report-section'>
<h2>Summary</h2>
<p>Your component can contain charts, tables, images, and several pages of content.</p>
</section>
<section className='report-section page-break-before'>
<h2>Details</h2>
<table>
<thead><tr><th>Month</th><th>Requests</th></tr></thead>
<tbody>
<tr><td>January</td><td>12,400</td></tr>
<tr><td>February</td><td>14,100</td></tr>
<tr><td>March</td><td>15,800</td></tr>
</tbody>
</table>
</section>
</article>
);
}
2. Add print CSS that allows the component to grow
Most clipped PDFs come from a fixed viewport height or an ancestor with overflow: auto. Override those constraints only while printing.

.print-root {
max-width: 1100px;
margin: 0 auto;
}
@media print {
.no-print,
nav,
.toolbar,
.sticky-actions {
display: none !important;
}
html,
body {
margin: 0 !important;
padding: 0 !important;
background: #fff !important;
}
.print-root,
.print-root * {
box-sizing: border-box;
}
.print-root {
width: 100% !important;
max-width: none !important;
height: fit-content !important;
min-height: 0 !important;
max-height: none !important;
overflow: visible !important;
}
.report {
width: 100%;
color: #000;
}
.report-section {
break-inside: avoid;
page-break-inside: avoid;
}
.page-break-before {
break-before: page;
page-break-before: always;
}
table {
width: 100%;
border-collapse: collapse;
}
thead {
display: table-header-group;
}
tr {
break-inside: avoid;
page-break-inside: avoid;
}
@page {
size: A4 portrait;
margin: 12mm;
}
}
@page supplies paper and margin hints; the browser and the user’s print settings still determine the final output. For US Letter use size: Letter portrait. Use landscape for wide tables or charts.
Remove every scrolling ancestor
Changing only the printable element is insufficient when a parent creates a clipping context. In print media, set overflow: visible, remove fixed heights, and disable sticky positioning on the printable element and its relevant ancestors.
@media print {
.app-shell,
.content-panel,
.dashboard-scroll {
height: auto !important;
max-height: none !important;
overflow: visible !important;
position: static !important;
}
}
3. Wait for data, images, and fonts
Invoke printing only after asynchronous data has rendered and visual assets are ready. Otherwise the print document can contain placeholders or missing images.
async function waitForPrintableAssets(root: HTMLElement) {
const images = Array.from(root.querySelectorAll('img'));
await Promise.all(
images.map((image) => {
if (image.complete) return Promise.resolve();
return new Promise<void>((resolve) => {
image.addEventListener('load', () => resolve(), { once: true });
image.addEventListener('error', () => resolve(), { once: true });
});
})
);
if (document.fonts?.ready) {
await document.fonts.ready;
}
}
export function PrintButton({ root }: { root: HTMLElement | null }) {
const print = async () => {
if (!root) return;
await waitForPrintableAssets(root);
window.print();
};
return <button className='no-print' onClick={print}>Save as PDF</button>;
}
4. Use react-to-print for a selected component
react-to-print prepares a print iframe for a component ref, can copy styles, sets a document title, and provides callbacks. Install it with your package manager, then adapt the API names to the installed major version.
npm install react-to-print
import { useRef } from 'react';
import { useReactToPrint } from 'react-to-print';
export function ReportWithReactToPrint() {
const contentRef = useRef<HTMLDivElement>(null);
const print = useReactToPrint({
contentRef,
documentTitle: 'component-export',
onBeforePrint: async () => {
if (contentRef.current) {
await waitForPrintableAssets(contentRef.current);
}
},
onAfterPrint: () => {
console.log('Print dialog closed');
},
});
return (
<>
<button className='no-print' onClick={print}>Print or save PDF</button>
<div ref={contentRef} className='print-root'>
<LargeReport />
</div>
</>
);
}
Put print rules in the component’s own stylesheet. Styles that depend on an application-shell parent may not exist inside the print iframe. react-to-print does not itself bypass print preview to download a PDF; its custom print callback can hand the prepared iframe document to a PDF generator when that workflow is required.
5. Download a PDF programmatically
Use this path when the interface must start a file download without relying on print-preview controls. jsPDF creates the PDF, while html2canvas rasterizes DOM content into images. Install both packages:
npm install jspdf html2canvas
import html2canvas from 'html2canvas';
import jsPDF from 'jspdf';
export async function downloadComponentPdf(root: HTMLElement) {
await waitForPrintableAssets(root);
const canvas = await html2canvas(root, {
backgroundColor: '#ffffff',
scale: window.devicePixelRatio || 1,
useCORS: true,
logging: false,
});
const pdf = new jsPDF({
orientation: 'portrait',
unit: 'mm',
format: 'a4',
});
const pageWidth = 210;
const pageHeight = 297;
const margin = 12;
const usableWidth = pageWidth - margin * 2;
const imageHeight = (canvas.height * usableWidth) / canvas.width;
const image = canvas.toDataURL('image/png');
let remaining = imageHeight;
let y = margin;
pdf.addImage(image, 'PNG', margin, y, usableWidth, imageHeight);
remaining -= pageHeight - margin * 2;
while (remaining > 0) {
pdf.addPage();
y = margin - (imageHeight - remaining);
pdf.addImage(image, 'PNG', margin, y, usableWidth, imageHeight);
remaining -= pageHeight - margin * 2;
}
pdf.save('component-export.pdf');
}
This produces image-like pages. Text selection, links, font rendering, very tall canvases, and page-break placement need verification for your component. html2canvas documents CSS support boundaries and cannot render cross-origin iframes; canvases containing cross-origin content can become unreadable. See the html2canvas documentation and jsPDF project documentation.
Hybrid: prepare with react-to-print, generate with a custom callback
A hybrid pipeline lets react-to-print isolate the component and copy its styles, then passes the print iframe’s document to your PDF generator. Keep browser printing available as a fallback when selectable text and accessibility matter more than an automatic download.
6. Choose the right PDF path
| Requirement | Browser print | react-to-print | jsPDF + html2canvas |
|---|---|---|---|
| Selectable text | Usually preserved | Usually preserved | Usually rasterized |
| Automatic download | No; user chooses Save as PDF | No; it opens print preview | Yes |
| Component isolation | Manual ref and CSS | Built in | Manual DOM selection |
| CSS fidelity | Browser print engine | Browser print engine | Limited by html2canvas support |
| Page-break control | break-* and @page |
Same CSS rules | Manual slicing or layout |
| Cross-origin assets | Subject to browser rules | Subject to browser rules | Cross-origin iframes cannot be rendered |
| Bundle impact | Minimal | Small wrapper | Additional rasterization and PDF libraries |
| Mobile/WebView behavior | Depends on platform print support | Still depends on print support | Can download in supported browsers |
7. Page breaks, tables, charts, and wide layouts
- Use
break-before: pagefor known section starts andbreak-inside: avoidfor cards, figures, and table rows. - Use
thead { display: table-header-group; }so table headings repeat where the browser supports it. - For wide tables, choose landscape or create a deliberate print layout instead of shrinking text until it is unreadable.
- Charts rendered on canvas may need a higher capture scale; SVG charts generally remain sharper in browser print.
- Do not place a fixed-height chart or card inside an ancestor with
overflow: hidden. - Verify background graphics, scale, margins, paper size, and destination in the print dialog.
@media print {
.wide-table-page {
break-before: page;
}
.wide-table {
font-size: 9pt;
}
.keep-together {
break-inside: avoid;
page-break-inside: avoid;
}
}
8. Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| The PDF shows only the viewport | Fixed height or scrolling container | Set height and max-height to auto and overflow to visible in @media print. |
| The right side of a dashboard is missing | Desktop layout is wider than the paper | Use landscape, reduce print-only widths, or create a responsive print layout. |
| Buttons and navigation appear | No print-only hiding rule | Add display: none !important to a no-print class and other controls. |
| Styles disappear with react-to-print | Rules target an unprinted parent or are not copied into the iframe | Use selectors rooted in the printed component and include its stylesheet. |
| Images are blank | Printing started before images loaded, or the source is cross-origin | Wait for image load events, configure permitted CORS, or use same-origin assets. |
| Fonts change | Web fonts were not ready | Await document.fonts.ready and ensure the font is available to the print document. |
| A section splits awkwardly | No break rule or the section is taller than a page | Add break-inside: avoid; split oversized sections into smaller blocks. |
| Programmatic PDF text is not selectable | html2canvas produced a raster image | Use browser printing or a PDF pipeline that lays out text and links natively. |
| html2canvas throws a security error | Cross-origin content tainted the canvas | Serve assets with suitable CORS headers or remove the cross-origin iframe. |
| Print uses stale data | React state or a query was still pending | Disable the print action while loading and wait for the final render. |
| Mobile print does nothing | The browser or embedded WebView lacks print support | Offer a programmatic download or a server-side PDF endpoint. |
9. Reliability and performance checklist
- Render a dedicated print root instead of printing the entire application shell.
- Wait for data, images, fonts, and chart rendering before capture.
- Test at each target paper size and orientation in the browsers your users run.
- Keep print CSS deterministic: avoid animations, transitions, sticky elements, and time-dependent content.
- For large components, browser printing avoids an extra rasterization pass; html2canvas memory use grows with pixel dimensions and device scale.
- For programmatic generation, split very tall content into deliberate sections rather than creating one enormous canvas.
- Use a stable filename through
documentTitleorpdf.save(), and log failures around data loading and asset readiness. - Run visual checks for clipped tables, missing backgrounds, broken links, and page breaks after dependency or browser upgrades.
10. Or skip the browser setup
ScreenshotNeo can capture a URL as a PNG, JPEG, WebP, or PDF with one GET request. It is useful when the React page is already deployed and you need a repeatable capture outside a user’s browser. Its cleanup steps accept cookie or consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.

See the ScreenshotNeo API documentation for the complete option set, including full-page capture, lazy-image loading, CSS selector element capture, device presets, custom viewport and retina scale, PDF paper size, margins, orientation and page ranges, custom CSS and JavaScript, clicks, waits, request blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, caching TTL, signed links, asynchronous jobs, signed webhooks, bulk capture, usage, and OpenAPI details.
curl -G 'https://api.screenshotneo.com/v1/shot' \
-d access_key=YOUR_API_KEY \
--data-urlencode url=https://your-app.example.com/report \
-o report.pdf
import requests
r = requests.get(
'https://api.screenshotneo.com/v1/shot',
params={
'access_key': 'YOUR_API_KEY',
'url': 'https://your-app.example.com/report',
'format': 'pdf',
},
timeout=90,
)
r.raise_for_status()
open('report.pdf', 'wb').write(r.content)
const q = new URLSearchParams({
access_key: 'YOUR_API_KEY',
url: 'https://your-app.example.com/report',
format: 'pdf',
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot failed: ${res.status}`);
const bytes = new Uint8Array(await res.arrayBuffer());
// Write bytes to report.pdf with your Node.js file API.
There are 1,000 free screenshots each month with no card. Paid plans start at $5 for 3,000 shots, and every feature is included on every plan. Create a free ScreenshotNeo account.
11. Frequently asked questions
Can I print only one component?
Yes. Put that component in a dedicated ref and hide the rest of the page with print CSS, or use react-to-print’s component selection.
Does window.print() download a PDF automatically?
No. It opens the browser print dialog; the user selects Save as PDF. MDN describes it as opening the print dialog and notes that it waits for a still-loading document to finish: Window.print().
Why is my full component clipped?
A fixed height, scroll container, hidden overflow, or an overly wide layout is usually responsible. Remove those constraints in print media and choose an appropriate paper orientation.
Should I use react-to-print or html2canvas?
Use browser printing or react-to-print when selectable text and browser CSS fidelity matter. Use html2canvas with jsPDF when an automatic client-side download matters and image-like pages are acceptable.
Can a PDF include content from an iframe?
Browser printing depends on the iframe’s origin and permissions. html2canvas cannot render cross-origin iframes, so proxy or otherwise make required content same-origin before rasterization.
How do I prevent a chart or card from splitting?
Apply break-inside: avoid and page-break-inside: avoid, while allowing sections taller than one page to split naturally.


