Open PDF in a new browser window

2

Implemented a functionality in the system to generate a PDF file using iTextSharp, however it is opening in the same tab, I would like it to be opened in a new browser tab. I tried to use Response.Redirect Response.Write I tried to use target = _blank . And a lot of other things I found on Google, but I've had no success at all. Could someone give a help?

My role is like this

Private Sub gerarPDF(ByVal texto As String, ByVal arquivo As String)

    Dim dTime As DateTime = DateTime.Now
    Dim arquivoPDF = arquivo & dTime.Second & dTime.Millisecond & ".pdf"
    If (arquivo.Contains(".pdf")) Then
        arquivo = arquivo.Replace(".pdf", "")
    End If


    Dim doc As iTextSharp.text.Document = New iTextSharp.text.Document
    iTextSharp.text.pdf.PdfWriter.GetInstance(doc, New FileStream(Request.PhysicalApplicationPath + "\" & arquivoPDF, FileMode.Create))

    Dim img = doc.Add(New iTextSharp.text.Paragraph("JPG"))
    doc.Open()
    For Each E1 As iTextSharp.text.IElement In HTMLWorker.ParseToList(New StringReader(texto), New StyleSheet())
        doc.Add(E1)
    Next
    doc.Close()
    Response.Redirect("~/" & arquivoPDF)
End Sub

Protected Sub btnImprimir_Click(sender As Object, e As EventArgs) Handles btnImprimir.Click
    gerarPDF(txtMensagemHistorico.Text, "HistoricoMsg_")
End Sub
    
asked by anonymous 02.02.2018 / 18:45

0 answers