JSPDF AutoTable: Preserve line breaks from user-entry TextArea in didParseCell

103 Views Asked by At

I tacked this onto the end of similar issue #807 on GitHub but am hoping for a quicker response here.

I’m creating a dynamic table in JS for a single page app where half the table contents come from JSON and the user enters the other half. The last column for each row is a textarea for notes. I’m using something like this in a didParseText event:

if(data.column.index==3){
  let cid = "#textarea-id-prefix"+data.row.index.toString();
  try{
    let cResult=document.querySelector(cid).value;
    data.cell.text=cResult;
  }
  catch{er){console.log("No notes.")}
} ```

This however doesn’t pass the \n into the PDF as a line break, only as extra line spaces.  Adding a `.replaceAll(“\n”,”<br/>”)` to cResult only inserts the `<br/>` characters (even using a regex for line breaks.)

Is there a better way to get the user entry out of the text area, or does someone have a trick for preserving the line breaks for readability in the generated PDF?

Thanks!
0

There are 0 best solutions below