Using Google Apps Script, I have an html template that I fill and then send out (via fax and/or email) as a pdf. The template includes a two-column table with questions/answers.
If there are enough rows, the table breaks across pages in the pdf, and the page breaks usually happen in the middle of cells; I'd like to avoid this.
I've tried using break-inside: avoid;
in both the <tr>
and <td>
elements, with no effect.
Here's the template:
<table style="border-collapse: collapse; border: 1px solid black; table-layout: fixed; width: 100%;">
<tbody>
<tr>
<th style="border: 1px solid black; width: 30%; padding: 5px;">Question</th>
<th style="border: 1px solid black; width: 70%; padding: 5px;">Response</th>
</tr>
<? rows.forEach(function(row){ ?>
<tr style="break-inside: avoid;">
<td style="break-inside: avoid; border: 1px solid black; padding: 5px; line-height: 1.5rem;"> <?= row.question ?> </td>
<td style="break-inside: avoid; border: 1px solid black; padding: 5px; line-height: 1.5rem;"> <?!= row.answer ?> </td>
</tr>
<? }) ?>
</tbody>
</table>
and here's the Apps Script code that converts it to pdf:
var html = '<h3>' + subject + '</h3>'
var tableTemplate = HtmlService.createTemplateFromFile('response-table-template')
tableTemplate.rows = rows;
html += tableTemplate.evaluate().getContent();
var blob = Utilities.newBlob(html, MimeType.HTML, subject).getAs(MimeType.PDF);
and then the blob
is attached to an email/fax. All of that works fine except for my question: Is there a way to avoid breaking table rows over the pages? Possibly another way to convert the html to pdf that respects the break-inside
property? Or an html/css solution that will be respected by Apps Script when converting the html blob to pdf?