DEV Community

Cover image for How difficult problem in pdf solved by just creating it
Shubham Arora
Shubham Arora

Posted on

How difficult problem in pdf solved by just creating it

Yes! in programming the thing that gave me blow was creating PDF having URL images.

I Used a lot of methods for it but all were with some corns and pros. e.g if you are able to load replica of the table on PDF then the problem was with loading URL images e.g Amazon S3, google images etc. Here I will describe to you what technology I used what methods I applied for generating pdf.


JavaScript(Client Side), NodeJS (Server Side)


jsPDF, PDFMake, PDFkit


As using these technologies and methods I have some points that will help you to use efficiently

Using jsPDF and PDFMake You can generate a PDF file having static data and images easily.

When it comes to URL based images it becomes difficult to load directly to PDF file we can load images to PDF file by using some JavaScript methods like a canvas which first use URL images as its function parameter then convert it into a Base64 string which then can be used by jsPDF or PDFMake’s methods.

Now if we have images and table’s data both but there will be another problem of converting numbers of images to base64 and it is hanging of application.

So I found a way for converting PDF file is the PDFkit. it is the practice of converting PDF file, the only thing that it requires is hit and trail, the method that best for it according to me is PDFkit as mentioned. it all requires server-side support like file system, request packages

e.g var fs = require(‘fs’), 
var request = require(‘request’);
Enter fullscreen mode Exit fullscreen mode

Request method basically overcomes the base64 issue what it does it take image URLs and make it buffer the pdfkit used that buffer data and load it to PDF page without hanging application. pdfkit even support many properties like decorating text with font property, geometries like line, triangle, square and many all you just need apply hit and trial and you will get an almost same table with the dynamic images example you want to create pdf for vehicle inspections.

Thanks for reading ;)

You can find me on Twitter as @shubhu_off_base

Top comments (0)