我有水晶報告。我想將其導出爲PDF。同時我想用iTextSharp對它進行加密。使用itextSharp在Crystal Report導出期間加密PDF
這是我的代碼:
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "PDF File|*.pdf";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
string filepath = saveFileDialog1.FileName;
crd.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, filepath);
var doc = new Document(PageSize.A4);
PdfReader reader = new PdfReader(filepath);
PdfEncryptor.Encrypt(reader, new FileStream(filepath, FileMode.Open), PdfWriter.STRENGTH128BITS, "pass", "pass", PdfWriter.AllowScreenReaders);
}
我得到以下
Error: "The process cannot access the file because it is being used by another process"
問題是什麼?有沒有其他方法可以做到這一點?
您的實際問題是,你正在努力,而你是從文件中讀取到寫入文件。一般來說,這兩項行動不應該同時進行。 @reckface解決方案可能是最好的選擇。 – 2014-09-24 13:39:42