Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pdfeasy

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pdfeasy

Client/Server Side PDF-Creator based in PDFKit

  • 0.3.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

PDFEasy

Client/Server Side PDF-Generator based in PDFKit



  • ✅ Client/Server Side Support
  • ✅ Write in Typescript
  • ✅ Builded with ESBuild and requests with OhMyFetch
  • ✅ Browser STDLib
  • ✅ Custom Fonts && Purge Unused Fonts
  • ✅ Plugins Ready!

Installation

It's simple!

NPM

npm i pdfeasy

YARN

yarn add pdfeasy

PNPM

pnpm add pdfeasy

Simple Example

import pdfeasy, { Utils } from 'pdfeasy'
// import pdfeasy, { Utils } from 'pdfeasy/dist/client.cjs.js'
// import pdfeasy, { Utils } from 'pdfeasy/dist/node.esm.js'
// import pdfeasy, { Utils } from 'pdfeasy/dist/node.cjs.js'

pdfeasy.new({
  document: { // PDFKit options
    margins: {
      top: 40,
      bottom: 40,
      left: 80,
      right: 80
    }
  },
  plugins: [ // Plugins!
    {
      page: [ // render callback in every page AFTER finish contents insert. Not support before at this time.
        // simple counter footer
        ({ Text, Image }, context, current, total) => {
          // render in every page
          Text(`${current}/${total}`, { fontSize: 20 }, {
            x: context.width / 2,
            y: context.height - context.margins.bottom
          })

          // Image('https://i.imgur.com/to/path.png', {}, {})
        },
        // simple header
        ({ Text }, context, current, total) => {
          // render in every page
          Text('A Simple Header', {}, {
            x: context.width / 2,
            // negative number (-30 in case) ignore default margins
            y: context.margins.top - 20
          })
        }
      ]
    }
  ]
})

pdfeasy.add([
  ...Utils.content(), // Utils for debug
  { raw: 'Hello PDFEasy!', text: { font: 'Roboto' }}, // custom font,
  { raw: 'https://i.imgur.com/path.png', image: {}}, // external image
  { stack: [ // stack for paragraph's
    { raw: 'A ', text: {}},
    { raw: 'Simple', text: { bold: true, italic: true }},
    { raw: ' Stack!', text: {}},
  ]},
  // not recommended use this
  { raw: 'Text without option!' },
])

// or https://path/to/Roboto.ttf
pdfeasy.addFonts([
  {
    name: 'Roboto',
    normal: 'fonts/Roboto-Regular.ttf',
    bold: 'fonts/Roboto-Medium.ttf',
    italic: 'fonts/Roboto-Italic.ttf',
    bolditalic: 'fonts/Roboto-BoldItalic.ttf'
  }
])

pdfeasy.run().then((blob: string) => {
  const iframe = document.querySelector('#pdf') as HTMLIFrameElement

  iframe.src = blob
}).catch((err: any) => {
  console.error(err)
})

See source demo for more explanations

See examples for .pdf results.

See scripts for server-side runner.

Bundles

Uses standard minification

pdfeasy/dist/client.cjs.js

pdfeasy/dist/client.esm.js

pdfeasy/dist/node.cjs.js

pdfeasy/dist/node.esm.js

pdfeasy/dist/node.iife.js

pdfeasy/dist/index.d.ts

Keywords

FAQs

Package last updated on 05 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc