Jamie Fellrath
asked on
Trying to get PDF to open as "Open,Save,Cancel" instead of as a pop-up.
Hi all,
I have a website that is using the iTextSharp open source functionality to generate a PDF of a gridview on the fly and push it to the user. It's VB.NET. The code is here:
Here's the issue: instead of pushing it to the user with the option to Open or Save the file, it's coming as a pop-up window and many of the browsers are ignoring it because it IS a pop-up. I'd like to do it with the option to open or save, instead.
I'm fairly sure that the problem lies with the code at the end of the Sub:
But I'm not a Javascript guy and frankly I got this from an external website. Does "window.open" have options to change the way this is opened, or should I be using some other code to do this?
Basically, the way this works: the link for this page is on a different page, which opens the link to this page with the "historyDate" parameter. "historyDate" is used with "FundPerformanceForPDF.asp x," and that is a simple gridview on a page that is being used as the source to render into a PDF.
Any help I can get in avoiding using a popup would be most welcome!
Thanks,
Jamie
I have a website that is using the iTextSharp open source functionality to generate a PDF of a gridview on the fly and push it to the user. It's VB.NET. The code is here:
Protected Sub ProcessPDF()
Dim docWorkingDocument As iTextSharp.text.Document = New iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 1, 1, 0, 0)
Dim cssFileLocation As String = ConfigurationManager.AppSettings("PDFPrintCSSlocation").ToString()
'Dim cssText = System.IO.File.ReadAllText("~/Styles/PDFPrint.css")
Dim strHtml As String
Dim strCSS As String
'Dim memStream As New MemoryStream()
Dim strWriterHTML As New StringWriter()
Dim strWriterCSS As New StringWriter()
Dim dateHistory As Date = Request.Params("historyDate")
Server.Execute("FundPerformanceForPDF.aspx?historyDate=" & dateHistory.ToShortDateString(), strWriterHTML)
strHtml = strWriterHTML.ToString()
strWriterHTML.Close()
strWriterHTML.Dispose()
Server.Execute(cssFileLocation, strWriterCSS)
strCSS = strWriterCSS.ToString()
strWriterCSS.Close()
strWriterCSS.Dispose()
Dim strFileShortName As String = "CollegeAdvantage Fund Performance.pdf"
Dim strFileName As String = HttpContext.Current.Server.MapPath("reports\" & strFileShortName)
'Dim srdDocToString As StringReader = Nothing
Try
Dim pdfWrite As PdfWriter
pdfWrite = PdfWriter.GetInstance(docWorkingDocument, New FileStream(strFileName, FileMode.Create))
'srdDocToString = New StringReader(strHtml)
Dim strmHTML As New MemoryStream(Encoding.UTF8.GetBytes(strHtml))
Dim strmCSS As New MemoryStream(Encoding.UTF8.GetBytes(strCSS))
docWorkingDocument.Open()
Dim fontProvider As New XMLWorkerFontProvider(XMLWorkerFontProvider.DONTLOOKFORFONTS)
XMLWorkerHelper.GetInstance().ParseXHtml(pdfWrite, docWorkingDocument, strmHTML, strmCSS)
Catch ex As Exception
Response.Write(ex.Message)
Finally
If Not docWorkingDocument Is Nothing Then
docWorkingDocument.Close()
docWorkingDocument.Dispose()
End If
'If Not srdDocToString Is Nothing Then
' srdDocToString.Close()
' srdDocToString.Dispose()
'End If
End Try
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "myscript", "window.open('reports/" & strFileShortName & "','_blank','location=0,menubar=0,status=0,titlebar=0,toolbar=0');", True)
'Close this page after processing the PDF is done.
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "closePage", "window.open('', '_self', ''); window.close();", True)
End Sub
Here's the issue: instead of pushing it to the user with the option to Open or Save the file, it's coming as a pop-up window and many of the browsers are ignoring it because it IS a pop-up. I'd like to do it with the option to open or save, instead.
I'm fairly sure that the problem lies with the code at the end of the Sub:
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "myscript", "window.open('reports/" & strFileShortName & "','_blank','location=0,menubar=0,status=0,titlebar=0,toolbar=0');", True)
But I'm not a Javascript guy and frankly I got this from an external website. Does "window.open" have options to change the way this is opened, or should I be using some other code to do this?
Basically, the way this works: the link for this page is on a different page, which opens the link to this page with the "historyDate" parameter. "historyDate" is used with "FundPerformanceForPDF.asp
Any help I can get in avoiding using a popup would be most welcome!
Thanks,
Jamie
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oh, yes, instead of window.open
ASKER
That did it! Thank you!
ASKER
Thanks for the help!
No problem :)
ASKER