1.1.0 • Published 8 years ago

ion2-pdf v1.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
8 years ago

Ionic 2 Helper Extension

This is a ionic 2 extension for pdf

Installation

Install package:

npm install ion2-pdf --save

Copy contents of vendors folder to the app www/js folder

Update index.html with:

<!-- PDFMake  -->
<script src='js/pdfmake.min.js'></script>
<script src='js/vfs_fonts.js'></script>

Usage

Generate a invoice like document:

const genOpts = { fonts: Pdf.getFonts() };
const docOpts = {
  base: Pdf.getBase(),
  title: Pdf.getTitle('TAX INVOICE'),
  tenant: Pdf.getTenant(tenant),
  info: Pdf.getInfo(
    `${model.billingAttentionTo}\n\nAttention: ${model.billingAttentionTo}`,
    [
      { text: 'Invoice No:\nInvoice Date:\nTerms:' },
      { text: `${model.invoiceCode}\n${model.invoiceDate}\n${model.invoiceTerm}` }
    ]
  ),
  standardTable: Pdf.getStandardTable(
    [
      { text: 'Description of professional services rendered', style: ['tableHeader', 'fill-gray']},
      { text: 'Disbursement', style: ['center', 'tableHeader', 'fill-gray']},
      { text: 'Fee', style: ['center', 'tableHeader', 'fill-gray']},
    ],
    R.map(n => { return [
        { text: n.name },
        { text: (n.isDisbursement) ? Formatter.getCurrency(n.amount) : '', style: 'right' },
        { text: (!n.isDisbursement) ? Formatter.getCurrency(n.amount) : '', style: 'right' }
      ]}, model.sales)
  ),
  subtotalTable: Pdf.getSubtotalTable([
    { text: Formatter.getCurrency(R.reduce(
        (acc, value) => acc + ((value.isDisbursement) ? value.amount : 0), 0, model.sales)),
      style: ['right']},
    { text: Formatter.getCurrency(R.reduce(
        (acc, value) => acc + ((!value.isDisbursement) ? value.amount : 0), 0, model.sales)),
      style: ['right']},
  ]),
  summaryTable: Pdf.getSummaryTable([
    [
      { text: 'Total before GST', style: ['right']},
      { text: Formatter.getCurrency(model.beforeTaxAmount), style: ['right'] }
    ],
    [
      { text: 'Add GST at 7%', style: ['right']},
      { text: Formatter.getCurrency(model.taxAmount), style: ['right'] }
    ],
    [
      { text: 'Total after GST', style: ['right']},
      { text: Formatter.getCurrency(model.afterTaxAmount), style: ['right'] }
    ],
  ]),
  footer: Pdf.getFooter(model.invoiceFooter),
}
Pdf.open(docOpts, genOpts);