pdfjs
pdfjs copied to clipboard
Calling .br() does not always add a line break
We have noticed this from a few generated documents, sometimes the text is not properly formatted because a .br()
is ignored.
It seems that there is something about the header that cases various display bugs on multiple page documents. For example, this in the sandbox :
// available variables: pdf, fonts, logo, lorem
var doc = new pdf.Document({
font: fonts.Helvetica,
padding: 1 * pdf.cm
})
var header = doc.header().table({ widths: [null, null], paddingBottom: 1*pdf.cm }).row()
header.cell().image(logo, { height: 2*pdf.cm })
header.cell().text({ textAlign: 'right' })
.add('Test.')
doc.footer()
.pageNumber(function(curr, total) { return curr + ' / ' + total }, { textAlign: 'center' })
var cell = doc.cell()
var table = doc.table({
widths: [1.5*pdf.cm, 2*pdf.cm, null, null, 2*pdf.cm, 2.5*pdf.cm],
borderHorizontalWidths: function(i) { return i < 2 ? 1 : 0.1 },
padding: 5
})
function addRow(index) {
var tr = table.row()
tr.cell(index.toString())
tr.cell().text({ font: fonts.Helvetica, textAlign: 'right' })
.add("A:").br()
.add("B:").br()
.add("C:").br()
.add("D:").br()
.add("E:").br()
.add("F:")
;
tr.cell().text({ font: fonts.HelveticaBold })
.add("some:").br()
.add("value:").br()
.add("some value:").br()
.add("some value:").br()
.add("test:").br()
.add("some value:")
;
tr.cell().image( logo );
tr.cell().text()
.add("A:").br()
.add("B:").br()
.add("C:").br()
.add("D:").br()
.add("E:").br()
.add("F:")
;
tr.cell().text()
.add("A:").br()
.add("B:").br()
.add("C:").br()
.add("D:").br()
.add("E:").br()
.add("F:")
;
}
for (let i = 1; i < 30; ++i) {
addRow(i)
}
Produces :
For some reason, to solve this issu, one has to simply set the paddingBottom
to the row instead of the table.
Never mind.
Hi, thanks a lot for the report. It should be fixed on master
- would you mind testing it and letting me know if it works for you as well?