如何在.NET中以编程方式密码保护pdf? [英] How to password protect pdf programmatically in .NET?
本文介绍了如何在.NET中以编程方式密码保护pdf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用C#中的密码以编程方式保护PDF文件. 相同的PDF文件必须使用不同的名称和不同的密码保存.
I need to programmatically protect a PDF file with a password in C#. The same PDF file must be saved with different names and different password.
有人知道这种方法吗(请不要使用昂贵的工具)?
Does anyone know a method for this (no expensive tools, please..)?
推荐答案
可以使用 itextsharp :>
using (var input = new FileStream("test.pdf", FileMode.Open, FileAccess.Read, FileShare.Read))
using (var output = new FileStream("test_encrypted.pdf", FileMode.Create, FileAccess.Write, FileShare.None))
{
var reader = new PdfReader(input);
PdfEncryptor.Encrypt(reader, output, true, "userPassword", "userPassword", PdfWriter.ALLOW_PRINTING);
}
这篇关于如何在.NET中以编程方式密码保护pdf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文