0.1.8 • Published 3 years ago

@raminjafary/sura v0.1.8

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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

OptionDefaultDescription
typepdfFile type to be generated
htmlPathundefinedDirectory or path of html file
stylePathundefinedDirectory or path of style file
pdfsee Playwright page.pdfPDF options
screenshotsee Playwright page.screenshotScreenshot options
pageLoadsee Playwright page.gotoOptions 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

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.4

3 years ago

0.1.5

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago