The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
To generate a PDF, launch the Chromium binary provided by chrome-aws-lambda, navigate a Puppeteer page to your HTML or a URL, then call page.pdf(). The package supplies the Lambda-oriented browser launch setup; PDF generation itself is a Puppeteer Page API operation. Pair package versions deliberately, test the exact Lambda runtime and architecture you will deploy, and close the browser in a finally block.
What the implementation does
The package README demonstrates launching Chromium and opening a page; it does not itself create the PDF. Puppeteer’s Page.pdf() returns PDF data rendered using print CSS media. The code below combines those documented roles: chrome-aws-lambda provides launch arguments, viewport, executable path, and headless setting, while Puppeteer’s page API navigates and produces the PDF. See the chrome-aws-lambda README and Puppeteer Page.pdf() API.
This is an implementation pattern, not a verified drop-in deployment. The repository’s compatibility table is historical, so validate the installed package’s actual Puppeteer API and test the precise Node.js runtime, architecture, Chromium build, and integration response behavior you intend to use.
Recommended Free Tools
Install and verify a compatible package pair
Install chrome-aws-lambda alongside the corresponding puppeteer-core version (or Puppeteer version) as described by the package. Do not assume that the newest Puppeteer release works with the Chromium binary bundled by an older chrome-aws-lambda release. The repository’s visible compatibility table ends with Puppeteer 10.1, chrome-aws-lambda 10.1, and Chromium revision 92; it is not evidence of current Lambda-runtime compatibility.
#1 Best Overall
Before deployment, record the chosen package versions, confirm their documented relationship, build for the target Lambda Amazon Linux environment and architecture, and run an actual PDF capture in that target. AWS runtime identifiers and deprecation status change; consult the live AWS Lambda runtimes table for the runtime you plan to deploy. AWS warns that deprecated runtimes can lose patches and technical support.
Generate a PDF in a Lambda handler
This handler accepts an event containing a publicly reachable url and returns base64-encoded PDF data for an integration that supports binary responses. The response shape is not appropriate for every trigger; use S3 or another durable destination for larger files or where the caller cannot accept the response payload.
const chromium = require('chrome-aws-lambda');
exports.handler = async (event) => {
let browser;
try {
if (!event || typeof event.url !== 'string' || !event.url) {
return { statusCode: 400, body: 'A url is required' };
}
browser = await chromium.puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath,
headless: chromium.headless,
});
const page = await browser.newPage();
await page.goto(event.url, { waitUntil: 'networkidle2' });
const pdf = await page.pdf({
format: 'A4',
printBackground: true,
preferCSSPageSize: true,
});
return {
statusCode: 200,
headers: { 'content-type': 'application/pdf' },
body: Buffer.from(pdf).toString('base64'),
isBase64Encoded: true,
};
} finally {
if (browser) await browser.close();
}
};
The browser reference is kept outside the try so the finally block can close it after either a successful render or an exception. If page.goto() or page.pdf() fails, the function still reaches cleanup. A close failure can itself reject the invocation; in a production handler, decide how to log and report cleanup errors without hiding the original rendering error.
Render supplied HTML instead of a URL
For HTML passed in an event, create a page and call page.setContent(html) rather than page.goto(url). Do not print immediately if that HTML references external fonts, images, stylesheets, or scripts: ensure those resources have loaded and that any application-specific rendering has completed. If content is untrusted, treat it as an input-security boundary; rendering arbitrary HTML may cause the browser to request external resources.
Return bytes or persist the file
The example returns a base64 body for a binary-capable synchronous integration. Check that integration’s payload limits and encoding requirements before using this path. For larger PDFs, durable storage, or a download workflow, generate the PDF bytes, write them temporarily or upload them to S3, then return a reference that your application can authorize and serve. A community example illustrates a Lambda-to-S3-to-signed-URL flow, but it is not authoritative deployment guidance: community Chromium/Lambda example repository.
For an S3 upload, grant the Lambda execution role only the bucket and actions needed for the destination path. AWS’s general serverless file-processing tutorial demonstrates Lambda/S3 integration, but its example processes and encrypts existing PDFs; it does not establish Chromium rendering settings.
Choose print layout and page behavior
page.pdf() uses print CSS media by default and waits for fonts by default according to the Puppeteer API. That means output may differ from the page as viewed in a browser window: print-specific styles can hide navigation, change colors, or alter layout.
Free tools Windows power users keep installed
One-click scans. No signup required.
| Need | Setting or step | Effect |
|---|---|---|
| Paper size | format: 'A4' or another supported paper format |
Sets the PDF page format when CSS page sizing does not take precedence. |
Honor CSS @page dimensions |
preferCSSPageSize: true |
Lets CSS page size take priority over the API paper-size choice. |
| Landscape output | landscape: true |
Changes page orientation. |
| Margins | margin: { top, right, bottom, left } |
Sets PDF margins; choose units such as mm or in in the values. |
| Background colors and images | printBackground: true |
Includes printed backgrounds that may otherwise be omitted. |
| Selected pages | pageRanges: '1-3' |
Restricts output to the specified page ranges. |
| Save locally | path: '/tmp/output.pdf' |
Writes a file to the Lambda execution environment’s temporary storage. |
| Screen rather than print CSS | await page.emulateMediaType('screen') |
Uses screen media styles for PDF rendering instead of the default print media. |
Use the API options that match the document’s layout rather than relying on defaults. If exact colors matter, print styles may need -webkit-print-color-adjust. Puppeteer documents PDF behavior and options in its PDF generation guide and PDFOptions API; confirm details against the version actually paired with the Lambda browser.
Rank #3
Package and deploy for Lambda
The Chromium binary and Node dependencies must be available in a deployment artifact that matches Lambda’s execution environment and architecture. The project README documents a Lambda layer workflow; a deployment package, layer, or container can be used depending on your build and operational setup. Regardless of packaging method, test the artifact inside the target runtime rather than assuming a local development machine represents Lambda.
Memory, timeout, and concurrency
The project README gives 512 MB as a minimum memory recommendation and suggests 1600 MB or more. Treat those values as historical package guidance, not universal sizing for today’s workloads. Tune memory and timeout with representative pages, including the complexity of HTML, number of pages, image and font loading, and expected concurrency. A simple invoice and a multi-page report with many external assets can have very different requirements.
Set timeouts with enough room for browser startup, navigation, resource loading, PDF generation, and any upload. Under concurrency, account for the number of simultaneous browser processes and the memory each invocation consumes. No single timeout or memory value is established for every document or runtime.
Temporary files and durable output
Lambda’s /tmp ephemeral storage is configurable from 512 MB to 10,240 MB. Files there are temporary and tied to an execution environment, not durable storage; do not return a /tmp path as if it were a lasting download. Use it for transient extraction or an intermediate PDF when needed, then persist the file to S3 or another durable service. See AWS Lambda ephemeral storage documentation.
Keep the PDF in memory when the document is small and the invocation path can accept its bytes. Write it to /tmp when a file-based step is useful and space is sufficient. Upload to durable storage when the result must outlive the invocation, be retrieved later, or be shared through an access-controlled download path.
Handle page readiness and reliability
waitUntil: 'networkidle2' is a practical starting point for many pages, but it is not a guarantee that every application has finished rendering. A site with persistent network activity may never reach network idle, while a client-rendered page may become visually complete only after an application-specific selector or state appears. Select a readiness condition that matches the target page, and test pages with slow fonts, images, authentication, redirects, and dynamic content.
- For a URL that requires authentication, provide the required session or credentials using an approved mechanism; the sample does not implement authentication.
- For a page that needs a particular component, wait for that component before printing rather than treating network quiet as proof of visual readiness.
- For externally loaded assets, check the final rendered PDF for missing images, substituted fonts, or layout shifts.
- For failures, log enough context to identify the navigation or PDF stage without logging secrets embedded in URLs, cookies, or headers.
- Always close Chromium on success and failure so browser processes do not remain open for the invocation.
Troubleshooting common failures
| Symptom | Likely cause | What to check |
|---|---|---|
| Executable path or browser launch error | The binary was not extracted, packaged, or selected correctly for this runtime or architecture. | Confirm the deployed package/layer includes the compatible Chromium build; verify await chromium.executablePath resolves and that the artifact matches the Lambda target. |
| Missing module or incompatible Puppeteer method | The installed chrome-aws-lambda and Puppeteer versions do not form the documented pair. |
Inspect deployed dependency versions and use the package’s matching Puppeteer version; do not infer compatibility from a different local install. |
| Navigation timeout or invocation timeout | The URL is slow, keeps connections open, requires authentication, or has resource-heavy content; the Lambda timeout may be too short. | Identify whether failure occurs during navigation, waiting, PDF creation, or upload; adjust the readiness strategy and size timeout using representative pages. |
| Blank or incomplete PDF | The page printed before client-side rendering or external assets completed, or print CSS hides the expected content. | Wait for the application’s ready state, inspect print styles, and check external font/image loading in the generated output. |
| Backgrounds or colors are missing | Background printing is disabled or print color adjustment changes rendering. | Set printBackground: true and review CSS color-adjust rules. |
| Wrong paper dimensions or clipped content | CSS @page sizing, API format, margins, or orientation do not match. |
Set the desired format, margins, and orientation explicitly; decide whether CSS sizing should take precedence using preferCSSPageSize. |
| PDF exists only during invocation | The output was written to temporary storage. | Upload it to persistent storage such as S3 before returning, and return an authorized retrieval reference. |
| Large response rejected or unusable by caller | The trigger or front-end integration cannot carry the PDF as a base64 response of that size or does not interpret binary responses. | Check the integration’s response size and binary handling; store the file durably and return a retrieval mechanism instead. |
Or skip the browser setup
If your task is to capture an existing web page as a PDF rather than run your own Lambda-hosted Chromium, ScreenshotNeo offers a website screenshot API and MCP server. Its PDF endpoint can return a PDF from one GET request. The API can remove cookie/consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. AI agents can use its MCP server, and 1,000 screenshots per month are free with no card; paid plans start at $5 for 3,000 shots. This is a hosted capture alternative, not a replacement for custom in-Lambda document generation or private HTML rendering.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →For options and response details, see the ScreenshotNeo documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.pdf
Sign up for ScreenshotNeo to start with 1,000 free screenshots a month, with no card required.
Frequently Asked Questions
Does chrome-aws-lambda generate the PDF itself?
No. It supplies the Lambda-oriented Chromium launch setup; the PDF is created by Puppeteer’s page.pdf() method.
Can I use the same handler for any Lambda trigger?
The rendering approach can be adapted, but the sample’s base64 HTTP response is only suitable for integrations that support that response format and size. Other triggers can persist the output and return a reference.
Will a PDF always look like the page on screen?
No. PDF rendering uses print media by default, so print CSS can change what appears. Screen media can be selected explicitly before calling page.pdf().
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.

