Generate PDF files using NodeJS and PDFMake

ASP.NET, PHP, Tutorials

In this article we will show you how to generate PDF invoices on the web server side. We use this approach to generate and email billing reminders to our customers.

1. Download NodeJS to the web server. For Windows choose 64-bit MSI installer.

2. Run and install keeping all default settings.

3. Inside your project create a new folder named pdfmake.

4. Proceed to that folder, start the command line and run:

5. This will create index.js, in this file we will add the code that create PDF file. In our case, we will be generating due invoices for our cliens.

PDFMake documentation

Here is the index.js file we that generates invoices.

6. Now we are ready to create PDF files. Here is how you execute it from PHP code:

And the same for C#:

1 thought on “Generate PDF files using NodeJS and PDFMake

  1. using iTextSharp.text;
    using iTextSharp.text.pdf;
    using System.IO;

    // Create a new PDF document
    Document document = new Document();

    // Create a PDF writer that writes the PDF document to a file stream
    PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(“output.pdf”, FileMode.Create));

    // Open the PDF document for writing

    // Add content to the PDF document
    Paragraph paragraph = new Paragraph(“Hello World!”);

    // Close the PDF document
    In this example, we first import the necessary iTextSharp libraries. Then, we create a new Document object, which represents the PDF document we want to create.

    Next, we create a PdfWriter object, which is responsible for writing the PDF document to a file stream. We pass in the Document object and a new FileStream object that specifies the output file name and mode.

    We then open the Document object for writing, and add content to the PDF document using the Add method. In this example, we add a simple paragraph that says “Hello World!”

    Finally, we close the Document object to complete the PDF generation process. This will save the PDF file to the specified file stream.

    Note that this is a very basic example, and there are many more advanced features and options you can use when generating PDFs with iTextSharp.

Leave a Reply

Your email address will not be published. Required fields are marked *