Full Code of PSPDFKit-labs/pdfkit-invoice for AI

master 6ffaaa716f07 cached
5 files
6.1 KB
1.9k tokens
9 symbols
1 requests
Download .txt
Repository: PSPDFKit-labs/pdfkit-invoice
Branch: master
Commit: 6ffaaa716f07
Files: 5
Total size: 6.1 KB

Directory structure:
gitextract_6mxd5gs2/

├── .gitignore
├── README.md
├── createInvoice.js
├── index.js
└── package.json

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
node_modules
invoice.pdf


================================================
FILE: README.md
================================================
# PDFKit Invoices

<center>
  <a href="https://pspdfkit.com/web">
    <img src="./screenshot.png" alt="Screenshot of an invoice PDF in the PSPDFKit for Web reader." width="1009">
  </a>
</center>

## Prerequisites

- [Node.js](http://nodejs.org/) (with npm or Yarn)

## Getting Started

This repository is an example of how to make PDF invoices with PDFKit.

There are two important fields in this this repository:

- [`index.js`](index.js) is the main entry point. It defines the data structure used to create the invoices.
- [`createInvoice.js`](createInvoice.js) exports a function that can be used to create invoice PDFs.

To get started, use the following commands:

```bash
git clone https://github.com/PSPDFKit-labs/pdfkit-invoice.git

npm install  # Install dependencies

npm start  # This will create an invoice.pdf file in the root of the project.
```

To learn more about this project, make sure to read the accompanying [blog post](https://pspdfkit.com/blog/2019/generate-invoices-pdfkit-node)

## Contributing

Please ensure
[you have signed our CLA](https://pspdfkit.com/guides/web/current/miscellaneous/contributing/) so that we can
accept your contributions.


================================================
FILE: createInvoice.js
================================================
const fs = require("fs");
const PDFDocument = require("pdfkit");

function createInvoice(invoice, path) {
  let doc = new PDFDocument({ size: "A4", margin: 50 });

  generateHeader(doc);
  generateCustomerInformation(doc, invoice);
  generateInvoiceTable(doc, invoice);
  generateFooter(doc);

  doc.end();
  doc.pipe(fs.createWriteStream(path));
}

function generateHeader(doc) {
  doc
    .image("logo.png", 50, 45, { width: 50 })
    .fillColor("#444444")
    .fontSize(20)
    .text("ACME Inc.", 110, 57)
    .fontSize(10)
    .text("ACME Inc.", 200, 50, { align: "right" })
    .text("123 Main Street", 200, 65, { align: "right" })
    .text("New York, NY, 10025", 200, 80, { align: "right" })
    .moveDown();
}

function generateCustomerInformation(doc, invoice) {
  doc
    .fillColor("#444444")
    .fontSize(20)
    .text("Invoice", 50, 160);

  generateHr(doc, 185);

  const customerInformationTop = 200;

  doc
    .fontSize(10)
    .text("Invoice Number:", 50, customerInformationTop)
    .font("Helvetica-Bold")
    .text(invoice.invoice_nr, 150, customerInformationTop)
    .font("Helvetica")
    .text("Invoice Date:", 50, customerInformationTop + 15)
    .text(formatDate(new Date()), 150, customerInformationTop + 15)
    .text("Balance Due:", 50, customerInformationTop + 30)
    .text(
      formatCurrency(invoice.subtotal - invoice.paid),
      150,
      customerInformationTop + 30
    )

    .font("Helvetica-Bold")
    .text(invoice.shipping.name, 300, customerInformationTop)
    .font("Helvetica")
    .text(invoice.shipping.address, 300, customerInformationTop + 15)
    .text(
      invoice.shipping.city +
        ", " +
        invoice.shipping.state +
        ", " +
        invoice.shipping.country,
      300,
      customerInformationTop + 30
    )
    .moveDown();

  generateHr(doc, 252);
}

function generateInvoiceTable(doc, invoice) {
  let i;
  const invoiceTableTop = 330;

  doc.font("Helvetica-Bold");
  generateTableRow(
    doc,
    invoiceTableTop,
    "Item",
    "Description",
    "Unit Cost",
    "Quantity",
    "Line Total"
  );
  generateHr(doc, invoiceTableTop + 20);
  doc.font("Helvetica");

  for (i = 0; i < invoice.items.length; i++) {
    const item = invoice.items[i];
    const position = invoiceTableTop + (i + 1) * 30;
    generateTableRow(
      doc,
      position,
      item.item,
      item.description,
      formatCurrency(item.amount / item.quantity),
      item.quantity,
      formatCurrency(item.amount)
    );

    generateHr(doc, position + 20);
  }

  const subtotalPosition = invoiceTableTop + (i + 1) * 30;
  generateTableRow(
    doc,
    subtotalPosition,
    "",
    "",
    "Subtotal",
    "",
    formatCurrency(invoice.subtotal)
  );

  const paidToDatePosition = subtotalPosition + 20;
  generateTableRow(
    doc,
    paidToDatePosition,
    "",
    "",
    "Paid To Date",
    "",
    formatCurrency(invoice.paid)
  );

  const duePosition = paidToDatePosition + 25;
  doc.font("Helvetica-Bold");
  generateTableRow(
    doc,
    duePosition,
    "",
    "",
    "Balance Due",
    "",
    formatCurrency(invoice.subtotal - invoice.paid)
  );
  doc.font("Helvetica");
}

function generateFooter(doc) {
  doc
    .fontSize(10)
    .text(
      "Payment is due within 15 days. Thank you for your business.",
      50,
      780,
      { align: "center", width: 500 }
    );
}

function generateTableRow(
  doc,
  y,
  item,
  description,
  unitCost,
  quantity,
  lineTotal
) {
  doc
    .fontSize(10)
    .text(item, 50, y)
    .text(description, 150, y)
    .text(unitCost, 280, y, { width: 90, align: "right" })
    .text(quantity, 370, y, { width: 90, align: "right" })
    .text(lineTotal, 0, y, { align: "right" });
}

function generateHr(doc, y) {
  doc
    .strokeColor("#aaaaaa")
    .lineWidth(1)
    .moveTo(50, y)
    .lineTo(550, y)
    .stroke();
}

function formatCurrency(cents) {
  return "$" + (cents / 100).toFixed(2);
}

function formatDate(date) {
  const day = date.getDate();
  const month = date.getMonth() + 1;
  const year = date.getFullYear();

  return year + "/" + month + "/" + day;
}

module.exports = {
  createInvoice
};


================================================
FILE: index.js
================================================
const { createInvoice } = require("./createInvoice.js");

const invoice = {
  shipping: {
    name: "John Doe",
    address: "1234 Main Street",
    city: "San Francisco",
    state: "CA",
    country: "US",
    postal_code: 94111
  },
  items: [
    {
      item: "TC 100",
      description: "Toner Cartridge",
      quantity: 2,
      amount: 6000
    },
    {
      item: "USB_EXT",
      description: "USB Cable Extender",
      quantity: 1,
      amount: 2000
    }
  ],
  subtotal: 8000,
  paid: 0,
  invoice_nr: 1234
};

createInvoice(invoice, "invoice.pdf");


================================================
FILE: package.json
================================================
{
  "name": "pdfkit-invoice",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "pdfkit": "^0.13.0"
  }
}
Download .txt
gitextract_6mxd5gs2/

├── .gitignore
├── README.md
├── createInvoice.js
├── index.js
└── package.json
Download .txt
SYMBOL INDEX (9 symbols across 1 files)

FILE: createInvoice.js
  function createInvoice (line 4) | function createInvoice(invoice, path) {
  function generateHeader (line 16) | function generateHeader(doc) {
  function generateCustomerInformation (line 29) | function generateCustomerInformation(doc, invoice) {
  function generateInvoiceTable (line 72) | function generateInvoiceTable(doc, invoice) {
  function generateFooter (line 141) | function generateFooter(doc) {
  function generateTableRow (line 152) | function generateTableRow(
  function generateHr (line 170) | function generateHr(doc, y) {
  function formatCurrency (line 179) | function formatCurrency(cents) {
  function formatDate (line 183) | function formatDate(date) {
Condensed preview — 5 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (7K chars).
[
  {
    "path": ".gitignore",
    "chars": 25,
    "preview": "node_modules\ninvoice.pdf\n"
  },
  {
    "path": "README.md",
    "chars": 1175,
    "preview": "# PDFKit Invoices\n\n<center>\n  <a href=\"https://pspdfkit.com/web\">\n    <img src=\"./screenshot.png\" alt=\"Screenshot of an "
  },
  {
    "path": "createInvoice.js",
    "chars": 4145,
    "preview": "const fs = require(\"fs\");\nconst PDFDocument = require(\"pdfkit\");\n\nfunction createInvoice(invoice, path) {\n  let doc = ne"
  },
  {
    "path": "index.js",
    "chars": 568,
    "preview": "const { createInvoice } = require(\"./createInvoice.js\");\n\nconst invoice = {\n  shipping: {\n    name: \"John Doe\",\n    addr"
  },
  {
    "path": "package.json",
    "chars": 307,
    "preview": "{\n  \"name\": \"pdfkit-invoice\",\n  \"version\": \"1.0.0\",\n  \"description\": \"\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"start"
  }
]

About this extraction

This page contains the full source code of the PSPDFKit-labs/pdfkit-invoice GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 5 files (6.1 KB), approximately 1.9k tokens, and a symbol index with 9 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!