问题描述
我在Itext7中生成分页符时遇到问题.环境:
I have a problem with generating a page break in the Itext7. Environnement:
- Visual Studio 2017 C#
- 版本itext7核心:7.0.2.2 [试用许可证atm]
- 版本itext7.pdfhtml:1.0.0.2
生成PDF的流程:
- 使用RazorEngine用我的cshtml解析我的模型
- 创建文档和作者
- 使用
iText.Html2pdf.HtmlConverter.ConvertToPdf(msHtml,writer);
=> mshtml是我在第1步中生成的html的内存
- Use of RazorEngine to parse my model with my cshtml
- Create a doc and writer
- Use of
iText.Html2pdf.HtmlConverter.ConvertToPdf(msHtml, writer);
=> mshtml is the memory of my generated html in step 1
我测试过的Stackoverflow问题
用于php ... Html2Pdf中的分页符=>不打算更改我的nuget包
is for php...Page break in Html2Pdf=>not planning on changing my nuget package
用于php ... https://stackoverflow.com/a/21773395/5625156 =>无效=>使用位置有任何限制这些标签?您可以在div中使用它们吗?...?
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中的分页符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!