1: Imports System
2: Imports System.IO
3: Imports iTextSharp.text
4: Imports iTextSharp.text.pdf
5: ...
6: ...
7: ...
8: Private Sub Stampa()
9: Dim memStream As New MemoryStream
10: Dim pdfTemplate As String = GlobalVars.TemplatesPath & "template.pdf"
11: Dim pdfReader As New PdfReader(pdfTemplate)
12: Dim pdfStamper As New PdfStamper(pdfReader, memStream)
13: pdfStamper.Writer.CloseStream = False
14: Dim pdfFormFields As AcroFields = pdfStamper.AcroFields
15: ' Setto i field che voglio valorizzare sul documento PDF
16: ' Checkbox
17: pdfFormFields.SetField("Check1", "1")
18: pdfFormFields.SetField("Check2", "0")
19: ' Campi testuali
20: pdfFormFields.SetField("Text1", "Nome")
21: pdfFormFields.SetField("Text2", "Cognome")
22: ' Rimuovo tutti i fields
23: pdfStamper.FormFlattening = True
24: pdfStamper.Close()
25:
26: ' Faccio direttamente la response del contenuto
27: Response.AppendHeader("content-disposition", "attachment; filename=modulo_utente.pdf")
28: Response.AppendHeader("Content-Length", memStream.Length.ToString)
29: Response.ContentType = "application/pdf"
30: Response.BinaryWrite(memStream.ToArray)
31: Response.Flush()
32: memStream.Close()
33: End Sub