Quote:
Originally Posted by night.rider
sir really ... this adding password to pdf works and i wrote in C#.net
it really works... awesome yaar...
sir can u tell me if before encryption the pdf is encrypted then wat to do becoz the pdfencrypter gives error...
sir please , if more u can tell abt all this and more
C#.net code as below
Code:
private void btnopen_Click(object sender, EventArgs e)
{
OpenFileDialog FldBrow = new OpenFileDialog();
FldBrow.Title = "Select PDF To Add Password";
FldBrow.InitialDirectory="c:\\";
FldBrow.Filter = "PDF Files (*.pdf)|*.pdf";
FldBrow.FilterIndex = 2;
FldBrow.RestoreDirectory=true;
if(FldBrow.ShowDialog() == System.Windows.Forms.DialogResult.OK)
textBox1.Text=FldBrow.FileName;
}
private void Save_Click(object sender, EventArgs e)
{
SaveFileDialog sfd1=new SaveFileDialog();
sfd1.Title = "Save Output File";
sfd1.InitialDirectory = "My Documents\\";
sfd1.Filter = "PDF files (*.pdf)|*.pdf";
sfd1.FilterIndex = 2;
sfd1.RestoreDirectory = true;
if(sfd1.ShowDialog()==System.Windows.Forms.DialogResult.OK)
textBox2.Text=sfd1.FileName;
}
private void addpwd_Click(object sender, EventArgs e)
{
string input = "";
string output = "";
string password = "";
input = textBox1.Text;
output = textBox2.Text;
password = txtpass.Text;
Add_pwd_to_pdf(input, output, password);
}
private void Add_pwd_to_pdf(string input, string output, string password)
{
//string ownpwd = "123";
PdfReader preader = new PdfReader(input);
PdfEncryptor.Encrypt(preader, new FileStream(output, FileMode.Append), PdfWriter.STRENGTH128BITS, password,"",PdfWriter.ALLOW_SCREENREADERS);
}