繁体   English   中英

从大HTML生成PDF

[英]Generate PDF from large html

我正在从HTML字符串生成PDF。 当此字符串真的很长时,我想创建一个新页面,拆分文本(不破坏html),依此类推。

这是我的代码:

// instantiate Pdf object
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();

// specify the Character encoding for for HTML file
pdf.HtmlInfo.CharSet = "UTF-8";
pdf.HtmlInfo.Margin.Left = 10;
pdf.HtmlInfo.Margin.Right = 10;
pdf.HtmlInfo.PageHeight = 1050;
pdf.HtmlInfo.PageWidth = 730;
pdf.HtmlInfo.ShowUnknownHtmlTagsAsText = true;
pdf.HtmlInfo.TryEnlargePredefinedTableColumnWidthsToAvoidWordBreaking = true;
pdf.HtmlInfo.CharsetApplyingLevelOfForce = Aspose.Pdf.Generator.HtmlInfo.CharsetApplyingForceLevel.UseWhenImpossibleDetectFromContent;
// bind the source HTML

pdf.BindHTML("MyVeryVeryLongHTML");

MemoryStream stream = new MemoryStream();
pdf.Save(stream);

byte[] pdfBytes = stream.ToArray();

该代码适用于HTML,但不处理溢出。 文本在页面后继续。 是否可以将页面的最大“高度”设置为不交叉,如果这样做,它将重新创建新页面?

希望有道理!

非常感谢

您可以通过选择所需的PDF页面类型(例如A1,A2等)来设置页面高度。 之后,Aspose将自动解决您的页面高度问题。 有关更多信息,请参见链接。

设定PDF页面高度

更新资料

更新pdf.HtmlInfopdf.PageSetup (or pdf.PageInfo)并添加下边距也。

暂无
暂无

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

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