简体   繁体   English

将 HTML 转换为 PDF,并为 Java 中的不同页面设置动态边距

[英]Convert HTML to PDF With a Dynamic Margin for Different Pages in Java

We are working on creating PDf from HTML which will be printed on Legal Page - It contains financial stamps only for first 3 pages at the top.我们正在努力从 HTML 创建 PDf,它将打印在法律页面上 - 它仅包含顶部前 3 页的金融邮票。 So, we need to set big top margin for first 3 pages only for the space of the Financial Stamp and default margin for rest of the pages.因此,我们只需要为金融印章的空间设置前 3 页的大页边距和页面 rest 的默认页边距。 We are using CYaHPConverter for HTML -> PDF conversion which does not support this dynamic margin setup on runtime pdf creation.我们正在使用 CYaHPConverter 进行 HTML -> PDF 转换,它不支持运行时 pdf 创建时的动态边距设置。 Can anyone have any idea how to solve this problem with CSS or HTML. Or, suggest any other convertion library for this dynamic margin setup for different pages?任何人都知道如何使用 CSS 或 HTML 解决此问题。或者,为不同页面的动态页边距设置建议任何其他转换库?

I tried YaHP-Converter 's documentation and other popular library like - Aspose.PDF.我尝试了 YaHP-Converter的文档和其他流行的库,如 Aspose.PDF。 But not sure how to pass the margin per page.但不确定如何传递每页边距。 I also tried Vanilla CSS but failed to get the idea.我也试过香草 CSS 但没能明白。

I don't know much about YaHP converter , but we can achieve this using the itextPdf library easily.我不太了解YaHP converter ,但我们可以使用itextPdf库轻松实现这一点。

Here is the link which will help you in setting the different margins for different pages.这是帮助您为不同页面设置不同页边距的链接

Based on personal experience, I suggest you use to itext v7 as it can process complicated HTML documents as well compared to v5.根据个人经验,我建议您使用 itext v7,因为与 v5 相比,它可以处理复杂的 HTML 文档。 Check this for more information on why should we use v7检查以获取有关我们为什么要使用 v7 的更多信息

Note: itextpdf library is not free for commercial use, please check their site for further license-related information注意: itextpdf 库不能免费用于商业用途,请查看其站点以获取更多与许可相关的信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM