<pre> Dim pdfTable As New PdfPTable(DataGridView1.ColumnCount) pdfTable.DefaultCell.Padding = 3 pdfTable.WidthPercentage = 100 pdfTable.HorizontalAlignment = Element.ALIGN_LEFT pdfTable.DefaultCell.BorderWidth = 1 Dim yourFont As BaseFont = BaseFont.CreateFont("c:\windows\fonts\arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED) Dim mainFont As New Font(yourFont, 8, Font.Bold) 'Adding Header row For Each column As DataGridViewColumn In DataGridView1.Columns Dim cell As New PdfPCell(New Phrase(column.HeaderText, mainFont)) cell.BackgroundColor = New iTextSharp.text.BaseColor(240, 240, 240) pdfTable.AddCell(cell) Next 'Adding DataRow For Each row As DataGridViewRow In dataGridView1.Rows For Each cell As DataGridViewCell In row.Cells pdfTable.AddCell(cell.Value.ToString()) Next Next 'Exporting to PDF ' SaveFileDialog1.FileName = "" ' SaveFileDialog1.Filter = "PDF (*.pdf)|*.pdf" ' Dim folderPath As String = SaveFileDialog1.ShowDialog 'Using stream As New FileStream(folderPath & "", 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 Dim SaveFileDialoga = New SaveFileDialog() SaveFileDialoga.Filter = "PDF Files|*.pdf" SaveFileDialoga.FilterIndex = 0 If (SaveFileDialoga.ShowDialog() = DialogResult.OK) Then End If Dim myDocument = New Document(iTextSharp.text.PageSize.A4, 10.0F, 10.0F, 10.0F, 10.0F) PdfWriter.GetInstance(myDocument, New FileStream(SaveFileDialoga.FileName, FileMode.Create)) myDocument.Open() myDocument.Add(pdfTable) myDocument.Close()
pdfTable.AddCell(cell.Value.ToString())
Dim cell As New PdfPCell(New Phrase(cell.Value.ToString(), mainFont)) pdfTable.AddCell(cell)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)