c# - C# 的 itextsharp:如何使用“PdfPageEventHelper”中的“OnStartPage”事件从 html 内容呈现为 pdf
问题描述
以下是html内容:
string headerData= "<table style='width: 100%;'><tbody><tr><td style='width: 50%; border: 0.1px solid #000; backgroundcolor:#f2f2f2; color: #000; height: 22px;font-weight:bold;text-align:right'>Territory: </td><td>USA</td></tr></tbody></table>"
现在我想使用 itextsharp 导出 pdf。我想在每个页面中重复标题,所以我使用“PdfPageEventHelper”中的“OnStartPage”事件。我可以编写简单的文本(如“hello Word”)或图像,但无法呈现 html 文本。
PdfPTable table = new PdfPTable(2);
PdfPCell cellHeaderSection = new PdfPCell(new Phrase(headerData));
table.AddCell(cellHeaderSection);
table.WriteSelectedRows(0, -1, document.LeftMargin, document.PageSize.Height - 36, writer.DirectContent);
解决方案
推荐阅读
- git - Git:查找正在进行的合并的(未来)父级
- java - 将 JSON Array 解析为 Java 数组返回最后一个元素作为第二个索引
- php - 删除/转换毫秒的选项
- python - 链式迭代器就地
- corda - 查询活动/住院corda-flows的状态
- spring-webflux - 响应式 WebFlux 的 ReactiveQuerydslPredicateExecutor 分页
- android - 我们可以从应用文件路径播放音频文件吗?
- prometheus - Prometheus:检查 HTTP 服务器是否已启动
- typescript - 区分元组没有按预期工作
- android - 如何在编辑文本中使用用户编号输入并将其用于数学运算