Use Bun to run Puppeteer or Playwright, wait until the page is genuinely ready, then call page.pdf() and save the returned bytes. This is the most stable approach because both libraries document a high-level PDF API. Bun.WebView can drive a browser and expose Chrome DevTools Protocol (CDP), but it is experimental and has no documented high-level pdf() method.
Choose the right Bun PDF approach
Your choice depends on how much browser control and operational predictability you need.
| Approach | PDF API | Browser requirement | Best fit | Main caveat |
|---|---|---|---|---|
| Puppeteer | page.pdf() |
Chromium downloaded or otherwise available, depending on the installed version | Stable scripts and services using Chrome | Package and browser installation details vary by version; follow the selected version’s official guidance. |
| Playwright | page.pdf() |
A supported browser installation | Projects that also need Playwright’s browser automation and testing features | PDF output is print-media by default, so configure media deliberately. |
| Bun.WebView | No documented high-level PDF method; raw cdp() can reach Chrome printing commands |
System WebKit on macOS, or Chrome-family executable for Chrome mode | Experimental integrations where direct WebView/CDP control is acceptable | Experimental API, platform-dependent browser discovery, and version-sensitive CDP code. |
For a production converter, start with Puppeteer or Playwright. Use WebView only when you can pin Bun and browser versions and test the CDP path on every deployment platform.
Convert a URL to PDF with Puppeteer in Bun
Install and run
Create a Bun project, install Puppeteer, and follow the installation instructions for the exact Puppeteer version you select. The package may download a compatible browser or expect one supplied by your environment.
#1 Best Overall
- PORTABLE SCANNER FOR USE ON-THE-GO — The fastest and lightest mobile single-sheet-fed compact document scanner in its class¹
- QUICK DOCUMENT SCANNING ― This Epson ultra-fast scanner scans a single page as quickly as 5.5 seconds²; Windows and Mac compatible
- VERSATILE PAPER HANDLING ― Portable scanner scans documents up to 8.5 x 72 in; Also easily digitizes receipts and ID cards to make accounting, bookkeeping, and organizing simpler
- INTUITIVE, HIGH-SPEED SOFTWARE — Epson ScanSmart Software³ is a smart tool allowing you to easily scan, review, and save; Stay organized easily with the help of this Epson scanner
- EASY SETUP — USB-powered connect to your computer for quick and simple scanning; No batteries or external power supply required to operate portable document scanner; Standard Connectivity: USB 2.0
bun init
bun add puppeteer
bun run pdf.ts https://example.com
Save this as pdf.ts:
import puppeteer from 'puppeteer';
const url = process.argv[2] ?? 'https://example.com';
const browser = await puppeteer.launch();
const page = await browser.newPage();
try {
await page.goto(url, { waitUntil: 'networkidle2' });
await page.pdf({
path: 'page.pdf',
format: 'A4',
printBackground: true,
});
} finally {
await browser.close();
}
page.goto() waits for navigation and the example uses Puppeteer’s documented networkidle2 strategy. page.pdf() writes the PDF to page.pdf; it also returns PDF bytes if you omit path. Puppeteer waits for web fonts by default, but that does not guarantee that application data, images, or charts have finished rendering.
Return bytes instead of writing a path
import puppeteer from 'puppeteer';
import { writeFile } from 'node:fs/promises';
const browser = await puppeteer.launch();
try {
const page = await browser.newPage();
await page.goto('https://example.com', { waitUntil: 'networkidle2' });
const pdf = await page.pdf({ format: 'A4', printBackground: true });
await writeFile('page.pdf', pdf);
} finally {
await browser.close();
}
This form is useful when a Bun server must upload the bytes, attach them to a response, or apply its own naming and storage policy.
Wait for client-rendered content
Network idle is not a universal “application ready” signal. Long polling, analytics, WebSockets, and streaming can keep a page active indefinitely, while a single API request may finish before the UI has displayed its result. Add an explicit readiness condition:
await page.goto('https://app.example.com/report', { waitUntil: 'domcontentloaded' });
await page.waitForSelector('[data-report-ready]', { timeout: 30_000 });
await page.evaluate(() => document.fonts.ready);
await page.pdf({ path: 'report.pdf', format: 'A4', printBackground: true });
Have the application add data-report-ready only after its data, images, and charts are visible. If you cannot change the page, wait for a known selector, a short delay, or an application-specific flag exposed through the page.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteControl print layout, colors, and paper
Print CSS versus screen CSS
Puppeteer and Playwright generate PDFs using the print CSS media type by default. To reproduce the on-screen design instead, emulate screen media before printing:
Rank #2
- FAST SPEEDS - Scans color and black and white documents a blazing speed up to 16ppm (1). Color scanning won’t slow you down as the color scan speed is the same as the black and white scan speed.
- ULTRA COMPACT – At less than 1 foot in length and only about 1. 5lbs in weight you can fit this device virtually anywhere (a bag, a purse, even a pocket).
- READY WHENEVER YOU ARE – The DS-640 mobile scanner is powered via an included micro USB 3. 0 cable allowing you to use it even where there is no outlet available. Plug it into you PC or laptop and you are ready to scan.
- WORKS YOUR WAY – Use the Brother free iPrint&Scan desktop app for scanning to multiple “Scan-to” destinations like PC, Network, cloud services, Email and OCR. (2) Supports Windows, Mac and Linux and TWAIN/WIA for PC/ICA for Mac/SANE drivers. (3)
- OPTIMIZE IMAGES AND TEXT – Automatic color detection/adjustment, image rotation (PC only), bleed through prevention/background removal, text enhancement, color drop to enhance scans. Software suite includes document management and OCR software. (4)
await page.emulateMediaType('screen');
await page.pdf({ path: 'screen-style.pdf', format: 'A4', printBackground: true });
Use print media for documents intended for paper or archival output. Use screen media when the web page’s screen stylesheet is the desired visual result. Print color adjustment can alter colors; add -webkit-print-color-adjust: exact in the page’s CSS when exact colors are required and the page author controls that stylesheet.
Common PDF options
- Paper: choose
format: 'A4','Letter', or another supported format, or provide explicit width and height. - Margins: set
marginvalues such as{ top: '20mm', right: '15mm', bottom: '20mm', left: '15mm' }. - Backgrounds: set
printBackground: truefor colored sections, images, and backgrounds. - Headers and footers: enable the library’s display-header/footer option and provide HTML templates when you need page numbers or document metadata; reserve space with margins.
- Page size and orientation: use
landscape: truefor wide tables or explicit dimensions for custom paper. - Page ranges: render selected pages when your Puppeteer or Playwright version supports the relevant option.
Keep layout rules in print CSS where possible: avoid breaking headings from their following content, set predictable widths, and hide navigation or interactive controls that do not belong in the document.
Playwright alternative in Bun
Playwright exposes the same essential flow: navigate, wait for readiness, optionally emulate media, and call page.pdf(). Its PDF method returns a buffer and uses print CSS by default.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →import { chromium } from 'playwright';
const browser = await chromium.launch();
try {
const page = await browser.newPage();
await page.goto(process.argv[2] ?? 'https://example.com', { waitUntil: 'networkidle' });
await page.waitForLoadState('domcontentloaded');
const pdf = await page.pdf({
path: 'page.pdf',
format: 'A4',
printBackground: true,
});
console.log(`Wrote ${pdf.length} bytes`);
} finally {
await browser.close();
}
Install Playwright and its supported browser according to the version’s official instructions. The exact browser-download command and package behavior are version-specific, so pin the dependency in your project and document that setup for deployment.
Can Bun.WebView generate a PDF?
Bun documents Bun.WebView as an experimental headless browser. It can navigate, execute JavaScript, interact with elements, take screenshots, and expose a raw cdp(method, params?) bridge after navigation. The reference does not document a high-level pdf() method.
Rank #3
- STAY ORGANIZED – Easily convert your paper documents into digital formats like searchable PDF files, JPEGs, and more.Power Consumption : 2.5W or less (Energy Saving Mode: 0.7W). Suggested Daily Volume : 500 scans..Does it contain liquid: no
- CONVENIENT AND PORTABLE –lightweight and small in size, you can take the scanner anywhere from home offices, classrooms, remote offices, and anywhere in between
- HANDLES VARIOUS MEDIA TYPES – Digitize receipts, business cards, plastic or embossed cards, reports, legal documents, and more
- FAST AND EFFICIENT – No technical hurdles or complicated setups here; easily scan both sides of a document at the same time, in color or black-and-white, at up to 12 pages-per-minute, and with a 20 sheet automatic feeder
- BROAD COMPATIBILITY – Works with both Windows and Mac devices, be it laptop or computer
In Chrome mode, a CDP printing command may be technically possible, but that integration is version-sensitive and requires you to verify the target Bun release and Chrome protocol. The Chrome backend searches for Chrome, Chromium, Edge, Brave, and related binaries and can also use Playwright’s chrome-headless-shell cache. If no executable is found, construction fails. Chrome mode is available on macOS, Linux, and Windows; WebKit mode is macOS-only.
Because WebView is experimental, treat CDP PDF printing as an advanced integration rather than the default tutorial path. Pin Bun, the browser, and your CDP parameters; add a smoke test that opens a known page and validates the resulting PDF before deploying.
Production workflow and reliability checklist
- Validate input. Accept only permitted URL schemes (normally HTTPS), apply an allowlist if users supply URLs, and set a navigation timeout.
- Launch predictably. Reuse a browser process where appropriate, but create a fresh page or context per job so cookies and page state do not leak between users.
- Navigate with an intentional wait. Use
networkidle2or Playwright’s equivalent for ordinary pages; use a selector or application readiness signal for long-lived apps. - Wait for visual assets. Check the required content, fonts, images, and charts. Lazy-loaded images may need scrolling or an application-specific trigger.
- Set media and paper options. Decide print versus screen CSS, backgrounds, margins, orientation, and page ranges before rendering.
- Write atomically. Save to a temporary path or buffer, verify that a PDF was produced, then move it into final storage.
- Always close resources. Put
browser.close()infinallyso failed navigation does not leak browser processes.
Troubleshooting Bun PDF conversion
“Browser executable not found”
Install the browser required by your Puppeteer, Playwright, or WebView setup, or configure the launcher with an explicit executable path. Ensure the runtime user can execute it in the deployment container.
The PDF is blank or missing data
The page likely printed before client rendering completed. Replace a generic network-idle wait with waitForSelector, a readiness flag, or a short, bounded delay. Check that the requested URL does not require authentication or a blocked API call.
Colors or backgrounds differ
PDFs use print media by default and printing may adjust colors. Try page.emulateMediaType('screen') when screen styling is intended, and enable printBackground. If you own the CSS, use -webkit-print-color-adjust: exact selectively.
Rank #4
- IRIScan Express, portable scanner : scans color and black and white documents a blazing speed up to 8ppm simplex. Color scanning won’t slow you down as the color scan speed is the same as the black and white scan speed.
- IRIScan Express mobile scanner is powered via an included micro USB 2. 0 cable allowing you to use it even where there is no outlet available. Plug it into you PC or laptop and you are ready to scan. USB cable provided. AC Adapter not provided and not needed.
- IRIScan flatbed scanner uses a simplex scanning mode allows for quick and straightforward scanning of single-sided documents. IRIScan with its full portable features is the ideal document scanners for computers.
- IRIScan document scanner : Versatile scanning capabilities, including scanning to Word, PDF, and Excel formats with companion software provided Readiris OCR
- Receipt scanner and card scanner with Additional features include scanning business cards directly to Outlook, photo scanning, and receipt scanning for efficient document management
Navigation times out
Investigate slow third-party resources, redirects, bot checks, and pages that never become idle because of polling. Increase the timeout only when justified; otherwise wait for the document’s own ready selector and disable nonessential resources.
Crashes, 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 minutePC 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 & 11Fonts or images are absent
Wait for document.fonts.ready, verify cross-origin assets are reachable from the browser environment, and ensure lazy content is triggered before printing.
Processes accumulate after failures
Close the browser in a finally block and add job-level timeouts. In a worker service, monitor child-process count and restart unhealthy workers rather than allowing unbounded browser leakage.
Or skip the browser setup
ScreenshotNeo provides a hosted URL-to-PDF API when you do not want to install or operate a browser. Its endpoint is documented at https://screenshotneo.com/docs/. A one-call Bun-compatible request can save a PDF response:
const q = new URLSearchParams({
access_key: 'YOUR_API_KEY',
url: 'https://stripe.com'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`ScreenshotNeo request failed: ${res.status}`);
await Bun.write('page.pdf', await res.arrayBuffer());
Before capture, ScreenshotNeo accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response reports the page verdict and billing status in X-Page-Verdict and X-Billed headers. It also offers an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →The Free plan includes 1,000 shots per month with no card. Paid plans start at $5 for 3,000 shots; yearly billing gives two months free, and every feature is included on every plan. Sign up for the free plan to try it without a card.
Best Value
- Scanner type: Document
- Connectivity technology: USB
- With Auto Scan Mode, the scanner automatically detects what you're scanning
- Digitize documents and images
Cost, performance, and operational trade-offs
Local Puppeteer or Playwright gives maximum control over authentication, JavaScript, CSS, request interception, and file handling, but each worker consumes browser CPU and memory and needs browser patching and sandbox decisions. Browser startup adds latency; keeping a controlled browser process warm can improve throughput, while isolating pages or contexts protects jobs from state leakage.
WebView may reduce library layering, but its experimental status and platform-specific executable requirements increase maintenance risk. A hosted service removes browser installation and scaling work, but introduces an external request, API-key management, and per-shot billing. Choose based on whether control, deployment simplicity, or predictable operations matter most for your workload.
FAQ
Does Bun have a built-in URL-to-PDF function?
Bun’s documented WebView API does not provide a high-level PDF method. Puppeteer or Playwright is the practical documented route.
Free tools Windows power users keep installed
One-click scans. No signup required.
Why does my PDF use print styles?
Both Puppeteer and Playwright use the print CSS media type by default. Emulate screen media before calling page.pdf() when that is the intended output.
Can I convert authenticated pages?
Yes. Create the browser context with the required cookies or authentication headers, then wait for the authenticated page’s own readiness signal before printing.
Frequently Asked Questions
Does Bun have a built-in URL-to-PDF function?
Bun.WebView has no documented high-level PDF method; use Puppeteer or Playwright for the documented page.pdf() flow.
Why does my PDF use print styles?
Puppeteer and Playwright use print CSS by default. Emulate screen media before printing when necessary.
Can I convert authenticated pages?
Yes, provide the required cookies or headers in the browser context and wait for the authenticated UI to finish rendering.
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.

