我有水晶报告。我想将其导出为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