pdfHtml5 exportOptions to remove nested tags

pdfHtml5 exportOptions to remove nested tags

iecwebmastiecwebmast Posts: 66Questions: 9Answers: 1

Hello,

I'm having some trouble with nested html tags when using the buttons plugin with pdfHtml5.
The text in my cell is wrapped in two nested <div> and a <p>. In the PDF export, I only need the contents of the <p>

<td>
  <div class="flagimg" style="background-image: url(...)">
    <div class="flagtext">
      <p>name of country</p>
    </div>
  </div>
</td>

The nested <div> and <p> are creating additional space above and below the cell data, which makes the PDF very long.
I would like to remove nested html tags, but I'm not sure how to write the syntax right.

 $(document).ready(function() {
    var buttonCommon = {
      exportOptions: {
        format: {
          body: function(data, column, row) {
            data = data.replace(/<div class="flagtext"\">/, '');
            data = data.replace(/<.*?>/g, "");
            return data;
          }
        }
      }
    };

Can anyone help me with this?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,853Questions: 1Answers: 10,134 Site admin

    It should be that the HTML is stripped, newlines remove and the resulting text trimmed by default in the PDF export. Could you give me a link to the page showing the issue so I can take a look at it?

    Thanks,
    Allan

  • iecwebmastiecwebmast Posts: 66Questions: 9Answers: 1

    Hi Allan,

    Here is a little jsfiddle which illustrates the problem.
    https://jsfiddle.net/lbriquet/7f08n0qa/

    In doing this, I've discovered that the problem is not the nested div, but rather that the tags are indented in the code instead of being on one line. In the first row, the nested tags with indented code is leaving space above and below the country name data in the PDF export. In the second row I've put all of the tags on the same line... and no extra spacing is produced in the PDF export.

    Is there a way to get the PDF export to ignore the indentation of code? I guess I won't be the only person who runs into this problem sooner or later.

    Thank you in advance for your help!
    iecwebmast

  • allanallan Posts: 61,853Questions: 1Answers: 10,134 Site admin

    Thanks. You've got your own formatter, so all you need to do is use $.trim() to trim the string: https://jsfiddle.net/7f08n0qa/1/ .

    Allan

  • allanallan Posts: 61,853Questions: 1Answers: 10,134 Site admin
    Answer ✓

    Works just as well without a custom formatters as well: https://jsfiddle.net/7f08n0qa/2/ .

    Allan

  • iecwebmastiecwebmast Posts: 66Questions: 9Answers: 1

    thank you!

This discussion has been closed.