How to Convert a Webpage to PDF with LambdaTest
LambdaTest is a browser testing platform; the reviewed docs don’t establish a direct PDF export. Use browser Print for one-off saves or Playwright and Chrome Headless for automation.
Short answer: The reviewed LambdaTest product pages describe browser testing; they do not establish a built-in webpage-to-PDF export feature. For a one-off save, open the page in a browser and choose Save as PDF from Print. For repeatable conversion, use Playwright’s page.pdf() or Chrome Headless’s --print-to-pdf. LambdaTest can be useful for inspecting how a page renders in a remote browser; use a PDF method supported by your browser or automation setup.
1. Choose the right method
| Need | Use | What it provides |
|---|---|---|
| Save one page occasionally | Browser Print | A manual Save as PDF workflow with little setup. |
| Generate PDFs repeatedly in a script | Playwright | Programmatic control of print CSS, paper, margins, backgrounds and page ranges. |
| Run a simple headless command | Chrome Headless | Chrome’s --print-to-pdf flag and a capture timeout option. |
| Inspect rendering in a remote browser | LambdaTest, if your workflow uses it | Browser testing context. Confirm current product capabilities; the reviewed pages do not document a specific PDF export button. |
2. Save a webpage as PDF manually
- Open the webpage in a desktop browser and wait for the content you need to appear.
- Open the browser’s Print dialog.
- Choose Save as PDF as the destination or printer.
- Review the preview, including page breaks, orientation, margins, and background graphics if offered.
- Save the file and open it to check that important content was not clipped or omitted.
Browser menus and print settings vary by browser and version. The reviewed LambdaTest sources do not document a LambdaTest-specific PDF export control.
3. Automate conversion with Playwright
Install Playwright and its browser runtime using the instructions for your project in the official Playwright getting started guide. The following runnable Node.js example navigates to a page, waits for it to load, and writes a PDF:
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch({ headless: true });
const page = await browser.newPage();
try {
await page.goto('https://example.com', { waitUntil: 'networkidle', timeout: 60000 });
await page.pdf({
path: 'page.pdf',
format: 'A4',
printBackground: true,
margin: { top: '12mm', right: '12mm', bottom: '12mm', left: '12mm' }
});
} finally {
await browser.close();
}
})();
Playwright documents that page.pdf() generates a PDF using print CSS media. If the page should retain its screen styling, emulate screen media before calling pdf():
await page.emulateMedia({ media: 'screen' });
await page.pdf({ path: 'page.pdf', printBackground: true });
Choose one media mode deliberately. Print styles may hide navigation, change layout, or restyle content; screen media may preserve a screen layout that paginates poorly.
Playwright PDF options to tune
| Option | Use | Notes |
|---|---|---|
format |
Named paper size such as A4 or Letter | Use this when standard paper dimensions are desired. |
width, height |
Custom page dimensions | Use when the output needs a nonstandard page size. |
margin |
Set top, right, bottom, and left margins | Adjust for readability and printable area. |
printBackground |
Include background graphics and colors | Defaults to false; enable when backgrounds are part of the document. |
preferCSSPageSize |
Honor CSS @page sizing |
Use when the page’s print stylesheet defines the intended paper size. |
scale |
Scale page content | Adjust carefully; scaling can make text too small. |
pageRanges |
Export selected pages | Useful for extracting a subset of a longer document. |
landscape |
Set landscape orientation | Use for wide tables or layouts. |
displayHeaderFooter, headerTemplate, footerTemplate |
Add print header and footer templates | Template scripts are not evaluated, and page styles do not apply inside templates. |
For exact print colors, CSS can use -webkit-print-color-adjust: exact. Preview the PDF after changing color handling because print and screen color output can differ.
4. Automate conversion with Chrome Headless
Chrome documents the --print-to-pdf flag for saving a page as PDF. A basic command is:
chrome --headless --print-to-pdf=page.pdf https://example.com
Chrome’s headless documentation also describes --no-pdf-header-footer to omit the default header and footer, and --timeout to wait before capture. For example:
chrome --headless --timeout=5000 --no-pdf-header-footer --print-to-pdf=page.pdf https://example.com
The timeout gives a page extra time before capture; it does not guarantee that every application’s asynchronous content has finished. Check the output when pages load data or images dynamically.
5. Use LambdaTest in a PDF workflow
LambdaTest’s reviewed pages describe browser testing. That can fit a workflow where you need to inspect a page’s rendering in a browser environment, but the research does not establish a direct PDF export feature. Once you know which browser rendering you need, generate the PDF with the browser’s print function or an automation tool such as Playwright or Chrome Headless. Verify current LambdaTest capabilities before relying on a direct export feature.
6. Handle print layout and dynamic content
- Wait for meaningful content: A navigation event alone may not mean application data, lazy images, or fonts are ready. Wait for a known selector or application state in your automation when possible.
- Inspect print CSS: Print media can intentionally remove menus, change columns, or insert page breaks. Review the PDF, not just the browser viewport.
- Check long pages: PDFs paginate to paper dimensions. This differs from a full-page screenshot; tables, code blocks, and cards may split across pages.
- Choose page dimensions intentionally: Set A4/Letter or custom width and height, then adjust margins, orientation, and scale.
- Validate colors and backgrounds: Playwright omits print backgrounds by default. Enable them when needed and use print color adjustment CSS if exact colors matter.
- Handle authentication and restricted pages: A browser session may need the same cookies or credentials as a real user. Avoid placing secrets in shell history or source control.
7. Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Navigation or layout disappears | The page has print-specific CSS, and Playwright uses print media by default. | Inspect print styles; use page.emulateMedia({ media: 'screen' }) if screen appearance is the goal. |
| Backgrounds or colors are missing | printBackground defaults to false, or print color adjustment changes colors. |
Set printBackground: true; consider -webkit-print-color-adjust: exact in the page CSS. |
| Content is clipped or too small | Paper dimensions, margins, scale, or orientation do not fit the layout. | Try landscape, a suitable format or custom dimensions, smaller margins, or a modest scale adjustment. Inspect readability. |
| Some content is absent | Dynamic requests, lazy content, or fonts had not completed before capture. | Wait for a relevant selector or app-ready signal, increase the capture wait where appropriate, and inspect the saved PDF. |
| Unexpected header/footer appears | Default browser PDF headers and footers are enabled. | Use Playwright header/footer options as needed or Chrome’s documented --no-pdf-header-footer flag. |
| Page breaks split important content | Print pagination differs from the screen layout. | Adjust print CSS and page dimensions; review tables, images, and long code blocks across page boundaries. |
| Chrome command cannot start | The executable name or browser installation differs on the machine. | Run the installed Chrome/Chromium executable by its configured path and confirm headless support for that installation. |
8. Performance, reliability, and cost
Manual printing has minimal automation setup but requires a person for each save. Playwright and Chrome Headless require a browser runtime and script or command setup; their documentation here does not provide comparative speed benchmarks, so measure your own pages and workload. Dynamic pages can make capture time variable. Use a bounded timeout, wait for the content that matters, and handle failures so a stalled page does not block a batch indefinitely.
PDF size and generation time depend on the page, images, fonts, and print layout. If output matters operationally, retain error logs and inspect representative files, especially after site changes. The research dossier provides no pricing or performance figures for LambdaTest or these browser methods, so no cost or speed claims are made.
9. Or skip the browser setup
ScreenshotNeo is a website screenshot API and MCP server. Its PDF option can return a PDF through one API request. See the ScreenshotNeo API documentation for request options.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -d format=pdf -o page.pdf
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com", "format": "pdf"},
timeout=90,
)
r.raise_for_status()
open("page.pdf", "wb").write(r.content)
const q = new URLSearchParams({
access_key: 'YOUR_API_KEY',
url: 'https://stripe.com',
format: 'pdf'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`ScreenshotNeo returned HTTP ${res.status}`);
await require('node:fs/promises').writeFile('page.pdf', Buffer.from(await res.arrayBuffer()));
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. Learn more at ScreenshotNeo.
Create a free account for 1,000 screenshots a month, with no card required.
10. Frequently asked questions
Can LambdaTest save a webpage directly as a PDF?
The reviewed LambdaTest pages do not establish a direct PDF export feature. Confirm current product capabilities if you need a LambdaTest-specific workflow.
Does Playwright print the screen view by default?
No. page.pdf() uses print CSS media by default. Emulate screen media first when that is the intended styling.
Is a webpage PDF the same as a full-page screenshot?
No. A PDF is laid out and paginated for paper dimensions, while a full-page screenshot is an image capture of page content.
Which method should I start with?
Use browser Print for a one-off save, and Playwright or Chrome Headless when the conversion must run repeatedly without manual steps.


