I'm trying to create paragraph indents in PDFkit. The PDFkit docs state that the indent attribute is "to indent each paragraph of text". While trying this, only the first line has an indent.
const doc = new PDFDocument({ size: "A4" });
doc.pipe(fs.createWriteStream('output2.pdf'));
doc.addPage()
doc.text('fdgfdgfg fggfdgfdg fgfdg fdg dfgdfgdfg dfgfdg fgfgfdg fdgdfgdfg', { indent: 30 })
doc.end();
The code delivers an indent only in the first line of the paragraph. How can I indent the whole paragraph?
I moved from PDFKit to pdfmake (which is based on PDFKit), which handles indents for my case way better than PDFkit itself. For my use case it's also better since I use JSON output from my markdown lexer which can easily transformed to the input for pdfmake.
You need to doc.text and doc.moveDown if you want consecutive paragraphs.
const doc = new PDFDocument({ size: "A4" });
doc.pipe(fs.createWriteStream('output2.pdf'));
doc.addPage()
doc.text('This is the start of paragraph 1', { indent: 30 });
doc.moveDown();
doc.text('This is the start of paragraph 2', { indent: 30 });
doc.moveDown();
doc.text('This is the start of paragraph 3', { indent: 30 });
doc.end();