visionvalt-receipt-generator
v1.1.7
Published
A package to generate receipt PDFs
Downloads
24
Maintainers
Readme
Receipt PDF Generator
Overview
The Receipt PDF Generator is a Node.js module that creates a professional PDF receipt based on provided receipt data. This module utilizes the pdfkit
library to generate the receipt PDF file.
Usage
To use the Receipt PDF Generator, follow these steps:
Import the Module: Import the
generatePDFFile
function from the module into your script.Prepare Receipt Data: Define the receipt data object with all necessary fields.
Call the Function: Call the
generatePDFFile
function with the receipt data and the desired output file path.
Function Details
generatePDFFile(receiptData, outputFilePath)
Parameters:
receiptData: An object containing all necessary receipt information. outputFilePath: The file path where the PDF will be saved. Returns: The file path where the PDF has been saved.
Receipt Data Object The receiptData object should include the following properties:
date: Date of the receipt (e.g., '2024-08-17'). planName: Name of the plan or service. originalPrice: The original price before GST. logoPath: Path to the logo image. contactEmail: Contact email for support. contactMobile: Contact mobile number for support. invoiceID: Unique invoice identifier. items: Array of items with descriptions and amounts. billingPerson: Object with billing person's details (name, address, city, state, zip, country). paymentMethod: Method used for payment (e.g., 'Credit Card'). transactionID: Transaction identifier. additionalNotes: Additional notes about the transaction. gstRate: GST rate as a decimal (e.g., 0.18 for 18%).
Example Code
Here's a sample usage of the Receipt PDF Generator:
const { generatePDFFile } = require('./path/to/your/module');
const path = require('path');
// Define the receipt data
const receiptData = {
date: '2024-08-17',
planName: 'Premium Plan',
originalPrice: 100.00,
logoPath: 'assets/logo.png',
contactEmail: '[email protected]',
contactMobile: '+1234567890',
invoiceID: 'INV-2024-0001',
items: [
{ description: 'Service Fee', amount: 50.00 },
{ description: 'Additional Charges', amount: 10.00 }
],
billingPerson: {
name: 'John Doe',
address: '123 Elm Street',
city: 'Springfield',
state: 'IL',
zip: '62701',
country: 'USA'
},
paymentMethod: 'Credit Card',
transactionID: 'TRX-2024-123456',
additionalNotes: 'Payment was processed successfully.',
gstRate: 0.18 // GST rate as a decimal (18% GST)
};
// Define the path where the PDF will be saved
const outputFilePath = path.join(__dirname, 'custom_receipt_path.pdf');
// Generate the PDF file
generatePDFFile(receiptData, outputFilePath);
License
This project is licensed under the MIT License. See the LICENSE file for details.