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

    How to Disable or Prevent a .Pdffile from being printed or downloaded on browser

    hi Developers ,

    i want to disable or prevent a .Pdf file on browser .

    in my project i am opening a .Pdf from database to new tab . now i want to Disable Printable or Download from the End user. because all attachments are govt property and valuables.

    this is my code for open a .Pdf file on a new tab .

    protected void Button1_Click(object sender, EventArgs e)
    SqlConnection con = Connection.DBConn();
    string str = "SELECT KeyFactsFileName FROM tbl_question where id='" + sno + "' and status='A'";
    SqlDataAdapter sda = new SqlDataAdapter(str, con);
    DataSet ds = new DataSet();
    string path = ds.Tables[0].Rows[0]["KeyFactsFileName"].ToString();

    string urlName = Request.Url.AbsoluteUri;
    urlName = urlName.Remove(urlName.LastIndexOf("/"));
    string url = string.Format("{0}/Files/{1}", urlName, path);
    string script = "<script type='text/javascript'>'" + url + "')</script>";
    this.ClientScript.RegisterStartupScript(this.GetType(), "script", script);

    how can i done this task , could anyone know please suggest me to how can i done this task

    thanking with
  • #769356
    Hi Paul.

    If you open a pdf file in browser it will give you print and save file options as it is the browser behavior.
    I recommend you to use google docs viewer by passing the URL of your pdf file like below.

    <iframe src="" style="width:600px; height:500px;" frameborder="0"></iframe>

    Sridhar Thota.
    Editor: DNS Forum.

  • #769357
    thanks mr.sridhar thota , your code is working fine ,
    but i dont know how to View Pdf with Google Docs Viewer in application . could you please give any suggestions to that . if possible .

    thanking you.
    "Man becomes what he thinks about"

  • #769369
    Actually, it's impossible to prevent users from downloading pdf files on browser, but you can use a pdf viewer control to do that. The following solution is provided by Spire.PDFViewer for .NET, hope it meets your need.

  • Sign In to post your comments