Last active
April 2, 2018 12:26
-
-
Save joshi-kumar/8310c586680cb472c5ac5274687c5272 to your computer and use it in GitHub Desktop.
Protect PDF file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using iTextSharp.text.pdf; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ProtectPDF | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
protectPdf(); | |
} | |
protected static void protectPdf() | |
{ | |
//Set the file location. (get the file or save the protected file) | |
string WorkingFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic); | |
//Get existing pdf file. | |
string InputFile = Path.Combine(WorkingFolder, "ticket.pdf"); | |
//Save procted file in same path. | |
string OutputFile = Path.Combine(WorkingFolder, "myticket.pdf"); | |
using (Stream input = new FileStream(InputFile, FileMode.Open)) | |
{ | |
using (Stream output = new FileStream(OutputFile, FileMode.Create, FileAccess.Write)) | |
{ | |
PdfReader reader = new PdfReader(input); | |
PdfEncryptor.Encrypt(reader, output, true, "admin", null, PdfWriter.ALLOW_SCREENREADERS); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment