2
I implemented a functionality in the system to generate a PDF file using iTextSharp, but this opening in the same tab, I would like it to be opened in a new browser tab. I tried to use the Response.Redirect
Response.Write
I tried to use the target = _blank
. And a lot of other things I found on Google, but I didn’t have any success. Someone could help?
My function 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
Good morning I’m having the same doubt you managed to resolve ?
– Denilson Carlos