问题描述
我有一个使用 C# 编写的软件及其一个 win 表单应用程序。在他们有生成报告的模块。我们正在做的是生成一个 HTML 文件,然后将其转换为 PDF。为此,我们使用同步融合库
在详细介绍之前。这是我面临的问题。有分页线与数据重叠
我们想去掉这个分页线。
我们用来生成的代码如下
private void ConvertToPDF(string reportPath,string fileName)
{
if (string.IsNullOrEmpty(reportPath) && string.IsNullOrEmpty(fileName))
{
RootServiceProvider.MessageBoxEx.Show(RootServiceProvider.ShellForm,SharedResources.MSG_PDF_ERROR,SharedResources.WARNING,MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
PdfDocument doc = new PdfDocument();
doc.PageSettings.SetMargins(5);
doc.PageSettings.Orientation = PdfPageOrientation.Landscape;
PdfPage page = doc.Pages.Add();
SizeF pageSize = page.GetClientSize();
PdfUnitConvertor convertor = new PdfUnitConvertor();
float width = -1;
float height = -1;
AspectRatio dimension = AspectRatio.None;
dimension = AspectRatio.KeepWidth;
width = convertor.ConvertToPixels(page.GetClientSize().Width,PdfGraphicsUnit.Point);
using (HtmlConverter html = new HtmlConverter())
{
html.AutoDetectPageBreak = true;
using (HtmlToPdfResult result = html.Convert(reportPath,ImageType.Metafile,(int)width,(int)height,dimension))
{
if (result == null && result.RenderedImage == null)
return;
PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
format.Break = PdfLayoutBreakType.FitPage;
format.Layout = PdfLayoutType.Paginate;
doc.PageSettings.Height = result.RenderedImage.Size.Height+format.PaginateBounds.Bottom;
format.SplitTextLines = false;
// Render the image in PDF document
result.Render(page,format);
}
}
doc.Save(fileName);
doc.Close();
System.Diagnostics.Process.Start(fileName);
}
当 Adobe Readers 阅读模式将适合宽度滚动时,会发生这种情况。 我该怎么做才能克服这个问题?
解决方法
我们已尝试重现报告的问题,但无法使用提供的详细信息重现该问题。 IE 渲染引擎在内部使用 Microsoft 的 MSHTML 将 HTML 文件转换为矢量图像,我们将从该图像将内容渲染为 PDF 文档。
请提供更多详细信息,例如完整的输入 HTML 文件/URL(包含所有资源样式、脚本等)、输出文档、产品版本,以便我们最终检查问题。
但是,我们建议您尝试使用我们最新的 Blink/WebKit 渲染引擎来将 HTML 转换为 PDF。请参阅以下链接以获取更多信息,
UG: https://help.syncfusion.com/file-formats/pdf/converting-html-to-pdf
眨眼: https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/blink
WebKit: https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/webkit
知识库: https://www.syncfusion.com/kb/10377/how-to-convert-html-to-pdf-with-blink-using-c-and-vb-net
注意:我为 Syncfusion 工作。
问候,
Gowthamraj K