问题
I am creating an app which has a full of lists in a tab, and these lists have their data include (again lists inside, we can call them sublists).
I use the expo to build this app, and I use expo print API to convert these lists to PDF. When user tab to share, these lists saved to PDF and open share screen in IOS. Then the user can send this PDF file in any desirable way; It can be an attachment in a mail or whats app or any other included application,
The main problem is page-breaks in PDF, while there is a list which can not fit in an A4, I can't control page breaks, they might break a list at the end of the page,
I found a different solution about this, which can be a calculation the height of the cells and arranging an appropriate margin. Because I already know how many cells can be fit in a default A4.
I am using Print.printToFileAsync(options) to convert HTML to PDF.
I have already tried below CSS but It doesn't work;
<style>
@media print {
table {
background-color: #f44336;
page-break-inside: avoid !important;
}
h2 {
page-break-before: always !important;
}
}
</style>
Any help would be appreciated.
来源:https://stackoverflow.com/questions/56367385/how-to-avoid-page-breaks-inside-content-sections-in-output-pdf-generated-from-ht