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

cfdi2pdf

v2.1.4

Published

Convert CFDI xml file to pdf

Downloads

38

Readme

cfdi2pdf

version 2.0.0

cdfi2pdf creates a pdf based on an XML CFDI. It uses pdfmake and xml2js as dependencies.

Preface

Electronic invoices in Mexico are generated using XML files, this files contains all data of the transactions. The XML files are sent over email or downloaded and many times they are accompanied with the corresponding PDF file with the same information, so it is easy to print and to be sent by email to the receiver. We decided to make this module because we needed for our platform, so we can send and store the PDF representation of the electronic invoices generated. This implementation is specially designed to generate PDF from the CFDI 3.3 version as specified by the SAT (Mexican Government), as for Jan 2018 onwards. It may not be compatible with previous or future realeases, but we hope you might find it useful. Contributions are welcomed, please send us an email to <info @ quad-tree.com>

The default image in the example file is a Base64 string representation of a PNG file, and it should be replaced by the logo of the company that generates the XML.

How to install

1.- Make a directory:

$ mkdir cfditest
$ cd cfditest

2.- Install from NPM

$ npm install --save cfdi2pdf

Creating a PDF client side

You need to pass an XML string to the method in order to get the PDF document.

const cfdi2pdf = require("cfdi2pdf");
cfdi2pdf.createPDFClient(xml);

Creating a PDF server side

In order to use the module server side, you need to have the fonts to be used in your public folder.

You need to pass an XML string, the response (where the pdf will be sent), and the fonts as options in order to get the PDF document.

You can also send a base64 image as part of the options in order to be used as the logo of the company.

Here is an example using express:

create a file: cfdi2pdf_test.js

const express = require('express');
const app = express();
const cfdi2pdf = require("cfdi2pdf");
const fonts = {
  Roboto: {
    normal: 'public/fonts/Roboto/Roboto-Regular.ttf',
    bold: 'public/fonts/Roboto/Roboto-Medium.ttf',
    italics: 'public/fonts/Roboto/Roboto-Italic.ttf',
    bolditalics: 'public/fonts/Roboto/Roboto-MediumItalic.ttf'
  }
};
// Image must be a base 64 string
const image = "";
const options = {
  fonts,
  image,
  save: {
    folder: 'public/pdf/',
    fileName: `myPDF.pdf`,
  },
};
// XML in string
const xml = "";
app.get('/', async function(req, res, next) {
  const doc = await cfdi2pdf.createPDFServer(xml, options);
  doc.pipe(res);
  doc.end();
});

app.listen(3000, function () {
  console.log('cfdi2pdf app listening on port 3000');
});

In Terminal, run:

$ node cfdi2pdf_test.js

Open the browser at http://localhost:3000 and voilà, you have a PDF representation of a CFDI 3.3

Made with love at Quad Tree / SLP / Mexico

by: Manuel Garcia, Carlos Alvarez, Enrique Motilla visit our project at: https://erpcloud.mx

Maintained by: Alan Rodríguez