You must Sign In to post a response.
  • Category: ASP.NET

    Disable Copy,RightClick,Save and Print in pdf

    Hi Friends,

    I am Displaying one pdf file in asp.net. i have a requirement to disable right click, save,copy and print option of that pdf document. please help me to fix this.

    Thank you
  • #763975
    1. Open the PDF in the aspx page
    2. You can try to open that using the window.open

    Following is the sample code

    function openWin(PageP) {
    myWindow = window.open(PageP, PageP, 'height=750,width=1200,toolbar=no,directories=no,status=no, linemenubar=no,scrollbars=no,resizable=no ,modal=yes');
    myWindow.focus();
    }



    3. Also you can handle the key press using javascript

    By Nathan
    Direction is important than speed

  • #763979
    Hi

    You can go through below piece in javascript include your page try them

    this is the code


    <script language="javascript">
    function disableclick(event)
    {
    if(event.button==2)
    {
    return false;
    }
    }
    </script>


    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #763995
    Hai Ambika,
    If you are using the iTextSharp to generate the pdf, then there are few method parameters to restrict the save, edit etc.
    Below is the link where you can find the method to use it:

    http://www.codeproject.com/Questions/302896/Disable-save-as-Print-option-in-PDF-viewer

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #765496
    I searched the internet and found the following forums that discuss a similar requirement
    http://www.c-sharpcorner.com/forums/how-to-disable-save-and-print-option-from-pdf-viewer
    http://stackoverflow.com/questions/1936189/itext-disable-printing-copying-saving
    http://stackoverflow.com/questions/7102529/disable-print-pdf-in-iframe

  • #765499
    PDF document has its own security features to disable copy/paste and print option but you need to use some API to deal with PDF security settings, once the settings are applied then you open PDF in any editor, it will show you effect
    Good way to do it using iTextSharp see below snippet

    PdfReader reader = new PdfReader("my-old-file.pdf");
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("my-new-file.pdf"));
    stamper.setEncryption("my-owner-password".getBytes(), "my-user-password".getBytes(),
    PdfWriter.AllowPrinting | PdfWriter.AllowCopy, PdfWriter.STRENGTH40BITS);
    stamper.close();

    Here is additional link that might help you
    http://www.codeproject.com/Questions/302896/Disable-save-as-Print-option-in-PDF-viewer

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]


Sign In to post your comments