我找到了一种方法(不知道这是否是最好的方法,但它确实有效)
string oldFile = "oldFile.pdf";string newFile = "newFile.pdf";// open the readerPdfReader reader = new PdfReader(oldFile);Rectangle size = reader.GetPageSizeWithRotation(1);document document = new document(size);// open the writerFileStream fs = new FileStream(newFile, FileMode.Create, FileAccess.Write);PdfWriter writer = PdfWriter.GetInstance(document, fs);document.Open();// the pdf contentPdfContentByte cb = writer.DirectContent;// select the font propertiesbaseFont bf = baseFont.CreateFont(baseFont.HELVETICA, baseFont.CP1252,baseFont.NOT_EMBEDDED);cb.SetColorFill(baseColor.DARK_GRAY);cb.SetFontAndSize(bf, 8);// write the text in the pdf contentcb.BeginText();string text = "Some random blablablabla...";// put the alignment and coordinates herecb.ShowTextAligned(1, text, 520, 640, 0);cb.EndText();cb.BeginText();text = "Other random blabla...";// put the alignment and coordinates herecb.ShowTextAligned(2, text, 100, 200, 0);cb.EndText();// create the new page and add it to the pdfPdfimportedPage page = writer.GetimportedPage(reader, 1);cb.AddTemplate(page, 0, 0);// close the streams and voilá the file should be changed :)document.Close();fs.Close();writer.Close();reader.Close();
我希望这对某人==有用(并在此处发布任何错误)



