I have a page where I am trying to render a pdf file using response.contenttype = "application/pdf". when the page has rendered, I need to launch a javascript command to launch the window's print dialog box which is usually done using window.print()
The issue is because of contenttype not being html, page wouldn't fire the javascript function so can't auto launch the priting dialog. Here is the C# code, which i using to display pdf contents and along with this I tried window.print in static javascript and registering it using RegisterClientScript.
Code:
********************
Expand|Select|Wrap|Line Numbers
- FileStream fs = new FileStream(@"C:\somefile.pdf", FileMode.Open);
- Byte[] buffer = new byte[fs.Length];
- fs.Read(buffer, 0, (int)fs.Length);
- fs.Close();
- Response.ContentType = "application/pdf";
- Response.BinaryWrite(buffer);
- Response.Flush();
If I change the code to display a text file or a normal response.write(string), there is no problem in launching print dialog but as soon as it is "application/pdf", it just wouldn't show up.
Any ideas?