Click here to Skip to main content
15,917,652 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to disable Save as button in PDF file using iTextSharp or any other solution because I wish to show only the content of pdf and not allow to download pdf file in local drive ?
Posted
Comments
Sergey Alexandrovich Kryukov 22-Apr-15 2:38am    
The question makes no sense at all. Disable where? Showing some document and not downloading it would be a great abuse. What user would like to deal with you and your products?
—SA
Gurupatham 22-Apr-15 2:55am    
Hi Sergey Alexandrovich Kryukov,

I Developed file storage application in C#.net,Admin user upload the pdf files from that system,In specific requirement user can view only the content of pdf file and not allow to save local drive and also not allow to take printout.I findout solutions to disable pdf print option using iTextsharp but yet to not find the solution for disable save as option in pdf file.if there's any options and soltution please share with me.

Below mentioned code for disable print button in pdf file
--------------------------------------------------
using iTextSharp;
using iTextSharp.text;
using iTextSharp.text.pdf;

protected void Page_Load(object sender, EventArgs e)
{

string WorkingFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string InputFile = Path.Combine(WorkingFolder, "StickerSheet_New.pdf");
string OutputFile = Path.Combine(WorkingFolder, "2.pdf");


using (Stream input = new FileStream(InputFile, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using (Stream output = new FileStream(OutputFile, FileMode.Create, FileAccess.Write, FileShare.None))
{

PdfReader reader = new PdfReader(input);
//PdfEncryptor.Encrypt(reader, output, true, "23!54", "23!54", PdfWriter.ALLOW_SCREENREADERS);
System.Text.UTF8Encoding Encoding = new System.Text.UTF8Encoding();

PdfStamper stamper = new PdfStamper(reader, output);
stamper.SetEncryption(Encoding.GetBytes("23!54"), null, PdfWriter.AllowScreenReaders, PdfWriter.STRENGTH40BITS );
//output.ViewerPreferences.HideToolbar = true;
//PdfReader pReader = new PdfReader();
//PdfEncryptor.Encrypt(reader, new FileStream("1.pdf", FileMode.Open), PdfWriter.STRENGTH128BITS, "23!54", null, PdfWriter.AllowScreenReaders);
stamper.Close();
reader.Close();
Response.Write("PDF created");
}
}
}

}
}


1 solution

There is no way to prevent save of a PDF file opened in some viewer...
The only thing you can do is adding some security policy to the PDF file (password protection) and or encrypt it (an other kind of password protection)...
However! Event that will not prevent the user to create as many copies of the PDF file as one wants...but it will prevent the opening of it without the password...
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 22-Apr-15 2:57am    
Sure, a 5.
—SA
Kornfeld Eliyahu Peter 22-Apr-15 2:57am    
Thank you...
TheRealSteveJudge 22-Apr-15 3:33am    
Exactly. 5*
Kornfeld Eliyahu Peter 22-Apr-15 3:34am    
Thank you...
Gurupatham 22-Apr-15 5:43am    
Any other solutions for just display the pdf contents(not allow download/save/print) in .net?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900