密码保护PDF文件 [英] Password protecting a PDF file
本文介绍了密码保护PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下内容:
- 例行X,它每天创建一个PDF文件.
- 将这个文件附加到Outlook电子邮件并将其发送给收件人的例程Y.
以上两者均在VBA中.它们是从C#控制台应用程序调用的.
Both the above are in VBA. They are called from a C# console application.
创建PDF后,我需要用密码保护它.在不购买第三方软件的情况下通过VBA进行此操作相当麻烦.
Once the PDF has been created I need to password protect it. To do this via VBA without purchasing third party software is quite involved.
使用C#最简单的解决方案是什么?
What is the simplest solution using C#?
(我怀疑我们花费的金额和答案的复杂性之间存在反比关系!)
(I'm suspecting there will be an inverse relationship between amount we spend and complexity of answer!)
推荐答案
PDFSharp 应该能够使用密码保护PDF文件:
PDFSharp should be able to protect a PDF file with a password:
// Open an existing document. Providing an unrequired password is ignored.
PdfDocument document = PdfReader.Open(filename, "some text");
PdfSecuritySettings securitySettings = document.SecuritySettings;
// Setting one of the passwords automatically sets the security level to
// PdfDocumentSecurityLevel.Encrypted128Bit.
securitySettings.UserPassword = "user";
securitySettings.OwnerPassword = "owner";
// Don't use 40 bit encryption unless needed for compatibility reasons
//securitySettings.DocumentSecurityLevel = PdfDocumentSecurityLevel.Encrypted40Bit;
// Restrict some rights.
securitySettings.PermitAccessibilityExtractContent = false;
securitySettings.PermitAnnotations = false;
securitySettings.PermitAssembleDocument = false;
securitySettings.PermitExtractContent = false;
securitySettings.PermitFormsFill = true;
securitySettings.PermitFullQualityPrint = false;
securitySettings.PermitModifyDocument = true;
securitySettings.PermitPrint = false;
// Save the document...
document.Save(filename);
参考:
http://www.pdfsharp.net/wiki/ProtectDocument-sample.ashx
这篇关于密码保护PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文