470,831 Members | 1,652 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,831 developers. It's quick & easy.

ASP.NET: Executing Javascript when Response.ContentType is 'application/pdf'

Hi,
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
  1.         FileStream fs = new FileStream(@"C:\somefile.pdf", FileMode.Open);
  2.         Byte[] buffer = new byte[fs.Length];
  3.         fs.Read(buffer, 0, (int)fs.Length);
  4.         fs.Close();
  5.         Response.ContentType = "application/pdf";
  6.         Response.BinaryWrite(buffer);
  7.         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?
Sep 2 '08 #1
1 3828
Curtis Rutland
3,256 Expert 2GB
Well, the browsers are loading a third party object to render a PDF, not their own engine. And since I don't think that PDFs support javascript, I don't think that you will be able to do that. Perhaps you should open this PDF in another window, and do a javascript popup from the main window.
Sep 2 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Mustufa Baig | last post: by
reply views Thread by csgraham74 | last post: by
1 post views Thread by DB | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.