cell vertical alignment issue...

cell vertical alignment issue...

Forum member · May 30, 2013
Hi, I'm having an issue with the cell vertical alignment and cell height calculation when using standard windows fonts. I'm pasting code below that demonstrates the problem. The example creates two tables, one using the internal fonts and the other using a common windows font. In both tables, the row height is set so that it grows to accommodate the text. In the case of the windows font, the cell/row height appears to grow much larger than necessary. That also causes the vertical alignment to be off. Is there anything I can do to either fix the cell/row height calculation...or limit the growth of the cell/row so that it does not grow larger than necessary? Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Try Dim doc As Document = New Document Dim Pg As Page = New Page(PageSize.Letter, PageOrientation.Portrait, 18.0F) Dim t1 As Table2 = New Table2(10, 100, 300, 200) With t1 .Border.LineStyle = LineStyle.None .CellDefault.Border.LineStyle = LineStyle.Solid .CellDefault.Border.Width = 0.5 .CellDefault.Font = ceTe.DynamicPDF.Font.Helvetica .CellDefault.FontSize = 10 .CellDefault.VAlign = VAlign.Center .CellDefault.Padding = New CellPadding(0) For i = 1 To 5 .Columns.Add(50) Next For i = 1 To 5 Dim r As Row2 = .Rows.Add(10) For i2 = 1 To 5 Dim c As Cell2 = r.Cells.Add("Item[" & i.ToString & ":" & i2.ToString & "]") c.VAlign = VAlign.Center Next Pg.Elements.Add(New Label("Row " & i.ToString & " height = " & r.ActualRowHeight.ToString, 400, 100 + (i * 15), 200, 15, ceTe.DynamicPDF.Font.Helvetica, 10)) Next End With Pg.Elements.Add(t1) Dim Font_Calibri As ceTe.DynamicPDF.Text.OpenTypeFont = Nothing Font_Calibri = New ceTe.DynamicPDF.Text.OpenTypeFont("C:\Windows\Fonts\Calibri.ttf") Font_Calibri.Embed = True Font_Calibri.Subset = False Dim t2 As Table2 = New Table2(10, 300, 300, 200) With t2 .Border.LineStyle = LineStyle.None .CellDefault.Border.LineStyle = LineStyle.Solid .CellDefault.Border.Width = 0.5 .CellDefault.Font = Font_Calibri .CellDefault.FontSize = 10 .CellDefault.VAlign = VAlign.Center .CellDefault.Padding = New CellPadding(0) For i = 1 To 5 .Columns.Add(50) Next For i = 1 To 5 Dim r As Row2 = .Rows.Add(10) For i2 = 1 To 5 Dim c As Cell2 = r.Cells.Add("Item[" & i.ToString & ":" & i2.ToString & "]") c.VAlign = VAlign.Center Next Pg.Elements.Add(New Label("Row " & i.ToString & " height = " & r.ActualRowHeight.ToString, 400, 300 + (i * 15), 200, 15, ceTe.DynamicPDF.Font.Helvetica, 10)) Next End With Pg.Elements.Add(t2) doc.Pages.Add(Pg) doc.Draw("C:\PDFTesting\Example.pdf") Catch ex As Exception MsgBox(ex.ToString) End Try End Sub

Re: cell vertical alignment issue...

Support · May 31, 2013
Hello, The DynamicPDF API calculates the height required to fit the text in the cell using the font details which you are using. There is nothing in our DynamicPDF API which is adding more height to the row or cell when you use windows fonts other than internal fonts since the height depends on the font and font size you are using. You can try using the below code which gets the height of the text and check for the text heights using different fonts. Dim str As String = "Item[" & 1 & ":" & 1 & "]" Dim fontHelovetica As ceTe.DynamicPDF.Font = ceTe.DynamicPDF.Font.Helvetica Dim ht As Single = fontHelovetica.GetDefaultLeading(10) Console.WriteLine("Helvetica font height" + ht.ToString()) Dim font1 As ceTe.DynamicPDF.Font = New OpenTypeFont("C:\Windows\Fonts\Calibri.ttf") Dim ht1 As Single = font1.GetDefaultLeading(10) Console.WriteLine("Calibri font height" + ht1.ToString()) Console.ReadKey() Thanks, ceTe Software Support Team.