1.0.4 • Published 5 years ago

@danacita/documentassembly v1.0.4

Weekly downloads
4
License
MIT
Repository
gitlab
Last release
5 years ago

Getting Started

Install the module with:

npm i @danacita/documentassembly --save

Import the module

const DocumentAssembly = require('@danacita/documentassembly');

Create the data for the PDF or HTML based on the EJS template

// Args are dependent on the provided EJS template
const args = {
    date: '15-Februari-2020',
    borrowerFullName: 'goal',
    institution: 'Trisakti University',
    yearGraduate: '2020',
    guarantorFullName: 'Daniel',
    guarantorFamilyRelationship: 'son',
    loanAmount: '4.000.000',
    disbursementDate: '12-June-2019',
    disbursementTotal: '500.000',
    installmentPerMonth: '121.000',
    flatInterestPerMonth: '1.12',
    flatInterestPerYear: '17.1',
    tenor: '12',
    firstInstallmentPaymentDue: 'August 2019',
    lastInstallmentPaymentDue: 'September 2021'
};

Call the create function to generate the PDF file

(async () => {
    const pdfBuffer = await DocumentAssembly.create(
        {...args},
        './template.ejs', // The file path to your EJS template
        './demofile.pdf', // A PDF file will be generated to this file path
        'pdf' // The type of output that you want the DocumentAssembly to generate. It should be either 'pdf' or 'html'
    );
    console.log(pdfBuffer);
})(); // After the execution of the previous function, demofile.pdf should be generated at this file path './demofile.pdf

Call the create function to generate the HTML file

(async () => {
    const pdfBuffer = await DocumentAssembly.create(
        {...args},
        './template.ejs', // The file path to your EJS template (The template must be a EJS template)
        './demofile.html', // A HTML file will be generated to this file path
        'html' // The type of output that you want the DocumentAssembly to generate. It should be either'pdf' or 'html'
    );
    console.log(pdfBuffer);
})(); // After the execution of the previous function, demofile.html should be generated at this file path './demofile.html

Documentation

+ create: (args: Object, templateFilePath: string, outputFilePath: string, outputFormat: string) => Promise;

note: 1. You must write a full file path, including writing the file name of the new PDF or the new HTML. 2. The return type of this function are dependent on the outputFormat. "pdf" returns a PDF buffers, while "html returns a plain html text 3. The outputFormat should be either 'pdf' or 'html'