L'esempio che ti propongo è il classico "Hello World!"
Di per se non è molto utile. Lo diventa solo se è il primo di una raccolta di esempi, sempre più complessi, dove si esplorano le diverse possibilità della libreria.
codice:
Imports t = iTextSharp.text
Imports p = iTextSharp.text.pdf
Imports xml = iTextSharp.tool.xml
Imports css = iTextSharp.tool.xml.css
Imports htm = iTextSharp.tool.xml.pipeline.html
Public Class frmTestITextSharp
'Hello World! (FileStream) A4 verticale
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
Dim leggoPdf As Boolean = False
Dim fs As FileStream = Nothing
Try
Me.Cursor = Cursors.WaitCursor
Application.UseWaitCursor = True
Dim fileCreato As String = "c:\tmp\prova.pdf"
fs = New FileStream(fileCreato, FileMode.Create)
Dim document As t.Document = Nothing
Try
'creo il documento iTextSharp: predefinito A4, margine di 36 punti, verticale
'1pt = 0.35278 mm; 1mm = 2.8346 pt
document = New t.Document()
'creo una istanza di PdfWriter
Dim writer As p.PdfWriter = p.PdfWriter.GetInstance(document, fs)
'apro il documento
document.Open()
'aggiungo contenuto
document.Add(New t.Paragraph("Hello World!"))
document.Add(New t.Paragraph("Hello World!"))
leggoPdf = True
Catch ex As Exception
Throw
Finally
Try
'chiudo il documento
If document IsNot Nothing AndAlso document.IsOpen Then document.Close()
If leggoPdf Then
Try
'apro il file col programma predefinito
l.AproFileConProgrammaPredefinito(fileCreato)
Catch ex As Exception
Throw
End Try
End If
Catch ex As Exception
Throw
End Try
End Try
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
If fs IsNot Nothing Then fs.Dispose()
Application.UseWaitCursor = False
Me.Cursor = Cursors.Default
End Try
End Sub
End Class