PdfReader reader = new PdfReader(FileUpload1.PostedFile.FileName);
iTextSharp.text.Rectangle size = reader.GetPageSizeWithRotation(1);
Document document = new Document(size);
string name = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
FileStream fs = new FileStream(System.IO.Path.GetFullPath(FileUpload1.PostedFile.FileName), FileMode.Open, FileAccess.Write);
PdfWriter writer = PdfWriter.GetInstance(document, fs);
document.Open();
byte[] data = ReadFully(FileUpload1.PostedFile.InputStream);
PdfContentByte cb = writer.DirectContent;
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb.SetColorFill(BaseColor.DarkGray);
cb.SetFontAndSize(bf, 8);
cb.BeginText();
string hash = string.Empty;
using (SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider())
{
hash = Convert.ToBase64String(sha1.ComputeHash(data));
}
cb.ShowTextAligned(1, hash, 400, 150, 0);
cb.EndText();
PdfImportedPage page = writer.GetImportedPage(reader, 1);
cb.AddTemplate(page, 0, 0);
document.Close();
fs.Close();
writer.Close();
reader.Close();
我正在尝试在特定坐标上写下我的pdf文本。我的文字是pdf,但旧内容也迷失了。
请建议解决方案。 提前谢谢。