Hi everyone, I have a question about openning a pdf file in browser and wonder if anybody has idea about how to do that.
What I want to accompolish is: There is a button "Open PDF" on my web page. When the user clicks this button, a specific pdf file should be opened and displayed in the current browser or a new browser. Please note that I do NOT want a dialog to be popped up to ask users to "Save File" or "Open File". Does anybody know how to do that? As far as I know, i can user Response.Redirect("xxx.pdf"). But the known problem of using this method is that the pdf file doesn't show up until the Refresh button is clicked.
Thanks in advance for any help.
Hi,
You need to set the Content Type of the Response object and add the binary form of the pdf in the header. See this post for details:
http://geekswithblogs.net/azamsharp/archive/2005/09/18/54294.aspx
HTH,
Vivek
Hi Vivek,
In this way, it still pops up a dialog to ask users if they want to save or open the pdf file. Are there any ways to get rid of the popup?
Thank you so much!
All I've ever done was link to the pdf
<a href="http://links.10026.com/?link=pdf location">PDF</a>
and it opens in the window just like you're asking.
2 more links
http://www.developerfusion.co.uk/forums/thread/101074/#101074
but i think it's probably client side setting
http://dotnetjunkies.com/Forums/ShowPost.aspx?PostID=11112
here's some code I use
Private Sub get_assignd_btn_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles get_assignd_btn.Clickoops . I see after posting that I used reportviewer - maybe you can still use it
Dim myBytes()As Byte
Dim mimeTypeAs String =Nothing
Dim EncodingAs String =Nothing
Dim extensionAs String ="PDF"
Dim streamids()As String =Nothing
Dim warnings()As Microsoft.Reporting.WebForms.Warning =Nothing
Me.ObjectDataSource1.DataBind()
Me.ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WebForms.ReportDataSource("assigned",Me.ObjectDataSource1))
Me.ReportViewer1.LocalReport.Refresh()
myBytes = ReportViewer1.LocalReport.Render("PDF",Nothing, mimeType, Encoding, extension, streamids, warnings)Response.Buffer =True
Response.Clear()
Response.ContentType = mimeType
Response.AddHeader("content-disposition","attachment; filename=assigned_calls." + extension)
Response.BinaryWrite(myBytes)
Response.Flush()
Response.End()
End Sub
You can never determine how a browser will act. If the browser doesn't have the Acrobat plugin then it will never open within the browser, regardless of what headers you send. If the browser is set up to save .PDF files rather than use the plugin then it won't display either. There are many browsers on the market and each can be configured to react differently and each will have different dialogue boxes. You can never determine how every situation will be, not should you be able to - it's ultimately up to a user's preference. Imagine, for instance, if you could force execution of an .EXE simply by getting rid of a dialogue?
0 comments:
Post a Comment