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.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Use a real browser from Deno, wait for the page to render, call Puppeteer’s page.pdf(), and close the browser in a finally block. The approach handles client-rendered pages and gives you control over paper size, margins, CSS media, backgrounds, and page ranges. Deno can run the TypeScript directly, but you must grant the permissions your script and browser need and verify that the selected Puppeteer version and browser executable work in your deployment environment.

The supported conversion flow

A browser-based renderer is the most complete way to turn a live URL or generated HTML into a PDF. The browser executes JavaScript, loads fonts and images, applies the site’s styles, and then prints the rendered page. A typical Deno program follows five steps:

  1. Import a browser automation package from npm.
  2. Launch a browser.
  3. Open a page and navigate to the URL.
  4. Call page.pdf() with the output settings you need.
  5. Close the browser even when navigation or PDF generation fails.

Puppeteer’s PDF API returns a Uint8Array. Supplying a path writes the file for you; omitting it lets your code handle the bytes itself. PDF generation uses print CSS by default, so screen-style rendering requires an explicit media emulation call.

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

Prerequisites and Deno permissions

Runtime and package support

Deno runs TypeScript without a separate compiler step and can consume npm packages. The exact import syntax, Puppeteer release, and browser-install behavior can change, so confirm them against the versions used by your project before deploying. The documentation reviewed for this workflow does not establish one universal Deno-specific browser installation recipe.

#1 Best Overall
PDF Converter Ultimate - Convert PDF files into Word, Excel, PowerPoint and others - PDF converter software with OCR recognition compatible with Windows 11 / 10 / 8.1 / 8 / 7
  • Convert your PDF files into Word, Excel & Co. the easy way
  • Convert scanned documents thanks to our new 2022 OCR technology
  • Adjustable conversion settings
  • No subscription! Lifetime license!
  • Compatible with Windows 11, 10, 8.1, 7 - Internet connection required

Grant only the permissions you need

Deno starts with no file, network, or environment access. A remote page needs network access, and saving a PDF needs filesystem write access. Launching a locally managed browser can also require the process and read permissions expected by your runtime and browser setup. Start narrowly, then add a permission only when an error identifies a genuine requirement.

deno run --allow-net --allow-write --allow-read --allow-run page_to_pdf.ts

If your deployment provides a browser executable through a restricted service, its required permissions may differ. Do not use --allow-all merely to hide a permission error.

Complete Deno example with Puppeteer

Save this as page_to_pdf.ts. It navigates to a URL, waits for network activity to settle, prints an A4 PDF with backgrounds enabled, and always closes the browser.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import puppeteer from 'npm:puppeteer';

const url = 'https://example.com';
const browser = await puppeteer.launch();

try {
  const page = await browser.newPage();
  await page.goto(url, { waitUntil: 'networkidle2' });
  await page.pdf({
    path: 'page.pdf',
    format: 'A4',
    printBackground: true,
  });
} finally {
  await browser.close();
}

Run it with the permissions required by your environment:

deno run --allow-net --allow-write --allow-read --allow-run page_to_pdf.ts

The result is page.pdf in the current directory. In a production service, pass the URL and output path through validated configuration rather than accepting arbitrary user input; unrestricted navigation can expose internal addresses or private data.

Writing the returned bytes yourself

When you need to upload the PDF, encrypt it, or return it from an HTTP handler, omit path and use the returned bytes:

Rank #2
Doxillion Free Document Converter – Converts DOCX, DOC, PDF, WPS and Many More Files Quickly [Download]
  • Convert over 50 document file formats.
  • Preview your files from Doxillion before converting them.
  • Use batch conversion to convert thousands of files at once.
  • Enjoy an easy-to-use, intuitive interface with a Drag and Drop file option.
  • Burn your converted or original files directly to disc.
const pdf = await page.pdf({ format: 'A4', printBackground: true });
await Deno.writeFile('page.pdf', pdf);

The write operation still needs filesystem permission. The browser must remain open until the PDF promise resolves.

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

PDF settings that change the result

Option Effect Important default or interaction
format Chooses a named paper size such as A4. The documented default is Letter when no size is supplied.
width, height Sets custom paper dimensions. Use these when a named format does not match your output.
margin Controls top, right, bottom, and left whitespace. Specify units consistently, for example 20mm.
landscape Rotates the paper orientation. Useful for wide tables and dashboards.
printBackground Includes background colors and images. Defaults to false; set it to true when the design depends on backgrounds.
scale Scales the printed page. Changing it affects how much content fits on each sheet.
pageRanges Prints only selected pages. Use the range syntax accepted by Puppeteer.
preferCSSPageSize Lets CSS control the paper size. When enabled, a declared @page size takes priority over the format setting.
waitForFonts Waits for fonts before producing the PDF. Puppeteer documents this as true by default.
path Writes the PDF to a file. Omit it to receive a Uint8Array.

Print CSS versus screen CSS

Because PDF generation uses the print media type by default, a site’s @media print rules can hide navigation, change colors, or rearrange columns. To reproduce the on-screen design instead, set the media type before printing:

await page.emulateMediaType('screen');
await page.pdf({
  path: 'screen-style.pdf',
  format: 'A4',
  printBackground: true,
});

For your own HTML, define print-specific rules deliberately:

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

@media print {
  .site-nav,
  .cookie-banner {
    display: none;
  }
}

html {
  -webkit-print-color-adjust: exact;
}

The color-adjust property can preserve exact colors, but the final appearance still depends on the page’s assets, browser configuration, and CSS. No browser automation library guarantees identical output for every site.

Waiting for dynamic content

networkidle2 waits until network activity is quiet enough for the navigation to continue, but it cannot know whether an application has finished rendering a chart or loading data after a timer. Add an application-specific wait when necessary:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.goto(url, { waitUntil: 'domcontentloaded' });
await page.waitForSelector('[data-report-ready]');
await page.pdf({ path: 'report.pdf', format: 'A4', printBackground: true });

If the page has a known animation or delayed request, a short, explicit delay can be used, but selector-based readiness is less arbitrary. For long pages, make sure lazy-loaded images are triggered before printing; scrolling through the document or waiting for the application’s own “ready” signal may be required.

Rank #3
PDF Extra Ultimate | Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Yearly License | 1 Windows PC & 2 Mobile Devices | 1 User
  • EDIT text, images & designs in PDF documents. ORGANIZE PDFs. Convert PDFs to Word, Excel & ePub.
  • READ and Comment PDFs – Intuitive reading modes & document commenting and mark up.
  • CREATE, COMBINE, SCAN and COMPRESS PDFs
  • FILL forms & Digitally Sign PDFs. PROTECT and Encrypt PDFs
  • 1 Year License for 1 Windows & 2 Mobile (Android and/or iOS) devices.

Authenticated or customized pages

Perform login and cookie setup in the same browser context before calling page.pdf(). Keep credentials out of source files and logs. If a page blocks automated browsers, presents a CAPTCHA, or depends on a service unavailable from your deployment region, the PDF may contain an error page or incomplete content; automation cannot legitimately bypass a challenge.

Using Playwright instead

Playwright also exposes Page.pdf(), returns a PDF buffer, and uses print CSS by default. It documents the same screen-media pattern: emulate screen before generating the PDF when that is the desired output. Choose between Puppeteer and Playwright based on the package already used by your project, browser installation support in the target deployment, and the automation APIs you need. The available documentation does not establish a Deno-specific speed, cost, or reliability winner, so do not select one on an unverified benchmark.

Decision checklist

  • Keep Puppeteer if your codebase already uses its selectors, lifecycle, or plugins.
  • Choose Playwright when its browser-management or cross-browser APIs fit your deployment better.
  • For either library, pin and review versions, test the browser executable in the same container or host, and exercise representative pages before release.

Reliability, performance, and cost considerations

Reuse browsers for batches

Launching a browser for every URL adds startup overhead. For a batch job, launch once, create a fresh page per URL, close each page, and close the browser after the batch. A fresh page limits cookies and DOM state leaking between documents.

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

Control resource use

  • Set navigation and selector timeouts appropriate to your service rather than waiting forever.
  • Use page ranges, paper size, and scale to avoid producing unnecessarily large files.
  • Close pages and browsers in finally blocks so failed jobs do not accumulate processes.
  • Measure memory and PDF size with your own pages; the supplied documentation provides no universal performance figure.

Plan for changing pages

A PDF is a snapshot. Ads, timestamps, personalization, A/B tests, third-party widgets, and responsive breakpoints can change between runs. Record the URL, viewport, media type, browser version, and relevant options with each generated document when reproducibility matters.

Troubleshooting common failures

“Permission denied” or a network error

Cause: Deno blocked the requested capability. Fix: add the narrow permission required by the failing operation, such as --allow-net for navigation or --allow-write for the output file. Check that the host and port are allowed by your deployment’s network policy.

Browser launch fails

Cause: Puppeteer cannot find or start a compatible browser, or the runtime blocks the required process/read operation. Fix: verify the Puppeteer version, browser availability, executable path, and container dependencies. Test the same launch command in the deployment image; there is no single browser-install recipe that applies to every Deno environment.

Rank #4
PDF Extra Lifetime - Professional PDF Editor - Best Adobe Acrobat Pro Alternative - Lifetime License for Windows PC
  • Perfect Adobe Acrobat Pro alternative – lifetime license for Windows 10 and 11.
  • EDIT text, images, pages, hyperlinks, designs in PDF documents. ORGANIZE PDFs.
  • READ and Comment on PDFs – Intuitive reading modes & document commenting and mark up tools!
  • CREATE, COMBINE, SCAN and COMPRESS PDFs.
  • FILL forms & Digitally Sign PDFs. Work with Digital certificates

The PDF is blank or contains a loading screen

Cause: Printing happened before client-side rendering completed. Fix: wait for a specific ready selector, use an appropriate navigation condition, and confirm that API requests succeed from the host running Deno.

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

Colors or backgrounds are missing

Cause: print CSS is active or background printing is disabled. Fix: set printBackground: true, choose page.emulateMediaType('screen') when appropriate, and review @media print and -webkit-print-color-adjust.

Content is cut off or the layout is unexpectedly wide

Cause: paper dimensions, margins, orientation, scale, or responsive CSS do not match the page. Fix: set an explicit format or custom dimensions, try landscape, adjust margins and scale, and inspect the page at the viewport size used by the browser.

Fonts or images differ from the browser preview

Cause: assets were not available to the renderer, or the page changed media and loading behavior for print. Fix: wait for fonts and required selectors, verify asset responses, and ensure the browser can reach every origin used by the page.

Or skip the browser setup

ScreenshotNeo provides a website capture API and MCP server when you do not want to maintain browser automation in Deno. A single GET request returns a PNG, JPEG, WebP, or PDF; see the ScreenshotNeo documentation for request options.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G 'https://api.screenshotneo.com/v1/shot' -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
import requests
r = requests.get('https://api.screenshotneo.com/v1/shot', params={'access_key': 'YOUR_API_KEY', 'url': 'https://example.com'}, timeout=90)
open('shot.webp', 'wb').write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://example.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

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 disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing result. Its MCP server supplies take_screenshot, get_page_info, and capture_pdf tools to Claude, Cursor, and other MCP clients. The Free plan includes 1,000 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 to try it.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

FAQ

Can I convert HTML that is already in a Deno string?

Yes. Serve the string from a local or test HTTP endpoint that the browser can reach, or navigate to a controlled data URL. An HTTP endpoint is usually easier when the document references relative CSS, images, or fonts.

Best Value
Doxillion Free Document Converter for Mac – Converts DOCX, DOC, PDF, WPS and Many More Files Quickly [Download]
  • Convert over 50 document file formats.
  • Preview your files from Doxillion before converting them.
  • Use batch conversion to convert thousands of files at once.
  • Enjoy an easy-to-use, intuitive interface with a Drag and Drop file option.
  • Burn your converted or original files directly to disc.

Why does a CSS @page rule seem to be ignored?

Puppeteer only gives the CSS page size priority when preferCSSPageSize is enabled. Otherwise, the PDF options such as format and custom dimensions determine the paper.

Can I return the PDF directly from a Deno HTTP handler?

Yes. Keep the Uint8Array returned by page.pdf(), set a PDF content type and disposition, write the bytes to the response, and close the page and browser after the response data has been prepared.

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

Is a browser PDF identical to a print dialog PDF?

Not necessarily. Both use browser print concepts, but executable version, installed fonts, viewport, permissions, network timing, and page-specific CSS can change the result. Test the exact runtime used in production.

Frequently Asked Questions

Can I convert HTML that is already in a Deno string?

Yes. Serve the string from a local or test HTTP endpoint that the browser can reach, or navigate to a controlled data URL. An HTTP endpoint is usually easier when the document references relative CSS, images, or fonts.

Why does a CSS @page rule seem to be ignored?

Puppeteer only gives the CSS page size priority when preferCSSPageSize is enabled. Otherwise, the PDF options such as format and custom dimensions determine the paper.

Can I return the PDF directly from a Deno HTTP handler?

Yes. Keep the Uint8Array returned by page.pdf(), set a PDF content type and disposition, write the bytes to the response, and close the page and browser after the response data has been prepared.

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

Is a browser PDF identical to a print dialog PDF?

Not necessarily. Executable version, installed fonts, viewport, permissions, network timing, and page-specific CSS can change the result. Test the exact runtime used in production.

Quick Recap

Bestseller No. 1
PDF Converter Ultimate - Convert PDF files into Word, Excel, PowerPoint and others - PDF converter software with OCR recognition compatible with Windows 11 / 10 / 8.1 / 8 / 7
PDF Converter Ultimate - Convert PDF files into Word, Excel, PowerPoint and others - PDF converter software with OCR recognition compatible with Windows 11 / 10 / 8.1 / 8 / 7
Convert your PDF files into Word, Excel & Co. the easy way; Convert scanned documents thanks to our new 2022 OCR technology
Bestseller No. 2
Doxillion Free Document Converter – Converts DOCX, DOC, PDF, WPS and Many More Files Quickly [Download]
Doxillion Free Document Converter – Converts DOCX, DOC, PDF, WPS and Many More Files Quickly [Download]
Convert over 50 document file formats.; Preview your files from Doxillion before converting them.
Bestseller No. 3
PDF Extra Ultimate | Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Yearly License | 1 Windows PC & 2 Mobile Devices | 1 User
PDF Extra Ultimate | Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Yearly License | 1 Windows PC & 2 Mobile Devices | 1 User
READ and Comment PDFs – Intuitive reading modes & document commenting and mark up.; CREATE, COMBINE, SCAN and COMPRESS PDFs
$83.88
Bestseller No. 4
PDF Extra Lifetime - Professional PDF Editor - Best Adobe Acrobat Pro Alternative - Lifetime License for Windows PC
PDF Extra Lifetime - Professional PDF Editor - Best Adobe Acrobat Pro Alternative - Lifetime License for Windows PC
Perfect Adobe Acrobat Pro alternative – lifetime license for Windows 10 and 11.; EDIT text, images, pages, hyperlinks, designs in PDF documents. ORGANIZE PDFs.
$99.99
Bestseller No. 5
Doxillion Free Document Converter for Mac – Converts DOCX, DOC, PDF, WPS and Many More Files Quickly [Download]
Doxillion Free Document Converter for Mac – Converts DOCX, DOC, PDF, WPS and Many More Files Quickly [Download]
Convert over 50 document file formats.; Preview your files from Doxillion before converting them.

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.