How to Create PDF File with Text and Images in Node.js Using Hummus Recipe Library

How to Create PDF File with Text and Images in Node.js Using Hummus Recipe Library

Welcome folks today in this post we will be talking about how to create pdf file with text and images in node.js using a library called Hummus Recipe Library. All the source code of the application is given below. A step by step youtube video is also shown below.

 

 

Get Started

 

Official Link of Library

 

In order to get started we need to first of all create a brand new node.js project and execute the following command to install this package

 


npm i hummus-recipe --save

 

Now make the index.js file which will be the starting point of the application and copy paste the following code

 

const HummusRecipe = require('hummus-recipe');
const pdfDoc = new HummusRecipe('new', Date.now() + '.pdf');
pdfDoc
    // 1st Page
    .createPage('letter-size')
    .text('Welcome to Hummus-Recipe', 'center', 250, {
        color: '#066099',
        fontSize: 30,
        bold: true,
        font: 'Helvatica',
        align: 'center center',
        opacity: 0.8
    })
    .image('image.png', 170, 300, {width: 300, keepAspectRatio: true})

        .endPage()
    // 2nd page
    .createPage('A4', 90)
    .circle(150, 150, 300)
    .endPage()
    // end and save
    .endPDF(()=>{ /* done! */ });

 

See also  Node.js Express App to Find Image Size From URL or From Local Computer Using image-size Library 2020

 

Methods Used

 

  1. createPage : It actually creates the pdf page
  2. text: It actually renders the text into the pdf document
  3. image: It actually renders the image inside the pdf document
  4. circle: It actually draws the circle inside the pdf document
  5. endPage: It actually ends the current page contents inside the pdf document
  6. endPDF: It actually ends the PDF Document

 

Output PDF

 

Leave a Reply