Skip to main content

savePDF

Overview

Use the savePDF command to save the current browser context to a PDF file.

Usage

await browser.savePDF(filepath, {
orientation,
scale,
background,
width,
height,
top,
bottom,
left,
right,
shrinkToFit,
pageRanges,
});

Command Parameters

NameTypeDescription
filepathStringPath to the PDF file relative to the execution directory (the .pdf extension is mandatory).
orientationStringOrientation of the PDF page.
scaleNumberScale of the PDF page.
backgroundBooleanInclude the background in the PDF.
widthNumberWidth of the PDF page.
heightNumberHeight of the PDF page.
topNumberTop margin of the PDF page.
bottomNumberBottom margin of the PDF page.
leftNumberLeft margin of the PDF page.
rightNumberRight margin of the PDF page.
shrinkToFitNumberShrink the page to fit the PDF page size.
pageRangesObject[]Range of pages to include in the PDF.

Usage Examples

it("should save a PDF screenshot of the browser view", async ({ browser }) => {
await browser.savePDF("./some/path/screenshot.pdf");
});

References

We'd like to give credit to the original WebdriverIO docs article, from which we drew some information while writing our version.