Print Page | Close Window

Style Individual Table Cells

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=3969
Printed Date: 05 May 24 at 5:13PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Style Individual Table Cells
Posted By: chris_adsi
Subject: Style Individual Table Cells
Date Posted: 25 Jan 22 at 12:22PM
Hi

I am drawing tables onto my document, and I am struggling to format individual table cells.

Ideally I want to make my header/ footers bold text. I have tried just using html bold tags but this does not seem to work with the selected font, which is Century Gothic. Elsewhere in my document when I was to render the font as bold I actually select Century Gothic Bold as the font.

I have tried putting some code in to select the font on a cell by cell basis but that only seems to format the entire table as bold, not individual cells.

With the default font (Arial?) the bold html tags do seem to work.

Any ideas how I can get formatting control with a specific font please?



Replies:
Posted By: Ingo
Date Posted: 25 Jan 22 at 10:48PM
Hi Chris,


i don't know what you've read here in the forum and in the resources so far...
It would be good to see your code (a snippet with the table-syntax) to help.

Here's a thread with a good sample from Rowan:
http://www.quickpdf.org/forum/create-table-exactly-like-this-sample_topic1907.html

Here's a kb-article about how to insert a table into a pdf:
https://www.debenu.com/kb/insert-table-pdf/

Starting your search from here could give you many more results and help:
https://www.debenu.com/docs/pdf_library_reference/Search.php



-------------
Cheers,
Ingo



Posted By: chris_adsi
Date Posted: 26 Jan 22 at 8:34AM
Hi Ingo

Funnily enough it was exactly that first link where I started!

I hadn't seen that second one so wasn't familiar with the concept of the NormalFont BoldFont etc concept - that looks like it may well be what I need so will give it a try. 

This is my code :

    Set flds = FetchDocFields(lngType, lngSect, strUser, 1)
    
    lngFont = objPDF.AddTrueTypeFont(doc.FontName, 0)
    lngRes = objPDF.SelectFont(lngFont)
    'set to default for the table
    lngRes = objPDF.SetHTMLNormalFont("Default", lngFont)
    
    'how many rows?
    For Each fld In flds
        If fld.FieldType = FieldType.Table Then 'table level settings
            colms = fld.DrawOptions
            strBordColour = fld.BorderColour
            dblBordWidth = fld.BorderWidth
        End If
        If fld.FieldType = FieldType.TableRow Then
            rows = rows + 1
        End If
    Next
        
    'create the table skeleton
    lngTable = objPDF.CreateTable(rows, colms)
    
    'Specify color and width of table borders
    If strBordColour <> "" Then
        lngRes = objPDF.SetTableBorderColor(lngTable, 0, GetColourRGB(strBordColour, 0), GetColourRGB(strBordColour, 1), GetColourRGB(strBordColour, 2))
        lngRes = objPDF.SetTableThinBorders(lngTable, 1, GetColourRGB(strBordColour, 0), GetColourRGB(strBordColour, 1), GetColourRGB(strBordColour, 2))
    End If
    If dblBordWidth > 0 Then
        lngRes = objPDF.SetTableBorderWidth(lngTable, 0, dblBordWidth)
    End If
    
    'Specify table row height
    lngRes = objPDF.SetTableRowHeight(lngTable, 1, rows, 0)

    For Each fld In flds
    
        Select Case fld.FieldType
            
            Case FieldType.TableRow
                'resest
                row = row + 1
                ColM = 1
                If fld.Height > 0 Then
                    'Specify row height
                    lngRes = objPDF.SetTableRowHeight(lngTable, row, row, fld.Height)
                End If
                
            Case FieldType.TableCell
                'render cell
                'width
                lngRes = objPDF.SetTableColumnWidth(lngTable, ColM, ColM, fld.Width)
                'alignment
                lngRes = objPDF.SetTableCellAlignment(lngTable, 1, ColM, row, ColM, fld.Alignment)
                'Font Size
                If fld.FontSize > 0 Then
                    lngRes = objPDF.SetTableCellTextSize(lngTable, row, ColM, row, ColM, fld.FontSize)
                End If
                'Border Colour
                If fld.BorderColour <> "" Then
                    lngRes = objPDF.SetTableCellBorderColor(lngTable, row, ColM, row, ColM, 0, fld.BorderColourRGB(0), fld.BorderColourRGB(1), fld.BorderColourRGB(2))
                End If
                'border width
                If fld.BorderWidth > 0 Then
                    lngRes = objPDF.SetTableCellBorderWidth(lngTable, row, ColM, row, ColM, 0, fld.BorderWidth)
                End If
                'background fill
                If fld.BackgroundColour <> "" Then
                    lngRes = objPDF.SetTableCellBackgroundColor(lngTable, row, ColM, row, ColM, fld.BackgroundColourRGB(0), fld.BackgroundColourRGB(1), fld.BackgroundColourRGB(2))
                End If
                'forecolour
                If fld.Colour <> "" Then
                    lngRes = objPDF.SetTableCellTextColor(lngTable, row, ColM, row, ColM, fld.ColourRGB(0), fld.ColourRGB(1), fld.ColourRGB(2))
                End If
                'padding
                If fld.Padding > 0 Then
                    lngRes = objPDF.SetTableCellPadding(lngTable, row, ColM, row, ColM, 0, fld.Padding)
                Else
                    If fld.PadLeft > 0 Then
                        lngRes = objPDF.SetTableCellPadding(lngTable, row, ColM, row, ColM, 1, fld.PadLeft)
                    End If
                    If fld.PadTop > 0 Then
                        lngRes = objPDF.SetTableCellPadding(lngTable, row, ColM, row, ColM, 2, fld.PadTop)
                    End If
                    If fld.PadRight > 0 Then
                        lngRes = objPDF.SetTableCellPadding(lngTable, row, ColM, row, ColM, 3, fld.PadRight)
                    End If
                    If fld.PadBottom > 0 Then
                        lngRes = objPDF.SetTableCellPadding(lngTable, row, ColM, row, ColM, 4, fld.PadBottom)
                    End If
                End If
                'put the actual content in
                lngRes = objPDF.SetTableCellContent(lngTable, row, ColM, fld.FixedValue)
                
                ColM = ColM + 1 'increment column counter
                
        End Select
    
    Next
    
    'Draw the table onto the document
    lngRes = objPDF.DrawTableRows(lngTable, lngXPos, lngYPos, 400, 1, 0)




Posted By: chris_adsi
Date Posted: 26 Jan 22 at 8:46AM
Hi Ingo (again)

The SetHTMLBoldFont did the trick - just needed to make the table row a little larger in height for some reason for it to render OK but that may be the installed fonts.

Just got to work out how to do colspan and rowspan now!

Thanks



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk