non so dove sia l'errore. Prova se va il codice di sotto
codice:
Option Strict On
Imports t = iTextSharp.text
Imports p = iTextSharp.text.pdf
Partial Class CorsoApogeo_pdf_iTextSharp_test
Inherits System.Web.UI.Page
'Creo Hello World e salvo su flusso uscita
Protected Sub LinkButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton2.Click
Using ms As New MemoryStream()
Dim doc As t.Document = Nothing
Try
doc = New t.Document()
p.PdfWriter.GetInstance(doc, ms)
doc.Open()
CreateDoc(doc)
Catch ex As Exception
l.PrintLn(ex.Message) : Return
Finally
Try
If doc IsNot Nothing AndAlso doc.IsOpen Then doc.Close()
Catch ex As Exception
End Try
End Try
SaveDocOutputStream(ms, "prova.pdf")
End Using
End Sub
Protected Sub CreateDoc(ByVal doc As t.Document)
doc.AddTitle("Titolo")
doc.AddAuthor("Autore")
doc.AddSubject("Argomento")
doc.AddCreator("Test iTextCharp")
doc.Add(New t.Paragraph("Chapter 1 example 1: Hello World"))
End Sub
Protected Sub SaveDocOutputStream(ByVal ms As MemoryStream, ByVal nomeDocumento As String)
'Dim buffer As Byte() = ms.GetBuffer()
Dim buffer As Byte() = ms.ToArray()
ms.Flush()
Response.Clear()
'Response.AddHeader("Content-Disposition", "inline; filename=" & nomeDocumento)
Response.AddHeader("Content-Disposition", "attachment; filename=" & nomeDocumento)
Response.AddHeader("Content-Length", buffer.Length.ToString)
Response.ContentType = "application/pdf"
'Response.ContentType = "application/octet-stream"
If buffer.Length > 0 Then
Me.Response.OutputStream.Write(buffer, 0, buffer.Length)
End If
Response.Flush() : Response.End()
End Sub
End Class