密码使用C#保护的PDF [英] Password protected PDF using C#

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

问题描述

我创建使用C#代码在我的过程PDF文档。我需要保护docuemnt
有一些标准的密码,如123456或一些帐号。我需要做的这一点没有
的任何引用dll文件如PDF作家。



我使用的SQL Reporting Services报表生成PDF文件。



时有最简单的方法。


解决方案

我创建使用C#
码在我的过程PDF文档




您使用一些库来创建这个文件呢?该 PDF规范(8.6MB)是相当大的,涉及操作PDF的所有任务可以不很困难使用第三方库。密码保护和与自由和开放源码 iTextSharp的库加密的PDF文件是很容易的:

 使用(流输入=新的FileStream(的test.pdf,FileMode.Open,FileAccess.Read,FileShare.Read))
使用(流输出=新的FileStream(test_encrypted.pdf,FileMode.Create,FileAccess.Write,FileShare.None))
{
PdfReader读卡器=新PdfReader(输入);
PdfEncryptor.Encrypt(读卡器,输出,真正的秘密,秘密,PdfWriter.ALLOW_PRINTING);
}


I am creating a pdf document using C# code in my process. I need to protect the docuemnt with some standard password like "123456" or some account number. I need to do this without any reference dlls like pdf writer.

I am generating the PDF file using SQL Reporting services reports.

Is there are easiest way.

解决方案

I am creating a pdf document using C# code in my process

Are you using some library to create this document? The pdf specification (8.6MB) is quite big and all tasks involving pdf manipulation could be difficult without using a third party library. Password protecting and encrypting your pdf files with the free and open source itextsharp library is quite easy:

using (Stream input = new FileStream("test.pdf", FileMode.Open, FileAccess.Read, FileShare.Read))
using (Stream output = new FileStream("test_encrypted.pdf", FileMode.Create, FileAccess.Write, FileShare.None))
{
    PdfReader reader = new PdfReader(input);
    PdfEncryptor.Encrypt(reader, output, true, "secret", "secret", PdfWriter.ALLOW_PRINTING);
}

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

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