Opening a PDF File

btisdabomb

Member
Joined
Jul 12, 2006
Messages
16
Programming Experience
Beginner
I have an ASP.NET page that creates a set of .PDF files. It then appends them into one big PDF file and saves them to a location on a server.

What is the best way to open this new file in Adobe and still have the .aspx page running?
 
Are you trying to open the pdf within the current aspx page or simply want to open it while maintaining your aspx one seperately?

if you don't need it to be embedded in the current aspx page then just open it in a seperate window/tab with Javascript.

' open pdf in new window example
response.write("<script>window.open('http:/'MyCompanyName.com/MyDocumentName.pdf')</script>")


We use a third party API to generate pdf's dynamically and then display them by writing the pdf as a binary stream (from memory) to the browser in an aspx page. If that is the kind of thing you are talking about then you would need to do something like:

Dim BinImage as Object
' ...
' insert pdf into BinImage
' ...
Response.ContentType = "application/pdf"
Response.AddHeader("Content-Type", "application/pdf")
Response.AddHeader("Content-Disposition", "inline;filename=MyDocument.pdf")
Response.BinaryWrite(BinImage)


Hope that helps.
 
Well here is the code I am currently using... however, it doesn't seem to work everytime. While I am debugging and step through the code, sometimes the file doesn't open, or sometimes the .aspx page just hangs there.

VB.NET:
Private Sub OpenPdfFile(ByVal strReport As String)
        Dim path As String = strReport
        Dim client As New System.Net.WebClient
        Dim buffer As Byte() = client.DownloadData(path)

        If buffer IsNot Nothing Then
            Response.ContentType = "application/pdf"
            Response.AddHeader("content-length", buffer.Length.ToString())
            Response.BinaryWrite(buffer)
        End If

    End Sub

This code gets executed on the click of a button. What I need is for this PDF file to open and for the page to refresh.
 
Back
Top