Recommended Free Tools
To convert an Astro page to a PDF, render the page in a headless Chromium browser and return the bytes from an Astro endpoint. Create a route such as src/pages/api/page.pdf.ts, open the target with Puppeteer or Playwright, wait for content and fonts, call page.pdf(), and send the result with Content-Type: application/pdf. Use a static file when every visitor receives the same document; use an on-demand endpoint for current, authenticated, or user-specific content.
How Astro PDF generation works
Astro supplies the route and HTTP response; a browser engine supplies HTML-to-PDF rendering. An Astro page is not converted by the framework alone. Puppeteer and Playwright launch Chromium, load the fully rendered URL, apply print media styles, and expose a PDF method that returns a byte buffer.
Astro prerenders routes by default. A request-time PDF route must run in a server deployment, use an adapter, and opt out of prerendering with export const prerender = false. A JavaScript or TypeScript file under src/pages can act as the endpoint.
Prerequisites and project setup
- An Astro project with the page you want to print.
- A deployment adapter capable of running server endpoints.
- Either Puppeteer (which downloads or uses a Chromium binary) or Playwright with a supported browser installed.
- A target URL reachable from the browser process. A relative path is not sufficient when the browser runs separately from the Astro server.
Install one browser library in the project. Keep the choice consistent with your existing dependencies and deployment environment; both libraries provide first-class PDF APIs.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Generate a PDF with Puppeteer
Create src/pages/api/page.pdf.ts:
import puppeteer from 'puppeteer';
export const prerender = false;
export async function GET({ site }: { site?: URL }) {
const target = new URL('/docs/example', site ?? 'http://localhost:4321');
const browser = await puppeteer.launch({ headless: true });
try {
const page = await browser.newPage();
await page.goto(target.toString(), { waitUntil: 'networkidle0' });
const pdf = await page.pdf({
format: 'A4',
printBackground: true,
preferCSSPageSize: true,
});
return new Response(pdf, {
headers: {
'Content-Type': 'application/pdf',
'Content-Disposition': 'attachment; filename="page.pdf"',
},
});
} finally {
await browser.close();
}
}
Requesting /api/page.pdf now downloads page.pdf. page.pdf() uses the print CSS media type by default. The finally block is essential: it closes Chromium even when navigation or PDF creation fails.
Use a dynamic target safely
If the endpoint accepts a URL or document ID, validate it before navigation. Prefer an allowlist of your own origins, reject unsupported protocols, and avoid letting arbitrary users make your server browse internal network addresses. Pass authentication deliberately with page cookies, headers, or a server-side session rather than exposing credentials in query strings.
Generate a PDF with Playwright
The equivalent endpoint with Playwright is:
import { chromium } from 'playwright';
export const prerender = false;
export async function GET() {
const browser = await chromium.launch();
try {
const page = await browser.newPage();
await page.goto('http://localhost:4321/docs/example', {
waitUntil: 'networkidle',
});
const pdf = await page.pdf({
format: 'A4',
printBackground: true,
preferCSSPageSize: true,
});
return new Response(pdf, {
headers: {
'Content-Type': 'application/pdf',
'Content-Disposition': 'attachment; filename="page.pdf"',
},
});
} finally {
await browser.close();
}
}
Playwright can switch from print rendering to screen rendering before creating the PDF:
await page.emulateMedia({ media: 'screen' });
const pdf = await page.pdf({ format: 'A4', printBackground: true });
Use Puppeteer when your project already depends on it or its API is familiar. Use Playwright when you also need its browser and testing workflow. The decisive constraint is whether the selected browser binary can run on your Astro host.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Design the page for print
Put PDF-specific rules in a print stylesheet instead of trying to force the screen layout into paper:
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
@page {
size: A4;
margin: 18mm 14mm;
}
@media print {
nav,
.toolbar,
.no-print,
button {
display: none !important;
}
.page-break {
break-before: page;
}
a {
color: #000;
text-decoration: none;
}
* {
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
}
}
The browser normally applies print media when page.pdf() runs. If you explicitly emulate screen, screen rules are used instead, so make that choice intentional. The -webkit-print-color-adjust declaration helps preserve exact colors, although printer and browser settings can still affect output.
Important PDF options
format: a paper preset such asA4.widthandheight: custom page dimensions when a preset is unsuitable.margin: top, right, bottom, and left margins.printBackground: true: includes colored backgrounds, cards, and charts.preferCSSPageSize: true: lets your@pagerule control size and margins.landscape: true: useful for wide tables.scale: adjusts the rendered size.pageRanges: exports selected pages when supported by the chosen library.
Wait for real content, fonts, and images
networkidle or networkidle0 is a useful starting point, not a guarantee. Analytics, WebSockets, polling, and other long-lived connections can prevent an idle event or fire it before a client-side component finishes.
For deterministic output, wait for a selector that marks completion and for fonts:
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsawait page.goto(target.toString(), { waitUntil: 'domcontentloaded' });
await page.waitForSelector('[data-pdf-ready]', { timeout: 30000 });
await page.evaluate(() => document.fonts.ready);
await page.waitForTimeout(250);
Lazy images may need scrolling or an application-specific ready signal. A fixed delay alone is less reliable than a selector or explicit page state. Set navigation and selector timeouts so a broken page cannot hold a server request indefinitely.
Static PDFs versus on-demand PDFs
Build a static PDF
For a document identical for every visitor, generate it during your build and publish the resulting file from public/. This avoids launching a browser per request, reduces latency and hosting cost, and works well for release notes, manuals, and legal documents that change only when you deploy. Regenerate whenever the source page changes.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Render on demand
Use the endpoint approach for current data, personalized content, or authenticated pages. Add an Astro adapter for your host, set prerender = false, and ensure the runtime has a compatible browser binary. Astro adapters are available for common Node.js, Netlify, Vercel, and Cloudflare deployments, but browser support and packaging differ by provider. Verify the selected adapter and host before production.
Headers, authentication, and response behavior
Return a download with Content-Disposition: attachment. Use inline instead when the browser should display the PDF in its viewer. If you cache a deterministic PDF, include an appropriate cache policy and vary it by the inputs that affect the document. Do not cache a user-specific PDF publicly.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, 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 minuteFor protected pages, create a browser context with the required cookies or headers, or render the document from trusted server data instead of logging a browser into a user account. Never put bearer tokens in the target URL because URLs can be logged.
Troubleshooting common failures
The route returns HTML instead of a PDF
Confirm the request reaches the endpoint, that the handler returns the Response containing the PDF buffer, and that Content-Type is exactly application/pdf. A redirect, framework error page, or missing adapter usually means the route is being prerendered or the server function is not running.
The PDF is blank or missing client-rendered content
Navigate to the final URL, wait for a completion selector, and wait for document.fonts.ready. Replace an unconditional idle wait when the page keeps a connection open. Check that API calls made by the page are reachable from the deployment environment.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Screen styles are ignored
This is expected: PDF generation uses print media by default. Move the intended layout into @media print, or call page.emulateMedia({ media: 'screen' }) before page.pdf(). Keep print-specific navigation and controls hidden.
Colors or backgrounds disappear
Set printBackground: true and use -webkit-print-color-adjust: exact for important colors. Also check that your CSS does not disable backgrounds in print.
Chromium launches locally but fails in production
The host may not include the browser executable or required system libraries. Use the browser packaging supported by your adapter, configure the executable path only when your provider documents one, and test the production build in an environment matching the deployment runtime.
Requests hang or exhaust resources
Set navigation and selector timeouts, block unnecessary third-party requests where appropriate, reuse a controlled browser process when your runtime model allows it, and always close pages and browsers in cleanup code. Limit concurrent PDF jobs so several large documents cannot exhaust memory.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Performance, reliability, and security checklist
- Use static generation for immutable documents.
- Reuse a browser process carefully instead of launching one for every high-volume request, while isolating pages and closing them after use.
- Wait for application readiness rather than relying only on network idle.
- Keep PDFs bounded: large images and very long pages consume substantial memory.
- Validate target URLs and block private-network destinations for any user-controlled input.
- Apply authentication server-side and avoid leaking cookies or tokens into logs.
- Monitor timeout, launch, navigation, and PDF errors separately so failures are diagnosable.
Or skip the browser setup
ScreenshotNeo provides a website screenshot and PDF API when you do not want to package Chromium in your Astro server. One GET request can return a PDF; its cleaner accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing result. It also offers an MCP server for AI agents, including Claude and Cursor, with take_screenshot, get_page_info, and capture_pdf tools.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →See the full parameter list in the ScreenshotNeo documentation. A PDF request can use the same endpoint:
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o page.pdf
For a server-side Astro integration in Python:
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("page.pdf", "wb").write(r.content)
For Node.js:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is included on every plan. Create a free ScreenshotNeo account.
FAQ
Can an Astro static site generate a PDF at request time?
Not without a server-capable deployment. A prerendered site can publish prebuilt PDF files, while request-time generation requires an adapter and a non-prerendered endpoint.
Should I use Puppeteer or Playwright?
Either works. Choose based on the dependency already in your project, the browser runtimes your host supports, and whether you want to reuse Playwright’s testing APIs.
Free tools Windows power users keep installed
One-click scans. No signup required.
Why does a PDF have a different number of pages after a CSS change?
Paper size, margins, scale, font loading, and print rules all change pagination. Set these explicitly and wait for fonts before capturing.
Frequently Asked Questions
Can I generate a PDF without exposing the source page publicly?
Yes. Render a protected route in a server-side browser context with controlled cookies or headers, or build the document from trusted server data. Do not place credentials in the target URL.
What is the safest way to accept a URL from a user?
Allowlist permitted origins and protocols, reject private-network destinations, impose navigation and output limits, and log failures without recording secrets.
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.

