【问题标题】:Generate PDF from large html从大 html 生成 PDF
【发布时间】:2016-01-12 20:27:40
【问题描述】:

我正在从 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,但未处理溢出。文本在页面之后继续。是否可以将页面的最大“高度”设置为不交叉,如果可以,它会重新创建一个新页面?

希望它有意义!

非常感谢

【问题讨论】:

    标签: c# html pdf aspose aspose.pdf


    【解决方案1】:

    您可以通过选择所需的 PDF 页面类型(如 A1、A2 等)来设置页面高度。后记,您的页面高度问题将由 Aspose 自动处理。更多请参考链接..

    Aspose PDF Page Height

    更新

    将pdf.HtmlInfo 更新为pdf.PageSetup (or pdf.PageInfo) 并添加底部边距。

    【讨论】:

    • 我已经尝试过了,但它仍然做同样的事情。在我的问题中,我输入了代码:pdf.HtmlInfo.PageHeight = 1050;我也试过 pdf.HtmlInfo.PageHeight = Aspose.Pdf.Generator.PageSize.A4Height; - 结果相同
    • 在Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf(); 之后设置您期望的页面高度和宽度..
    • 好的,我得到了我的错误。这是因为我做了 pdf.HtmlInfo 而不是 pdf.PageSetup(或 pdf.PageInfo)。我还必须添加底部边距。感谢您的回复,我会将您的答案标记为已修复。也许只需在您的答案中添加我的评论,以便下一个可以提供帮助的用户:)
    猜你喜欢
    • 1970-01-01
    • 2011-12-31
    • 2015-07-18
    • 2013-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-22
    • 2014-09-29
    相关资源
    最近更新 更多