How to avoid page breaks inside content sections in output PDF generated from HTML using Expo.printToFileAsync on iOS

北城以北 提交于 2020-01-24 19:41:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!