I am using pdfkit to generate pdf file and i want to send this pdf file to browser.
My following code is working fine and i am getting one pdf with text.
Actually following code is sample to generate pdf using pdfkit in nodejs but now i want to create html table.
Latest Code
var PDFDocument = require('pdfkit');
var fs=require('fs');
doc = new PDFDocument();
doc.pipe( fs.createWriteStream('out.pdf') );
doc.moveTo(300, 75)
.lineTo(373, 301)
.lineTo(181, 161)
.lineTo(419, 161)
.lineTo(227, 301)
.fill('red', 'even-odd');
var loremIpsum = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in...';
doc.y = 320;
doc.fillColor('black')
doc.text(loremIpsum, {
paragraphGap: 10,
indent: 20,
align: 'justify',
columns: 2
});
doc.pipe( res );
doc.end();
But i don't have any idea how to generate HTML table in pdf using pdfkit?
Can any one help me to create HTML table pdf?
Well there's no easy to do it directly with PDFKit. You have to implement the table rendering logic yourself. If you wanna do it simply, you just have to realize that tables are just a bunch of rectangles with text into them. This will work with a one-off code. It won't be flexible though.
If you don't mind deviating from PDFKit a little bit, there's a couple of options:
And seeing you mention HTML, I would really suggest throw PDFkit out of the door when you have HTML and use phantomjs or wkhtmltopdf, which their job is to render HTML and optionally output PDF and that's what you want. Last time I was looking for a module that handles this well, I found phantom-html-to-pdf.
Click show image result