好的,所以我在过去的4个小时里一直在为此而奋斗。我有一个相对简单的代码块,无论我尝试什么,pdf文件总是腐败。我正在使用iTextSharp并尝试了从最旧到最新的每个版本。任何级别的洞察都会受到极大的关注!
以下是我的代码。
var reader = new PdfReader(@"C:\PDF\form_controller.pdf");
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream("file.pdf", FileMode.OpenOrCreate, Ext.Storage.isoStore)) {
using (PdfStamper stamper = new PdfStamper(reader, stream))
{
stamper.AcroFields.SetField("Name", "A cool name");
stamper.FormFlattening = true;
stamper.Close();
}
}
using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("file.pdf", FileMode.Open, Ext.Storage.isoStore))
{
using (FileStream file = new FileStream(@"C:\PDF\file.pdf", FileMode.Create, System.IO.FileAccess.Write))
{
byte[] bytes = new byte[isoStream.Length];
isoStream.Read(bytes, 0, (int)isoStream.Length);
file.Write(bytes, 0, bytes.Length);
}
}