Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Jan 12, 2021 5:05 pm

I am trying to display a tick ✓ and a black box ▀ in a pdf table - I create the records for the table with these values in but they appear as blank. What am I doing wrong?
Code: Select all
         Dim tempfont6 As New System.Drawing.Font("Arial", 6.0F, FontStyle.Regular)
        f6 = New PdfTrueTypeFont(tempfont6)
        Dim tempfont8 As New System.Drawing.Font("Arial", 8.0F, FontStyle.Regular)
        f8 = New PdfTrueTypeFont(tempfont8)
        HeadFont = f8
        BodyFont = f6
        Dim table As New PdfTable
        table.Style.CellPadding = 3
        table.Style.HeaderSource = PdfHeaderSource.ColumnCaptions
        table.Style.HeaderRowCount = 1
        table.DataSource = report_dt
        table.Style.ShowHeader = True
        table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.White
        table.Style.HeaderStyle.Font = HeadFont
        table.Style.HeaderStyle.StringFormat = New PdfStringFormat(PdfTextAlignment.Left)
        table.Style.DefaultStyle.StringFormat = New PdfStringFormat(PdfTextAlignment.Left)
        table.Style.HeaderStyle.TextBrush = PdfBrushes.Red
        table.Style.HeaderStyle.BorderPen = New PdfPen(PdfBrushes.Black)
        table.Style.DefaultStyle.BorderPen = New PdfPen(PdfBrushes.Blue)
        table.Style.BorderPen = New PdfPen(PdfBrushes.Blue)
        table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.White
        table.Style.DefaultStyle.Font = BodyFont

        Dim Last_Col As Integer = this_col - 1
        For rowno = 0 To Member_DS.Tables(0).Rows.Count - 1
            Dim report_row As DataRow = report_dt.NewRow()
            For colno = 0 To Member_DS.Tables(0).Columns.Count - 1
                Dim this_width = BodyFont.MeasureString(Member_DS.Tables(0).Rows(rowno).Item(colno).ToString).Width '* 1.5
                For col_rowno As Integer = 0 To Last_Col
                    If col_names(col_rowno) = Member_DS.Tables(0).Columns(colno).ColumnName Then
                        If colno >= ColumnDateStart Then
                            Dim thisvalue As String = Member_DS.Tables(0).Rows(rowno).Item(colno).ToString
                            If thisvalue = "Y" Then
                                thisvalue = "✓"
                            Else
                                If thisvalue = "X" Then
                                    thisvalue = "▀"
                                Else
                                End If
                            End If
                            report_row.Item(col_rowno) = thisvalue
                        Else
                            report_row.Item(col_rowno) = Member_DS.Tables(0).Rows(rowno).Item(colno)
                            If col_widths(col_rowno) < this_width Then
                                col_widths(col_rowno) = this_width
                            End If
                        End If
                    End If
                Next
            Next
            report_dt.Rows.Add(report_row)


BigAl1958
 
Posts: 11
Joined: Thu Jun 08, 2017 3:45 pm

Wed Jan 13, 2021 7:36 am

Hello,

Kindly note that some fonts do not support drawing the glyph "✓" and "▀", you need to use a font that supports these glyph. Please refer to the following code. If there are any issues, please provide your runnable project and your desired output to help us investigate further.
Code: Select all
        '......
        Dim tempfont6 As New System.Drawing.Font("Segoe UI Symbol", 6.0F, FontStyle.Regular)
        f6 = New PdfTrueTypeFont(tempfont6, True)
        Dim tempfont8 As New System.Drawing.Font("Segoe UI Symbol", 8.0F, FontStyle.Regular)
        f8 = New PdfTrueTypeFont(tempfont8, True)
        HeadFont = f8
        BodyFont = f6
        Dim table As New PdfTable
        '......


Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Wed Jan 13, 2021 9:42 am

That works but is it possible to use a different font in a particular cell or column?

BigAl1958
 
Posts: 11
Joined: Thu Jun 08, 2017 3:45 pm

Wed Jan 13, 2021 10:55 am

Hello,

Sorry to tell you that for PdfTable, it is not possible to use a different font in a particular cell or column. But our PdfGrid supports setting different fonts for each cell. Below is the corresponding code for your reference. You can give it a try on your side.
Code: Select all
        'Load Pdf from disk
        Dim doc As New PdfDocument()

        'Add a page
        Dim page As PdfPageBase = doc.Pages.Add(PdfPageSize.A4, New PdfMargins(5))

        Dim grid As PdfGrid = New PdfGrid
        grid.Columns.Add()
        grid.Rows.Add()
        grid.Rows.Add()
        grid.Rows(0).Cells(0).Value = "abcde"
        grid.Rows(1).Cells(0).Value = "✓"

        'Set the cell font in the first row and first column of the grid to a new font
        grid.Rows(0).Cells(0).Style.Font = New PdfTrueTypeFont(New Font("Arial", 12.0F), True)
        grid.Rows(1).Cells(0).Style.Font = New PdfTrueTypeFont(New Font("Segoe UI Symbol", 12.0F), True)
        grid.Draw(page, New PointF(100, 200))
        doc.SaveToFile("result.pdf")


Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Wed Jan 13, 2021 6:49 pm

Ok - I have got that working but the text in the whole grid is appearing in BOLD type even though I am not using a Bold font anywhere.

Each cell I set the font to either 'Arial' or 'Segoe UI Symbol' with FontStyle.Regular - am I missing a setting somewhere?

Code: Select all
        Dim tempdatesfont As New System.Drawing.Font("Segoe UI Symbol", 8.0F, FontStyle.Regular)
        datesfont = New PdfTrueTypeFont(tempdatesfont, True)
        Dim tempheadfont As New System.Drawing.Font("Arial", CSng(TheFont), FontStyle.Regular)
        HeadFont = New PdfTrueTypeFont(tempheadfont)
        Dim tempbodyfont As New System.Drawing.Font("Arial", CSng(TheFont + 2), FontStyle.Regular)
        BodyFont = New PdfTrueTypeFont(tempbodyfont)

        Rept = New PdfDocument
        Rept.PageSettings.Margins = New PdfMargins(0)
        TheMargin = New PdfMargins(20, 65, 10, 20)

        If Portrait = True Then
            Rept.PageSettings.Orientation = PdfPageOrientation.Portrait
            Dim newTheMargin As PdfMargins = New PdfMargins(TheMargin.Left, 0, TheMargin.Right, TheMargin.Bottom)
            page = Rept.Pages.Add(PdfPageSize.A4, newTheMargin, PdfPageRotateAngle.RotateAngle0, PdfPageOrientation.Portrait)
        Else
            Rept.PageSettings.Orientation = PdfPageOrientation.Landscape
            Rept.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle90
            Dim newTheMargin As PdfMargins = New PdfMargins(TheMargin.Left, 0, TheMargin.Right, TheMargin.Bottom)
            page = Rept.Pages.Add(PdfPageSize.A4, newTheMargin, PdfPageRotateAngle.RotateAngle0, PdfPageOrientation.Landscape)
        End If

        Rept.Template.Top = CreateHeaderTemplate(Rept, TheMargin)
        Rept.Template.Bottom = CreateFooterTemplate(Rept, TheMargin)
       Dim grid As PdfGrid = New PdfGrid
        grid.Style.Font = BodyFont
        grid.Style.CellPadding = New PdfPaddings(1, 1, 1, 1)
        grid.RepeatHeader = True
        grid.Style.TextPen = New PdfPen(PdfBrushes.Black, 1)
        grid.Style.TextBrush = PdfBrushes.Black
        For rowno = 0 To Member_DS.Tables(0).Rows.Count - 1
            For colno = 0 To Member_DS.Tables(0).Columns.Count - 1
                Dim this_width = BodyFont.MeasureString(Member_DS.Tables(0).Rows(rowno).Item(colno).ToString).Width * 1.5
                For col_rowno As Integer = 0 To Last_Col - 1
                    If col_names(col_rowno) = Member_DS.Tables(0).Columns(colno).ColumnName Then
                        Dim thisvalue As String = Member_DS.Tables(0).Rows(rowno).Item(colno).ToString
                        If col_headers(col_rowno) = "Amt" And varRegisterShowValue = "N" Then
                            thisvalue = "✓"
                            grid.Rows(rowno).Cells(col_rowno).Style.Font = datesfont
                            grid.Rows(rowno).Cells(col_rowno).Value = thisvalue
                            grid.Columns(col_rowno).Format.Alignment = PdfTextAlignment.Center
                        Else
                            If colno >= ColumnDateStart Then
                                If thisvalue = "Y" Then
                                    thisvalue = "✓"
                                    grid.Rows(rowno).Cells(col_rowno).Style.Font = datesfont
                                    grid.Rows(rowno).Cells(col_rowno).Value = thisvalue
                                    grid.Columns(col_rowno).Format.Alignment = PdfTextAlignment.Center
                                Else
                                    If thisvalue = "X" Then
                                        thisvalue = "▀▀▀"
                                        grid.Rows(rowno).Cells(col_rowno).Style.Font = datesfont
                                        grid.Rows(rowno).Cells(col_rowno).Value = thisvalue
                                        grid.Columns(col_rowno).Format.Alignment = PdfTextAlignment.Center
                                    Else
                                        grid.Rows(rowno).Cells(col_rowno).Style.Font = BodyFont
                                        grid.Rows(rowno).Cells(col_rowno).Value = Member_DS.Tables(0).Rows(rowno).Item(colno).ToString
                                        grid.Columns(col_rowno).Format.Alignment = PdfTextAlignment.Center
                                    End If
                                End If
                            Else
                                If col_headers(col_rowno) = "Pos" Or col_headers(col_rowno) = "Dt Pd" Then
                                    grid.Columns(col_rowno).Format.Alignment = PdfTextAlignment.Center
                                End If
                                If this_width > col_widths(col_rowno) Then
                                    col_widths(col_rowno) = this_width
                                End If
                                grid.Rows(rowno).Cells(col_rowno).Style.Font = BodyFont
                                grid.Rows(rowno).Cells(col_rowno).Value = thisvalue
                            End If
                        End If
                    End If
                Next
            Next
        Next
        Dim TableWidth As Decimal = 0
        Dim headerRow As PdfGridRow
        headerRow = grid.Headers.Add(1)(0)
        For rowno = 0 To Last_Col - 1
            headerRow.Cells(rowno).Value = col_headers(rowno)
            If col_widths(rowno) < 30 Then
                col_widths(rowno) = 30
            End If
            TableWidth += CDec(col_widths(rowno))
            grid.Columns(rowno).Width = CSng(col_widths(rowno))
        Next
        Dim offset As Single = ((Rept.PageSettings.Width - TableWidth) / 2) + 20
        grid.Draw(page, offset, 70, TableWidth)
   

BigAl1958
 
Posts: 11
Joined: Thu Jun 08, 2017 3:45 pm

Thu Jan 14, 2021 8:12 am

Hello,

Thanks for your feedback.
Regarding the “BOLD” issue, after further investigation and testing, I found this is because that you set a large value for the parameter “width” in the line "grid.Style.TextPen = New PdfPen(PdfBrushes.Black, 1)”. Please try to set a smaller value, like the following code snippet.
Code: Select all
        'grid.Style.TextPen = New PdfPen(PdfBrushes.Black, 1)
        grid.Style.TextPen = New PdfPen(PdfBrushes.Black, 0.1)


If there are any other questions, please do not hesitate to contact us.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Fri Jan 22, 2021 8:20 am

Work's perfectly

BigAl1958
 
Posts: 11
Joined: Thu Jun 08, 2017 3:45 pm

Fri Jan 22, 2021 10:01 am

Hello,

I am glad to hear that my code can solve your issue.
If you encounter any issues related to our products in the future, please feel free to contact us.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.PDF