here is the code
Imports System.IO
Imports System.Reflection
Imports iTextSharp.text
Imports iTextSharp.text.pdf
'Creating iTextSharp Table from the DataTable data
Dim pdfTable As New PdfPTable(Datagrid.ColumnCount)
pdfTable.DefaultCell.Padding = 30
pdfTable.WidthPercentage = 150
pdfTable.HorizontalAlignment = Element.ALIGN_LEFT
pdfTable.DefaultCell.BorderWidth = 1
'Adding Header row
For Each column As DataGridViewColumn In Datagrid.Columns
Dim cell As New PdfPCell(New Phrase(column.HeaderText))
'cell.BackgroundColor = New iTextSharp.text.Color(240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240)
pdfTable.AddCell(cell)
Next
'Adding DataRow
For Each row As DataGridViewRow In Datagrid.Rows
For Each cell As DataGridViewCell In row.Cells
pdfTable.AddCell(Convert.ToString(cell.Value))
Next
Next
'Exporting to PDF
Dim folderPath As String = "C:\Inventory System\"
If Not Directory.Exists(folderPath) Then
Directory.CreateDirectory(folderPath)
End If
Using stream As New FileStream(folderPath & "Inventory Data.pdf", FileMode.Create)
Dim pdfDoc As New Document(PageSize.A2, 10.0F, 10.0F, 10.0F, 0.0F)
PdfWriter.GetInstance(pdfDoc, stream)
pdfDoc.Open()
pdfDoc.Add(pdfTable)
pdfDoc.Close()
stream.Close()
End Using
End Sub