node-i2djs
  • Introduction to node-i2djs
  • Getting Started
    • Installation
    • Quick Start CanvasLayer
    • Quick Start Canvas PDF Layer
    • Examples
  • API Reference
    • canvasLayer
    • canvasPdfLayer
    • Element API
    • Textures
    • Path
    • Join Action
  • Guide
    • Element types
    • Data Join-Actions
    • Canvas: Textures & Sprite animation
    • Canvas: Clipping, Masking, Pattern
Powered by GitBook
On this page
  • Import node-i2djs module
  • Layer Creation:
  • Page creation
  • Element Creation:
  • Apply changes to Canvas
  • Export PDF
  1. Getting Started

Quick Start Canvas PDF Layer

Get started with node-i2d to create rich visualisations on node platform.

Integrate source code as specified on the installation page.

Import node-i2djs module

let { canvasPdfLayer } = require("node-i2djs");

Layer Creation:

Node-I2Djs offers an API for generating multi-page PDF documents. The following line of code creates a PDF instance using the canvasPdfLayer function, passing in the canvas context, as well as height and width as arguments.

let PDFInstance = canvasPdfLayer({context config}, height, width);

canvasPdfLayer returns exclusive API to support creation of single or Multi page PDF creations.

Page creation

Invoking addPage method via PDFInstance returns pageInstance.

let pageInstance = PDFInstance.addPage();

Element Creation:

pageInstance provides createEl api to create graphical elements. In the below example we are creating Circle element with attributes and style properties as specified below.

let circle = pageInstance.createEl({
    el: 'circle',
    attr: {
        r: 50,
        cx: renderer.width / 2,
        cy: renderer.height / 2
    },
    style: {
        fillStyle: '#ff0000'
    }
})

Apply changes to Canvas

With the below call, we are applying complete render tree onto the canvas layer.

PDFInstance.update()

Export PDF

let pdfSteam = PDFInstance.exportPdf();

exportPdf api returns pdfStream.

PreviousQuick Start CanvasLayerNextExamples

Last updated 2 years ago