MCPcopy Create free account
hub / github.com/webdriverio/webdriverio / savePDF

Function savePDF

packages/webdriverio/src/node/savePDF.ts:23–45  ·  view source on GitHub ↗
(
    this: WebdriverIO.Browser,
    filepath: string,
    options?: PDFPrintOptions
)

Source from the content-addressed store, hash-verified

21 * Command implementation of the `savePDF` command.
22 */
23export async function savePDF (
24 this: WebdriverIO.Browser,
25 filepath: string,
26 options?: PDFPrintOptions
27) {
28 /**
29 * type check
30 */
31 if (typeof filepath !== 'string' || !filepath.endsWith('.pdf')) {
32 throw new Error('savePDF expects a filepath of type string and ".pdf" file ending')
33 }
34
35 const absoluteFilepath = path.resolve(filepath)
36 await assertDirectoryExists(absoluteFilepath)
37
38 const pdf = await this.printPage(options?.orientation, options?.scale, options?.background,
39 options?.width, options?.height, options?.top, options?.bottom, options?.left, options?.right,
40 options?.shrinkToFit, options?.pageRanges)
41 const page = Buffer.from(pdf, 'base64')
42 fs.writeFileSync(absoluteFilepath, page)
43
44 return page
45}

Callers

nothing calls this directly

Calls 1

assertDirectoryExistsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…