@raminjafary/sura
TypeScript icon, indicating that this package has built-in type declarations

0.1.8 • Public • Published

Sura

npm (scoped with tag)

Generate PDF or screenshot with Node and Playwright.

Installation

npm i @raminjafary/sura
# or
yarn add @raminjafary/sura

Features

  • Generate PDF
  • Take screenshot
  • Support Sass/Scss

Usage

Generate PDF

It returns the data buffer and the fsPath of the generated file if pdf.path is specefied.

import { generateFile } from 'sura'

const { data, fsPath } = await generateFile({
      type: 'pdf',
      htmlPath: 'path/to/html/file',
      stylePath: path.join(
        __dirname,
        'public',
        'assets',
        'style.scss'
      ),
      pageLoad: {
        waitUntil: 'networkidle',
      },
      pdf: {
        path: 'path/to/save/file.pdf',
        format: 'A4',
        printBackground: false,
      },
    })

Take screenshot

It returns the data in base64 and the fsPath of the generated file if screenshot.path is specefied.

import { generateFile } from 'sura'

const { data, fsPath } = await generateFile({
      type: 'screenshot',
      htmlPath: 'path/to/html/file',
      pageLoad: {
        waitUntil: 'networkidle',
      },
      screenshot: {
        path: 'path/to/save/image.png',
        fullPage: true,
      },
    })

Options

Option Default Description
type pdf File type to be generated
htmlPath undefined Directory or path of html file
stylePath undefined Directory or path of style file
pdf see Playwright page.pdf PDF options
screenshot see Playwright page.screenshot Screenshot options
pageLoad see Playwright page.goto Options for URL to navigate page to

Development

  • Clone this repository.
  • Install dependencies using yarn install or npm install.
  • Start development server using npm run dev or yarn dev.

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i @raminjafary/sura

Weekly Downloads

6

Version

0.1.8

License

MIT

Unpacked Size

10.7 kB

Total Files

7

Last publish

Collaborators

  • raminjafary