垃圾的英语单词
c#中使⽤itextsharp替换pdf⽂本
public static void PDFReplace()
堕落的英文{
using (PdfReader reader = new PdfReader("D:\\test\\1.pdf"))
{
雄狮去流浪byte[] contentBytes = reader.GetPageContent(1);
string contentString = PdfEncodings.ConvertToString(contentBytes, PdfObject.TEXT_PDFDOCENCODING);
contentString = contentString.Replace("I", "1234");
备档线
reader.SetPageContent(1, PdfEncodings.ConvertToBytes(contentString, PdfObject.TEXT_PDFDOCENCODING)); new PdfStamper(reader, new FileStream("D:\\test\\2.pdf", FileMode.Create, FileAccess.Write)).Clo();
}
}
最好的学习方法>自理能力
使⽤这个会导致中⽂读取失败 最后经过测试 发现使⽤Default读取可以正常读到中⽂
public static void PDFReplace()
{
桃红清血丸
using (PdfReader reader = new PdfReader("D:\\test\\muweb.pdf"))
{
byte[] contentBytes = reader.GetPageContent(1);
string contentString = System.Text.Encoding.Default.GetString(contentBytes);
//string contentString = PdfEncodings.ConvertToString(contentBytes, "UTF-8");
contentString = contentString.Replace("","");
雨露reader.SetPageContent(1, Encoding.Default.GetBytes(contentString));
new PdfStamper(reader, new FileStream("D:\\test\\2.pdf", FileMode.Create, FileAccess.Write)).Clo();
}
}