5.20231.904
5.20231.904

The PDF Module

PdfDocument is the main class used in the wijmo.pdf module to create PDF documents. The implemenation is an extension of PDFKit, a JavaScript PDF generation library.

The key differences are:

  • A page is divided into three sections: header, body and footer. Each of these sections represents a drawing area with its own methods for drawing text and graphics.
  • Text of the header and footer areas can be defined declaratively and support macros for automatic page numbering.
  • The graphics state management methods such as fillColor, lineWidth are incapsulated within the pen and brush entities, that acts in more friendly way for .NET developers. It provides API for drawing text, vector graphics and images.

Using PdfDocument

Here is a typical sequence of steps when using PdfDocument:

  1. Create the PdfDocument class instance with the ended event handler declared. The Blob object containing document data will be passed to this event handler when document rendering is done, where it can be saved to a file.

Following is the minimal code required to generate a single page blank document:

import * as wjPdf from '@grapecity/wijmo.pdf';

var doc = new wjPdf.PdfDocument({
    ended: function (sender, args) {
        wijmo.pdf.saveBlob(args.blob, "Document.pdf");
    }
});
  1. Draw the document using the instance members.
doc.drawText("Lorem.");
doc.drawText("Ipsum.", 0, 30);

doc.drawImage("resources/wijmo1.png");
  1. Finally, call end method of the instance to finish rendering and raise the ended event.
doc.end();