c# - 使用 GEMBOX 将 HTML 转换为 Word 或 PDF
问题描述
我正在使用 Gembox.Documents 将 HTML 文件插入 Word 或 PDF 文档。
不幸的是,在生成的 Word(或 pdf)中,表格中行(单元格)内容的高度太高,与 HTML 文件中的原始高度不对应,我无法在 CSS 的帮助下进行更改或 HTML。
请问您能提出解决问题的方法吗?
string fileName="zzzz";
var destinationDocument = new DocumentModel();
var section = new Section(destinationDocument);
destinationDocument.Sections.Add(section);
var srcDocument = DocumentModel.Load(TempPath + fileName + ".html");
var pageSetup = srcDocument.Sections[0].PageSetup;
var destpagesPageSetup = destinationDocument.Sections[0].PageSetup;
destpagesPageSetup.Orientation = Orientation.Landscape;
destpagesPageSetup.PageWidth = 1000;
destpagesPageSetup.PageHeight = 1000;
destpagesPageSetup.RightToLeft = true;
destpagesPageSetup.PageMargins.Left = 20;
destpagesPageSetup.PageMargins.Right = 0;
destpagesPageSetup.PageMargins.Bottom = 0;
destpagesPageSetup.PageMargins.Top = 0;
destpagesPageSetup.PageMargins.Gutter = 0;
destpagesPageSetup.PageMargins.Footer = 0;
var mapping = new ImportMapping(srcDocument, destinationDocument, false);
var blocks = srcDocument.Sections[0].Blocks;
foreach (Block b in blocks)
{
//b.ParentCollection.TableFormat.DefaultCellSpacing = 1;
Block b1 = destinationDocument.Import(b, true, mapping);
section.Blocks.Add(b1);
}
var pageSetup1 = section.PageSetup;
destinationDocument.Save(TempPath + fileName + ".pdf");
谢谢
解决方案
出现此问题的原因是 HTML 内容中出现了单元格边距。
在调查该 HTML 后,问题已解决,该修复可在当前最新的错误修复版本中获得:
https ://www.gemboxsoftware.com/document/downloads/bugfixes.html
或者在当前最新的 NuGet 包中:
https ://www.nuget.org/packages/GemBox.Document/
推荐阅读
- azure - Azure Yaml 管道表达式;${{}} 与 $()
- verilog - 如何在 Verilog 模拟测试台中写入 txt 日志文件
- php - 尝试回声时卷曲双重提交
- c - 使用 Scanf 输入字符指针数组,但是当我在“空格”被截断后输入字符串时
- ubuntu - (已解决)在 jetson nano 上构建 isaac SDK 示例时出错:JetPack43 未在任何 .rc 文件中定义
- php - Symfony5/Doctrine 找不到我的实体的 XML 映射文件
- r - 偏差和分数残差图
- r - 在 R 中显示 2 个栅格之间的异同
- csv - pyspark从本地加载bigquery中的数据框
- java - 模态对话后 SwingWorker 发布()和处理(列表)乱序