從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);
}
}
}
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);
}
}
}