使用iTextSharp为现有PDF设置密码后,PDF页面为空白

时间:2014-01-19 20:02:18

标签: c# pdf itextsharp

我正在使用iTextSharp(C#)来设置现有PDF的密码。我可以设置现有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);
            }
        }
    }

此致 巴拉吉

1 个答案:

答案 0 :(得分:0)

我刚刚在Itext sharp文档中发现,只有使用Itext sharp创建的文件(仅使用Itest Shapr创建的现有pdf)才能使用Itext sharp保护,其他文件无法保护这就是它空白的原因。最好的替代方案是PDF sharp,它可以保护所有文件。

此致  巴拉吉

相关问题