473,387 Members | 1,904 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,387 software developers and data experts.

How to Display a PDF in a new browser window :)

11
I am trying to re-work a Visual Basic (ASP .NET 2.0) application that delivers a PDF to a user based on requests. I have the appropriate MIME type (Application/pdf) specified but need to open the pdf in a new browser window. Any ideas? I appreciate any and all input
Thanks
Aug 22 '07 #1
10 1842
drhowarddrfine
7,435 Expert 4TB
If you are asking how to do it in vb.net, you should ask on the .net forum.
Aug 22 '07 #2
mudrow1
11
If you are asking how to do it in vb.net, you should ask on the .net forum.
Thank you ... as a 'newbie' to the site I'm still getting my bearings here :)
Aug 23 '07 #3
phvfl
173 Expert 100+
Do you already have the PDF file on the server and so this is linking to it or are you trying to generate the PDF file on the fly and display it to the user?
Aug 26 '07 #4
mudrow1
11
Do you already have the PDF file on the server and so this is linking to it or are you trying to generate the PDF file on the fly and display it to the user?
The pdf files already exist - I am just trying to display their contents albeit in a new browser window once selected
Aug 27 '07 #5
phvfl
173 Expert 100+
As the PDF already exists this is just a matter of getting the HTML correct to link to the file.

To do this through HTML, no scripting required, create an anchor with the href being the location of the file (URL not local file path) and a target attribute of "_blank":
[HTML]
<a href="/test/doc.pdf" target="_blank">document</a>
[/HTML]

The main issue with this is that the target attribute is not valid in XHTML strict. You could also do this using javascript to open the new window. In this case the code would be:
[HTML]
<a href="/test/doc.pdf" onclick="return opendoc();">document</a>
[/HTML]
Expand|Select|Wrap|Line Numbers
  1. function opendoc(){
  2. window.open("/test/doc.pdf", "document name");
  3. return false;
  4. }
  5.  
In the javascript the return false means that the link is not followed. If for any reason javascript is disabled then the link will be followed and the file will open on the same page. A full description of the javascript window.open function can be found here. Be warned that you may find some pop-up blockers may block the new window.
Aug 28 '07 #6
mudrow1
11
As the PDF already exists this is just a matter of getting the HTML correct to link to the file.

To do this through HTML, no scripting required, create an anchor with the href being the location of the file (URL not local file path) and a target attribute of "_blank":
[HTML]
<a href="/test/doc.pdf" target="_blank">document</a>
[/HTML]

The main issue with this is that the target attribute is not valid in XHTML strict. You could also do this using javascript to open the new window. In this case the code would be:
[HTML]
<a href="/test/doc.pdf" onclick="return opendoc();">document</a>
[/HTML]
Expand|Select|Wrap|Line Numbers
  1. function opendoc(){
  2. window.open("/test/doc.pdf", "document name");
  3. return false;
  4. }
  5.  
In the javascript the return false means that the link is not followed. If for any reason javascript is disabled then the link will be followed and the file will open on the same page. A full description of the javascript window.open function can be found here. Be warned that you may find some pop-up blockers may block the new window.
Thanks for the guidance .. this is turning out to be more involved than I initially envisioned :) I appreciate your assistance !
Aug 28 '07 #7
mudrow1
11
Thanks for the guidance .. this is turning out to be more involved than I initially envisioned :) I appreciate your assistance !
I was able to get (closer to) my objective with the proceeding code
[CODE}
Imports System.Diagnostics
Partial Class _Default
Inherits System.Web.UI.Page


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'Shell("command.com /c c:\test.pdf", vbNormalFocus)

Process.Start("c:\test.pdf") ' "IEXplore.exe"


'If IO.File.Exists("C:\test.pdf") = True Then
'System.Diagnostics.Process.Start("C:\test.pdf")


'End If
End Sub


End Class
[/code]

but am still working out the 'kinks' since it works fine in my IDE but doesn't do anything when I move it to our secured web server (and access it via the HTTPS: protocol :) Thanks again - I'm also goign to try the Javascript route that you suggested later this evening - it nothing else I'm learning a lot 'the hard way' :) Thanks!
Aug 28 '07 #8
phvfl
173 Expert 100+
The code that you have would open the new instance of IE on the server, not on the client. This means that if a user clicked the button then they would see nothing but a new browser would open on the server.

If you want this action to be performed on a button click then use the javascript mentioned previously, if you are happy having a link on that is clicked then the standard HTML should work
Aug 29 '07 #9
mudrow1
11
The code that you have would open the new instance of IE on the server, not on the client. This means that if a user clicked the button then they would see nothing but a new browser would open on the server.

If you want this action to be performed on a button click then use the javascript mentioned previously, if you are happy having a link on that is clicked then the standard HTML should work
Thanks! I hadn't detected that glitch but I'm glad you pointed it out .. I went back and got the Javacript to work -- call me an Idiot (but not too loudly!) what would I do without you?
Aug 31 '07 #10
phvfl
173 Expert 100+
Thanks! I hadn't detected that glitch but I'm glad you pointed it out .. I went back and got the Javacript to work -- call me an Idiot (but not too loudly!) what would I do without you?
No problem, it's what we are here for. Easy mistake to make, I've done similar things in the past when first starting out :)
Sep 1 '07 #11

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

Similar topics

3
by: Hemanth | last post by:
Hello there, I've a utility that runs on a linux machine. Basically, it opens a window, draws a figure and captures the image (screen) and stores it as a jpeg file. The utility requires a...
3
by: Bob | last post by:
I am pretty new at C#, so bare with me. I want to be able to read a local HTML file and display it in a browser window within my application. I also want to submit that page to my application and...
3
by: VMI | last post by:
In my web app, how can I display an XML file in another browser window? Can this be done with C#? Thanks.
11
by: Tina | last post by:
I'm in a button clicked event on mainpage.aspx. I want to display a new webpage that has just my image, which is a jpg. I want the page to be a ..jpg not an aspx so that it will be easy for the...
1
by: chazmanian | last post by:
We have a situation where we display PDF files through IE via a method in our code-behind as follows protected void displayPDF(string exePath, string filePath { // exePath is the...
1
by: acool | last post by:
I just plain forgot this setting and I have been all up and down the options and nothing works, any hel is appreciated.
2
by: David Cho | last post by:
I hope I can describe the dilemma precisely. I have code to render PDF output in a browser window (using a third party control that merges PDF files and renders the PDF output in the browser...
9
by: tshad | last post by:
This was posted before but the message got messed up (all NLs were stripped out for some reason). I have 2 labels that hold the name of different images on my .aspx page. <asp:Label ID="Logo"...
3
by: Safalra (Stephen Morley) | last post by:
(Note: I'm not trying to do anything stupid based on the user's screen size - I'm just curious.) At work today I was looking at the visitor statistics for a client website, and noticed that...
2
by: H. Rodriguez | last post by:
Hello, I would like to be able to open a new IE window on the client side and display a PDF document in the new window. Many tutorial sites that I have checked suggest opening a new IE window...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.