我想使用iTextSharp将文本添加到现有的PDF文件,我发现不同的方式,但在所有这些文件中,作者和读者都是单独的pdf文件。 我想要一种方式,所以我可以打开pdf然后在不同的位置写入不同的东西。 现在我有这个代码,但它会创建一个新文件。ITextSharp编辑现有的pdf
using (FileStream stream1 = File.Open(path, FileMode.OpenOrCreate))
{
BaseFont bf = BaseFont.CreateFont(fontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
PdfReader reader = new PdfReader("C:\\26178DATA\\pdf\\holding.pdf");
var pageSize = reader.GetPageSize(1);
PdfStamper stamper = new PdfStamper(reader, stream1);
iTextSharp.text.Font tmpFont = new iTextSharp.text.Font(bf, fontSize);
PdfContentByte canvas = stamper.GetOverContent(1);
Phrase ph = new Phrase(words[1], tmpFont);
ph.Font = tmpFont;
canvas.SetFontAndSize(bf, fontSize);
ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, ph, iTextSharp.text.Utilities.MillimetersToPoints(x * 10), pageSize.GetTop(iTextSharp.text.Utilities.MillimetersToPoints(y * 10)), 0);
stamper.Close();
}