npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

transaction-pdf-generator

v0.0.3

Published

Generates invoice and receipt PDFs for transaction records.

Downloads

12

Readme

transaction-pdf-generator

Generates invoice and receipt PDFs for transaction records.

Installation

npm install transaction-pdf-generator

or

yarn add transaction-pdf-generator

Usage

Generate an empty invoice:

import { generateTransactionPdf } from 'transaction-pdf-generator'
import { writeFileSync } from 'fs'

const writeEmptyInvoicePdf = async () => {
    const pdfBuffer = await generateTransactionPdf()
    writeFileSync('empty-invoice.pdf', pdfBuffer)
}

writeEmptyInvoicePdf().catch(err => console.error(err))

// An empty-invoice.pdf file should be found in the current working directory.

Generate an invoice using all the available options:

import { generateTransactionPdf, TransactionPdfType} from 'transaction-pdf-generator'
import { writeFileSync } from 'fs'

const writeReceiptPdfUsingAllOptions = async () => {
    const pdfBuffer = await generateTransactionPdf({

        // See how a default can be included here:
        // https://pdfmake.github.io/docs/getting-started/server-side/
        fontDescriptors: {
            Times: {
                normal: 'Times-Roman',
                bold: 'Times-Bold',
                italics: 'Times-Italic',
                bolditalics: 'Times-BoldItalic',
            }
        },

        // This uses the image and fit properties as described here:
        // https://pdfmake.github.io/docs/document-definition-object/images/
        logo: {
            image: 'test/test-logo.png',
            fit: [118, 67],
        },
        companyDetails: `Example Company Name
Examplestreet 111 - 12345 Town
[email protected]`,
        customerAddress: `Dr Robin Exampleperson
Exampleperson's Business Name
Example Street 123 Unit 1A
Exampletown Examplestate 54321
Mycountry`,
        customerTaxId: 'BIZ123456789',

        // E.g. VAT number
        customerTaxIdType: 'Customer Sales Tax Id: ',

        // How the document is identified in your systems
        transactionId: '20010101001',
        transactionDate: (new Date).toLocaleDateString(),
        transactionPdfType: TransactionPdfType.Receipt,

        // paidDate is only shown if the transaction type is Receipt.
        paidDate: (new Date).toLocaleDateString(),
        taxRate: 0.1,

        // E.g. VAT, GST, or Sales Tax
        taxType: 'Generic Sales Tax',
        items: [
            {
                quantity: 2,
                description: 'Example service/product description 1',
                date: (new Date).toLocaleDateString(),
                unitPrice: 100,
            },
            {
                quantity: 1,
                description: 'Example service/product description 2',
                date: (new Date).toLocaleDateString(),
                unitPrice: 500,
            },
            {
                quantity: 1,
                description: 'Example service/product description 3',
                date: (new Date).toLocaleDateString(),
                unitPrice: 400,
            }
        ],
        currency: 'EUR',
        decimalPlaces: 2,
        paymentMethods: [
            {
                name: 'Bank transfer',
                details: `IBAN: XX11 1111 1111 1111 1111 11
Bank: Example Bank
Description: Example Description
Recipient: Example Company Name`,
            }
        ],
        supportText: [
            'Send us an email: ',
            {
                text: '[email protected]',
                link: 'mailto:[email protected]?subject=billing',
            },
            '.'
        ],
        thankYouText: 'Thank you for your business!',
        footerText: `Commercial registery: XXX 111111, Location
Directors: Person One, Person Two
Sales Tax Id: XX 111 111 111`
    })
    writeFileSync('all-options-receipt.pdf', pdfBuffer)
}

writeReceiptPdfUsingAllOptions().catch(err => console.error(err))