0

I'm using VB.NET, Framwork 4.5. Visual Studio 2013.

I'm using itextsharp version 5.5.3.0

I'm able to generate correctly a PDF file using memorystream via an aspx page when I pass querystring values and I open the page directly.

However when I try to open that same page in IE9 (sorry, stuck on that in our Enterprise and absolutely cannot change that) via showmodaldialog, the pdf is not showing the "Open" or "Save As.." Dialog, it's just showing a blank page and nothing happens.

Can someone please tell me if there's a catch when using itextsharp when using IE9 and showmodaldialog?

I had to use a hidden iframe and javascript function to load the page in the iframeso it shows the "Open Save as..." dialog in the same window.

It's working with iframe but i'm curious of what is going on with showmodaldialog

Here's the master page code to send the querystring parameters to a modaldialog

case 'report':
            mypage = 'pdfreport.aspx?mode=Individual&loteid=' + $('#IDLabel').text() + '&idah=' + param + '&invid=' + $('#hdfInventoryID').val()
            //alert(mypage)
            var width = '1000'
            var height = '685'
            var left = '20'
            var top = '0'
            break;
    }
    //alert(mypage)
    var r = window.showModalDialog(mypage, 'mywindow', 'left:'+left+';top:'+top+';dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;toolbar:0;resizable:0');

And here's the showmodaldialog code to generate the pdf:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


    Dim document As Document = New Document
    Dim output2 As MemoryStream = New MemoryStream()
    Dim writer As PdfWriter = PdfWriter.GetInstance(document, output2)

    document.SetPageSize(PageSize.LETTER)
    document.SetMargins(50, 50, 25, 25)
    document.Open()
    ''code to generate the pdf document
    document.Close()
    Response.ClearContent()
    Response.ClearHeaders()
    Response.ContentType = "application/pdf"
    Dim filename As String
    filename = "Filename"
    Response.AddHeader("Content-Disposition", String.Format("attachment;filename={0}.pdf", filename))
    Response.BinaryWrite(output2.ToArray())

End Sub
Jose R
  • 738
  • 2
  • 10
  • 26
  • Can you show us the code, its kind of hard to help without it. – Trevor Oct 30 '14 at 01:20
  • 1
    There's two related but very different part of a problem here, 1), making a PDF and 2), transmitting binary content to a browser. For #1, save the file to the server's disk, download it via FTP and sanity check it. Pass all of your query strings and whatever you want and manually transfer and validate each file. Once you're sure that is working, then you can 100% ignore iText and deal only with transferring of binary content to a browser. – Chris Haas Oct 30 '14 at 01:55
  • That's good advice by @ChrisHaas. After you've established that the file is created correctly on disk. You can adapt your application so that it sends a memory stream to the browser (instead of storing the file on disk). If this works for some browsers and not for others, you are experiencing a browser-related problem as opposed to an iTextSharp related problem. Sometimes setting the correct HTTP-headers can help, especially the header that defines the byte size of the PDF stream. See http://itextpdf.com/examples/iia.php?id=173 – Bruno Lowagie Oct 30 '14 at 11:20
  • @ChrisHaas So i should use a `Filestream` instead of `MemoryStream`? How would i download it via FTP and sanity check it? Thanks – Jose R Oct 30 '14 at 14:31
  • Thanks @BrunoLowagie, I will add those headers to see what happens. – Jose R Oct 30 '14 at 14:32
  • @BrunoLowagie i just set the reponse content-size and added the reponse headers.. no luck yet – Jose R Oct 30 '14 at 14:44

1 Answers1

0

Unfortunately I don't have my laptop with me to test this, but it seems that there is a known bug? With showmodaldialog and Page_Load on the opened page, I will try these answers once I get back to work.

Cheers,

Community
  • 1
  • 1
Jose R
  • 738
  • 2
  • 10
  • 26