Pdfkit: How can I separate some content (break line) in my PDF with PDFKit and Express

Created on 19 May 2017  路  4Comments  路  Source: foliojs/pdfkit

Hi,

Im new programming with nodejs and Im tryin to create some PDF Documents from a Browser request.
imagen

The thing is I would like to have the three paragraphs in the same PDF separateley with a line break. But it semms my code just add a comma (,) between each paragraph... I have inspected the PDFKit module, and I couldnt find where this coma comes from. Can somebody help me?

pdfdocument.pdf

This is my code:

`
const express = require('express');
const router = express.Router();
const PDFDocument = require('pdfkit');

router.get('/', function(req, res, next) {
    res.render('pdf', {
        title: 'Steps',
        text: 'Express'
    });
});
router.post('/', function(req, res) {
var doc = new PDFDocument();

var filename = req.body.filename;

filename = encodeURIComponent(filename) + '.pdf';

res.setHeader('Content-disposition', 'attachment; filename="' + filename + '"');
res.setHeader('Content-type', 'application/pdf');

var content = [req.body.content];

for(i = 0; i < content.length; i++ ) {
    doc.y = 300;
    doc.text(content[i], 50, 50);
}
doc.pipe(res);
doc.end();
});
module.exports = router;

and this is the html:

`

Create a PDF

.pdf

`

Most helpful comment

HI, I think you have to add
doc.moveDown() Inside the loop for!

Like this:

for(i = 0; i < content.length; i++ ) {
    doc.y = 300;
    doc.text(content[i], 50, 50);
    doc.moveDown()
}

All 4 comments

HI, I think you have to add
doc.moveDown() Inside the loop for!

Like this:

for(i = 0; i < content.length; i++ ) {
    doc.y = 300;
    doc.text(content[i], 50, 50);
    doc.moveDown()
}

Hi, thanks for your answer. I try that method but it seems to be IntelliJ can not recognize that method and Im getting the same PDF as before.
imagen

Any ideas why? Im using WebStorm 2017.1

I麓ve just resolve why Webstorm couldn麓t recognize the mothod moveDown(), pdfkit was not in the file package.json in my project.

I tried again with this method, but I still get my paragraphs separated by a comma. I dont know if it a standard setting... Any suggestions?

Sorry, I can't help you with Webstorm, I don't use it!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stephen-last picture stephen-last  路  4Comments

alFReD-NSH picture alFReD-NSH  路  4Comments

vovkvlad picture vovkvlad  路  5Comments

balsamiqMichele picture balsamiqMichele  路  4Comments

oknoorap picture oknoorap  路  4Comments