rkusa / pdfjs

A Portable Document Format (PDF) generation library targeting both the server- and client-side.
MIT License
774 stars 142 forks source link

Best way to insert blank lines? #229

Closed psalaets closed 4 years ago

psalaets commented 4 years ago

Hi, thank you for this library.

I am trying to insert arbitrary blank lines in my PDF. The effect should be similar to when a user presses the Enter key multiple times in a Word doc.

This is what I've tried so far

Code Does it work? Note
doc.text().br() :x:
doc.text('').br() :x:
doc.text(' ').br() :x:
doc.text(' '.repeat(2)).br() :x: inserts two blank lines
doc.text(' ') :x:
doc.text(' '.repeat(2)) :white_check_mark:
doc.text(' '.repeat(3)) :white_check_mark:
doc.text('\n') :x:
doc.text('\r\n') :x:
doc.text(' \n') :white_check_mark:
doc.text('\u000A') :x: line feed
doc.text('\u000D') :x: carriage return
doc.text('\u200B') :white_check_mark: zero width space

The attempts that worked seem a little hacky.

Is there a recommended way to do this in pdfjs 2.4.1?

rkusa commented 4 years ago

For arbitrary blank lines / whitespace, I usually use cells with a padding, e.g.:

doc.cell("Before whitespace", {paddingBottom: 20})

This also works with empty cells (though I rarely use that):

doc.cell({paddingBottom: 20})

It might be worth thinking about a dedicated API for that 🤔

(thanks for the overview btw!)