0
我正在使用iTextSharp(C#)设置现有PDF的密码。我可以为现有的PDF设置密码,但打开pdf(保存后)时,所有页面都完全空白。请帮我解决一下这个。使用iTextSharp设置现有PDF的密码后,PDF页面为空白
代码中使用:
private void securePDFFile(string InputFile, string OutputFile)
{
using (Stream input = new FileStream(InputFile, FileMode.Open, FileAccess.Read, FileShare.Read))
{
PdfReader reader = new PdfReader(input);
using (Stream output = new FileStream(OutputFile, FileMode.Create, FileAccess.Write, FileShare.None))
{
PdfEncryptor.Encrypt(reader, output, true, null, "secret", PdfWriter.AllowScreenReaders);
}
}
}
问候, 巴拉吉
这通常是无关iTextSharp的,但错误的I/O产生的问题。 PDF是一个二进制文件;如果您读取/保存为ASCII文件,则会出现您遇到的现象。检查文件中的字节。由于读取或写入字节的方式,您会看到所有流均已损坏。 –
@Bruno Lowagie:感谢您的回复,并顺便说一句我刚刚发现快速的事情,只有那些已经用锋利的iText创建的文件可以利用iText尖锐固定的尖锐的iText文档中,其他文件也不能保证,这就是为什么它的空白。 –
请提供空白样品文件。 – mkl