Pdf Document Creation Using iTextSharp
public function create_PDF()
Dim hw As New HtmlTextWriter(sw)
Dim pdfDoc As New Document(PageSize.A4, 50, 50, 50, 40)
pdf_file_name = "PdfFileName.pdf"
pdfFilePath = "Path Where The PDF Will save"
'Create Document class object and set its size to letter and give space left, right, Top, Bottom Margin
Dim wri As PdfWriter = PdfWriter.GetInstance(pdfDoc, New FileStream(pdfFilePath, FileMode.Create))
wri.ViewerPreferences = PdfWriter.PageModeUseOutlines
Dim eventHandler As PdfFooter = New PdfFooter()
wri.PageEvent = eventHandler
pdfDoc.Open()
pdfDoc.Add(Create_Head())
pdfDoc.Close()
end function
Private Function Create_Head() As iTextSharp.text.Table
' Create a table having five cell
Dim tbadd As New iTextSharp.text.Table(5)
tbadd.BorderWidth = 0
' tbadd.BorderColor = New iTextSharp.text.Color(0, 0, 0) ' Code for black color
tbadd.BorderColor = New iTextSharp.text.Color(255, 255, 255) ' Code for White color
tbadd.CellsFitPage = True
tbadd.Padding = 1.5
tbadd.Width = 98
'set width Of each cell
Dim widths = New Single() {6, 9, 14, 15, 12}
tbadd.Widths = widths
Dim p As Paragraph = New Paragraph("Ist Cell", verdana)
Dim tc As iTextSharp.text.Cell = New iTextSharp.text.Cell(p)
tc.Header = True
tc.HorizontalAlignment = Element.ALIGN_LEFT
'Marge two cell Among five cell
tc.Colspan = 2
'Code for add a cell in the table
tbadd.AddCell(tc)
tbadd.EndHeaders()
p = New Paragraph("2 nd Cell:", verdana)
tc = New iTextSharp.text.Cell(p)
tc.HorizontalAlignment = Element.ALIGN_LEFT
'Marge three cell Among five cell
tc.Colspan = 3
tc.Header = True
tbadd.AddCell(tc)
tbadd.EndHeaders()
p = New Paragraph("2nd Row Ist Cell", verdana1)
tc = New iTextSharp.text.Cell(p)
tc.HorizontalAlignment = Element.ALIGN_LEFT
' tc.Colspan = 3
tc.Header = True
tbadd.AddCell(tc)
tbadd.EndHeaders()
p = New Paragraph(" 2nd Row 2nd Cell", verdana1)
tc = New iTextSharp.text.Cell(p)
tc.HorizontalAlignment = Element.ALIGN_LEFT
' tc.Colspan = 3
tc.Header = True
tbadd.AddCell(tc)
tbadd.EndHeaders()
p = New Paragraph("2nd Row 3rd cell", verdana1)
tc = New iTextSharp.text.Cell(p)
tc.HorizontalAlignment = Element.ALIGN_LEFT
' tc.Colspan = 3
tc.Header = True
tbadd.AddCell(tc)
tbadd.EndHeaders()
p = New Paragraph("2nd Row forthCell", verdana1)
tc = New iTextSharp.text.Cell(p)
'Alignment of the content of the cell
tc.HorizontalAlignment = Element.ALIGN_LEFT
'Marge three cell Among five cell
'tc.Colspan = 3
tc.Header = True
tbadd.AddCell(tc)
tbadd.EndHeaders()
p = New Paragraph("2nd Row fifth Cell", verdana1)
tc = New iTextSharp.text.Cell(p)
tc.HorizontalAlignment = Element.ALIGN_LEFT
' tc.Colspan = 3
tc.Header = True
tbadd.AddCell(tc)
tbadd.EndHeaders()
Return tbadd
End Function