pdfjs icon indicating copy to clipboard operation
pdfjs copied to clipboard

Calling .br() does not always add a line break

Open yanickrochon opened this issue 4 years ago • 2 comments

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 :

image

yanickrochon avatar Sep 30 '19 14:09 yanickrochon

For some reason, to solve this issu, one has to simply set the paddingBottom to the row instead of the table.

Never mind.

yanickrochon avatar Sep 30 '19 14:09 yanickrochon

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?

rkusa avatar Oct 11 '19 11:10 rkusa