方法htmltopdf中的Itext7中的分页符 [英] Page break in Itext7 in method htmltopdf

查看:260
本文介绍了方法htmltopdf中的Itext7中的分页符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Itext7中生成分页符时遇到问题.环境:

I have a problem with generating a page break in the Itext7. Environnement:

  1. Visual Studio 2017 C#
  2. 版本itext7核心:7.0.2.2 [试用许可证atm]
  3. 版本itext7.pdfhtml:1.0.0.2

生成PDF的流程:

  1. 使用RazorEngine用我的cshtml解析我的模型
  2. 创建文档和作者
  3. 使用 iText.Html2pdf.HtmlConverter.ConvertToPdf(msHtml,writer); => mshtml是我在第1步中生成的html的内存
  1. Use of RazorEngine to parse my model with my cshtml
  2. Create a doc and writer
  3. Use of iText.Html2pdf.HtmlConverter.ConvertToPdf(msHtml, writer); => mshtml is the memory of my generated html in step 1

我测试过的Stackoverflow问题

建议的解决方案1:用于php ... Html2Pdf中的分页符=>不打算更改我的nuget包

Suggested solution 1: is for php... Page break in Html2Pdf =>not planning on changing my nuget package

建议的解决方案2:用于php ... https://stackoverflow.com/a/21773395/5625156 =>无效=>使用位置有任何限制这些标签?您可以在div中使用它们吗?...?

Suggested solution 2: is for php... https://stackoverflow.com/a/21773395/5625156 => not working => are there any restrictions where to use these tags? Can you use them inside a div ,...?

建议的解决方案3:使用 page-break-before:始终:在itext5中工作,但不在itext7中工作

Suggested solution 3: Use page-break-before: always: Worked in itext5 but not in the itext7

还有其他建议吗?还是这个问题?

Any other suggestions for the break? Or is this an issue?

更新1:* .cshtml中的分页代码

  // Worked like this in itext5
<div style="page-break-before: always;">
  // table 
</div> 

推荐答案

经过数小时的研究,并针对处于相同情况的人们.

After several hours of research and for those who are in the same situation.

在第2章:使用CSS定义样式"中提供的示例中,其中,宽度"是指财产存在.因此,我只是添加了宽度:100%喜欢"而且有效.

In the example provided in "Chapter 2: Defining styles with CSS" of itext, the "width" property is present. So i just added width: 100% like "" and it worked.

这篇关于方法htmltopdf中的Itext7中的分页符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆