iTextSharp的密码保护的PDF [英] iTextSharp Password Protected PDF

查看:862
本文介绍了iTextSharp的密码保护的PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在计算器上的以下问题和回答显示了如何生成离不开相应的密码打开一个PDF。

The following question and answer on StackOverflow show how to generate a PDF that cannot be opened without the appropriate password.

密码使用C#保护的PDF

我想同样使用这个框架,但略有改变,让我的用户打开PDF无需密码,但只允许他们编辑的PDF,如果他们有密码。

I would like to use this framework similarly, but slightly altered to allow my users to "open" the PDF without needing the password, but only allow them to EDIT the PDF if they have the password.

这是可能与iTextSharp的?

Is that possible with iTextSharp?

如果此事项,我工作在C#4.0中的WF 4.0自定义活动中。

if this matters, I am working in C# 4.0 within a WF 4.0 custom activity.

推荐答案

是的,有两个密码,你可以传递给 PdfEncryptor.Encrypt()的userPassword ownerPassword 。只是通过的userPassword 和人民将能够打开它没有指定密码。

Yes, there are two passwords that you can pass to PdfEncryptor.Encrypt(), userPassword and ownerPassword. Just pass null to the userPassword and people will be able to open it without specify a password.

        string WorkingFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
        string InputFile = Path.Combine(WorkingFolder, "Test.pdf");
        string OutputFile = Path.Combine(WorkingFolder, "Test_enc.pdf");

        using (Stream input = new FileStream(InputFile, FileMode.Open, FileAccess.Read, FileShare.Read))
        {
            using (Stream output = new FileStream(OutputFile, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                PdfReader reader = new PdfReader(input);
                PdfEncryptor.Encrypt(reader, output, true, null, "secret", PdfWriter.ALLOW_SCREENREADERS);
            }
        }

这篇关于iTextSharp的密码保护的PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆