using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using iTextSharp.text;
using System.IO;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
String FilePath = @"C:\Users\rashid\Desktop\Customer.pdf";
string PDFFilepassword = "12345";
try
{
byte[] bytes = System.IO.File.ReadAllBytes(FilePath);
using (MemoryStream inputData = new MemoryStream(bytes))
{
using (MemoryStream outputData = new MemoryStream())
{
PdfReader reader = new PdfReader(inputData);
PdfReader.unethicalreading = true;
PdfEncryptor.Encrypt(reader, outputData, true, PDFFilepassword, PDFFilepassword, PdfWriter.ALLOW_SCREENREADERS);
bytes = outputData.ToArray();
File.WriteAllBytes(FilePath , bytes);
}
}
}
catch (Exception ex)
{
throw ex;
}
}
}
}
No comments:
Post a Comment
Please do not add any spam link in the comment box.