473,385 Members | 1,267 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 4036
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

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

Similar topics

1
by: Radx | last post by:
Hello All I am having a very hard timt exporting crystal report to PDF document in my ASPX page. I am able to generate the PDF document , but the i am not able to pass the parameter to the...
0
by: Michael | last post by:
I have a problem forcing files to download. If I select Save the document is saved with no problems. If I select "Open" the document is empty or I get a "File not found" error from the application...
6
by: A.M-SG | last post by:
Hi, I have an aspx page at the web server that provides PDF documents for smart client applications. Here is the code in aspx page that defines content type: Response.ContentType =...
2
by: AP No spam | last post by:
Hi I need help to Print Pdf File directly without preview from client side To solve problem I used This C# code Response.Buffer = true;
1
by: Mustufa Baig | last post by:
I have an ASP.NET website where I am showing off crystal reports to users by exporting them to pdf format. Following is the code: ---------------- 1 Private Sub ExportReport() 2 Dim oStream...
0
by: csgraham74 | last post by:
Hi there again, I wonder if someone could help or advise me on my issue. i have created a menu control which i use to print out documents in pdf. the code that does it is below (see pdf code)....
1
by: DB | last post by:
Hi All, I’m trying to stream a PDF with .NET 2.0 in a c# web app. However, it does not actually show the PDF (using adobe acrobat). The Situation: Click on a Button, Opens a new Window,...
3
by: Cindy H | last post by:
Hi I have a webpage with a link to a pdf file on it. Right now the user has to click on the pdf file link to open and display the file. Does anyone know how I can get the web page to just open...
17
by: mansb2002 | last post by:
Hi, We recently moved our webserver from Win2K to Win2003. The application works fine. Only problem is that when user views a report as a PDF, IE does not show it. The following code is used to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.