利用iTextSharp加密PDF文件

http://sourceforge.net/projects/itextsharp/下载iTextSharp的源代码或DLL。

 

利用iTextSharp,从C#、VB等.Net下语言处理PDF文件,不用安装Acrobat,确实方便。


using System;
using System.Collections.Generic;
using System.Text;
using iTextSharp.text.pdf;
using System.IO;

namespace PDFSecurity
{
    
class PDFEncry
    {
        
public static void Encry(string pdfSrc, string pdfDest, bool strength,
            
string userPassword, string ownerPassword, int permissions)
        {
            PdfReader reader 
= new PdfReader(pdfSrc);
            Stream os 
= (Stream)(new FileStream(pdfDest, FileMode.Create));
            PdfEncryptor.Encrypt(reader, os, strength, userPassword, ownerPassword, permissions);
        }
    }
}

posted @ 2008-08-25 16:37  h2appy  阅读(2210)  评论(0编辑  收藏  举报