【发布时间】:2020-04-26 05:26:05
【问题描述】:
Aspose.Pdf.TextStamp 与之前添加的文本重叠。如何防止这种情况发生?
这是我用来准备文档的代码:
StringBuilder htmlPage = new StringBuilder();
//put here the html from https://pastebin.com/c6Hu4nV5
//instead of the `text foo`
htmlPage.Append("text foo");
byte[] bytes = Encoding.UTF8.GetBytes(htmlPage.ToString());
var streamHtml = new MemoryStream(bytes)
var objLoadOptions = new Aspose.Pdf.HtmlLoadOptions(0, 50, 0, 0);
var doc = new Aspose.Pdf.Document(streamHtml, objLoadOptions);
这是我用于添加页码(在我的上下文中是图章)的代码:
foreach (var page in doc.Pages)
{
Aspose.Pdf.Facades.FormattedText formattedText = new Aspose.Pdf.Facades.FormattedText(idAndVersion + page.Number + "-" + doc.Pages.Count,
Color.Black, Aspose.Pdf.Facades.FontStyle.Helvetica, Aspose.Pdf.Facades.EncodingType.Identity_h,
true, 12F);
var textStamp = new Aspose.Pdf.TextStamp(formattedText)
{
VerticalAlignment = Aspose.Pdf.VerticalAlignment.Bottom,
HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Left,
LeftMargin = 50,
BottomMargin = 20
};
page.AddStamp(textStamp);
}
我使用邮票作为添加页码的一种方式。也许有更好的方法来做到这一点?
我试图找到比here 更好的方法,但没有成功。
添加页码后,我要做的是:
using (var streamPdf = new MemoryStream())
{
doc.Save(streamPdf, Aspose.Pdf.SaveFormat.Pdf);
return streamPdf.GetBuffer();
}
【问题讨论】:
-
您能否通过将其上传到 Google Drive 或 Dropbox 来分享您尝试添加文本图章的 PDF 文档。我们将在我们的环境中测试该场景并相应地解决它。我是 Asad Ali,在 Aspose 担任开发人员宣传员。
-
@AsadAli,如上所示,我正在生成文件内容并在运行时创建文件。这意味着当与 pdf 生成相关的代码开始执行时,我没有文件。要不要我给你提供
htmlPage变量的字符串内容? -
@AsadAli,我在上面更新了我的问题。我相信现在您应该能够轻松地重现该问题。如果您需要我提供任何其他帮助,请告诉我。
标签: .net pdf constructor pagination aspose