【发布时间】:2018-03-08 03:43:36
【问题描述】:
我正在使用 itextsharp。我可以为某些 pdf 添加页脚,但有些我不能。这是我的代码:
byte[] bytes = File.ReadAllBytes(PPTpath);
Font blackFont = FontFactory.GetFont("Arial", 12, Font.NORMAL, BaseColor.BLACK);
using (MemoryStream stream = new MemoryStream())
{
PdfReader reader = new PdfReader(bytes);
using (stamper = new PdfStamper(reader, stream))
{
//stamper.FormFlattening = true;
int pages = reader.NumberOfPages;
for (int i = 1; i <= pages; i++)
{
//ColumnText.ShowTextAligned(stamper.GetUnderContent(i), Element.ALIGN_RIGHT, new Phrase("Generated ECAB", blackFont), 568f, 15f, 0);
ColumnText.ShowTextAligned(stamper.GetOverContent(i), Element.ALIGN_RIGHT, new Phrase("Generated ECAB", blackFont), 568f, 15f, 0);
}
}
bytes = stream.ToArray();
stamper.Close();
}
File.WriteAllBytes(PPTpath, bytes);
这是我尝试添加页脚https://dl.ubnt.com/datasheets/airfiber/airFiber_DS.pdf 的pdf 链接。有人可以解释为什么我不能在这个 pdf 文件中添加页脚。谢谢
【问题讨论】:
-
稍后我会详细查看,但一个明显的可能原因是您在
ColumnText.ShowTextAligned中使用了固定坐标。因此,您需要一个固定的坐标系。另一方面,PDF 在每一页上可以有不同的坐标系,只是原点通常在左下角。 -
@mkl ok 先生,我如何获得动态坐标?
-
我按原样运行您的代码(只是将结果写入不同的文件),它开箱即用,添加了页脚!您可能只是没有权限覆盖该文件吗?您使用哪个 iTextSharp 版本?我显然使用的是最新的 5.5.x:5.5.13。