Ok, getting a little closer to the goal, if IE7 didn’t exist I’d be done…
Here’s what I’ve got going so far.
On my page that is to launch the PDF I have an imagebutton. When that button is clicked the post back runs a program to collect some data.
It then saves the data to state like so:
Code:
Dim SID As New ArrayList
Session.Clear()
Session.Add("InvoiceSID", SID)
SID.Add(StudentID)
Session("InvoiceSID") = SID
Then if the user preference is to open a new tab it runs this code.
Code:
If Page.FindControl("HiddenURL") Is Nothing Then
Page.ClientScript.RegisterHiddenField("HiddenURL", "URL to PDFInvoice")
Else
CType(Page.FindControl("HiddenURL"), HiddenField).Value = "URL to PDFInvoice"
End If
Dim myScript As String = "if (document.getElementById(""HiddenURL"").value !=
""""){window.open(document.getElementById(""HiddenURL"").value, ""_blank"");
document.getElementById(""HiddenURL"").value = """";}"
Page.ClientScript.RegisterClientScriptBlock(Page.GetType, "ScriptFunction", myScript, True)
If the user preference is to open in same window it runs this code.
Code:
Response.Redirect("URL To PDFInvoice")
On my page that is to “catch” this request and build the PDF I have this code in the ASCX
Code:
<h1>ERROR Launching PDF!</h1>
Ooo-ahh, I know… It’s just there in case something goes wrong. In the ASCX.VB I have this code:
Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim SID As New ArrayList
SID = Session("InvoiceSID")
'MakeInvoice(SID) 'MakeInvoice() is >300 lines of code
MakeTest() 'for this example I’ll use MakeTest()
End If
End Sub
Private Sub MakeTest()
' Create a new PDF document
Dim document As PdfDocument = New PdfDocument
' Create an empty page
Dim page As PdfPage = document.AddPage
page.Orientation = PageOrientation.Landscape
'Create fonts
Dim Helvetica10 As XFont = New XFont("Helvetica", 10, XFontStyle.Regular)
' Get an XGraphics object for drawing
Dim gfx As XGraphics = XGraphics.FromPdfPage(page)
Dim L As Double = 2.0
'Put string
gfx.DrawString("Hello?", Helvetica10, XBrushes.Black, L, 72)
' Send Document to the browser
Dim stream As MemoryStream = New MemoryStream
document.Save(stream, False)
Response.Clear()
Response.ContentType = "application/pdf"
Response.AddHeader("content-length", stream.Length.ToString)
Response.BinaryWrite(stream.ToArray)
Response.Flush()
stream.Close()
Response.End()
End Sub
All that said… it all works perfect in Firefox and Safari. In IE7 only the option to open in the same window works. If you try and open in a new tab IE7 will open the tab and shows a blank screen.
Here is the code view.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
<BODY></BODY></HTML>
The kicker is, If I comment out” MakeTest()” I get my “ERROR launching PDF!” message. So, it must be trying to make the PDF but for some reason it's braking. Moreover, why is it only breaking when I open in new tab? It’s the same code that runs when you open it in the same and in a new tab.
I’m at a loss as to what I should do next do you have any thoughts or suggestions?
Thanks, Nathan Rover