Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
when i export to pdf then heders font are small and other cells are biger size.
i can mention size of font but not done.

What I have tried:

<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()
Posted
Comments
Richard Deeming 23-May-18 13:12pm    
That would be because you're telling your headers to render at 8pt, but letting your data rows use whatever the default font size is.
Arnav121 24-May-18 3:54am    
how to render data rows font have any idea?
Richard Deeming 24-May-18 6:58am    
In exactly the same way you do for the header row.
Arnav121 5-Jun-18 4:51am    
tell me like example
Richard Deeming 5-Jun-18 9:04am    
Replace:
pdfTable.AddCell(cell.Value.ToString())

with:
Dim cell As New PdfPCell(New Phrase(cell.Value.ToString(), mainFont))
pdfTable.AddCell(cell)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900