locked
Stream PDF Fails in Edge Browser RRS feed

  • Question

  • User1510859543 posted

    I have a process to stream a SSRS report to a browser.  After creating (saving) the report to a PDF file I send the file to the asp.net function below.  It works perfectly in every browser except Microsoft Edge.  When I run it in Edge it gives me the error page text below.

    Couldn't open PDF
    Something's keeping this PDF from opening.

    Some additional information as I found out that the failure is occurring prior to the MergePDFs function noted below.  It is failing in the process to stream the PDF using error and code below.

    The process cannot access the file '\\lifedev2012\Apps\LifeTime\OfficeDocs\Export\ARAgingReport1136.pdf' because it is being used by another process.

    Dim result As Byte() = Nothing
    
    Dim stream As FileStream
    
    ...more code here to generate report
    
    result = rs.Render(format, devInfo, extension, encoding, mimeType, warnings, streamIDs)
    execInfo = rs.GetExecutionInfo()
    
    'is failing on line below   
    stream = File.Create(strFullPath, result.Length)

    If I open the file from Windows Explorer it opens perfectly in Adobe Reader.  Any ideas?

        Public Shared Sub MergePDFs(ByVal files As List(Of String), ByVal filename As String)
            'Gets a list of full path files and merges into one memory stream
            'and outputs it to a browser response.
            Dim MemStream As New System.IO.MemoryStream
            Dim doc As New iTextSharp.text.Document
            Dim reader As iTextSharp.text.pdf.PdfReader
            Dim numberOfPages As Integer
            Dim currentPageNumber As Integer
            Dim writer As iTextSharp.text.pdf.PdfWriter = iTextSharp.text.pdf.PdfWriter.GetInstance(doc, MemStream)
            doc.Open()
            Dim cb As iTextSharp.text.pdf.PdfContentByte = writer.DirectContent
            Dim page As iTextSharp.text.pdf.PdfImportedPage
            Dim strError As String = ""
    
            For Each strfile As String In files
                reader = New iTextSharp.text.pdf.PdfReader(strfile)
                numberOfPages = reader.NumberOfPages
                currentPageNumber = 0
                Do While (currentPageNumber < numberOfPages)
                    currentPageNumber += 1
                    doc.SetPageSize(reader.GetPageSizeWithRotation(currentPageNumber))
                    doc.NewPage()
                    page = writer.GetImportedPage(reader, currentPageNumber)
                    cb.AddTemplate(page, 0, 0)
                Loop
            Next
            doc.Close()
            doc.Dispose()
    
            If MemStream Is Nothing Then
                HttpContext.Current.Response.Write("No Data is available for output")
            Else
                HttpContext.Current.Response.Clear()
                HttpContext.Current.Response.ContentType = "application/pdf"
                HttpContext.Current.Response.AppendHeader("Content-Disposition", "inline; filename=" + filename)
                HttpContext.Current.Response.BinaryWrite(MemStream.ToArray)
                HttpContext.Current.Response.OutputStream.Flush()
                HttpContext.Current.Response.OutputStream.Close()
                HttpContext.Current.Response.OutputStream.Dispose()
                MemStream.Close()
                MemStream.Dispose()
            End If
        End Sub

    Wednesday, February 3, 2016 5:08 PM

Answers

  • User1510859543 posted

    Resolved the error by putting the file create into a Using similar to below.

    Using stream As FileStream = File.Create(strFullPath, result.Length)

                stream.Write(result, 0, result.Length)

    End Using

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 3, 2016 6:40 PM