Vertical alignment in cell with multiple lines

I have a cell that contains two lines, and the vertical alignment doesn't seem to work. Here's what I'm doing. Please advise.

Dim tc1a As Aspose.Pdf.Cell = tr1.Cells.Add("Line 1#$NLLine 2")

tc1a.ColumnsSpan = 2

tc1a.VerticalAlignment = Aspose.Pdf.VerticalAlignmentType.Center

tc1a.Alignment = Aspose.Pdf.AlignmentType.Center

It comes out looking like this:

+--------------------------------------------+

| |

| Line 1 |

| Line 2 |

+--------------------------------------------+

Where Line 1 appears to be centered properly, and Line 2 just appears below it.

Hello David,

I have tested the scenario and I am unable to reproduce the problem. I am using Aspose.pdf v3.7.0.0. I have tested it using following code snippet. The resultant Pdf is in attachment, notice the required behavior in 3rd column.

Dim pdf1 As Pdf = New Pdf()
Dim sec1 As Aspose.Pdf.Section = pdf1.Sections.Add()
Dim tab1 As Table = New Table()
sec1.Paragraphs.Add(tab1)

tab1.ColumnWidths = "60 100 150"
tab1.DefaultCellBorder = New BorderInfo(CType(BorderSide.All, Integer), 0.1)
Dim row1 As Aspose.Pdf.Row = tab1.Rows.Add()
row1.Cells.Add("Line 1 #$NLLine 2 #$NLLine 3 #$NLLine 4 #$NLLine 5 #$NLLine 6#$NLLine 7#$NLLine 8")
row1.Cells.Add("col2")
Dim tc1a As Aspose.Pdf.Cell = row1.Cells.Add("Line 1#$NLLine 2")
tc1a.ColumnsSpan = 2
tc1a.VerticalAlignment = Aspose.Pdf.VerticalAlignmentType.Center
tc1a.Alignment = Aspose.Pdf.AlignmentType.Center

pdf1.Save("c:\ellAllignment.pdf")

I apologize for not posting full code before. I'm also using Aspose.PDF v3.7.0.0. Here's some sample code that reproduces the problem, and I'll try to attach the resulting PDF.

Dim license As Aspose.Pdf.License = New Aspose.Pdf.License

license.SetLicense("Aspose.Custom.lic")

Dim FontName As String = "Arial"

Dim FontSize As Integer = 10

Dim PointsPerInch As Integer = 72

Dim ThisPdf As Aspose.Pdf.Pdf = New Aspose.Pdf.Pdf

ThisPdf.PageSetup.Margin.Top = 0.5 * PointsPerInch

ThisPdf.PageSetup.Margin.Right = 0.5 * PointsPerInch

ThisPdf.PageSetup.Margin.Bottom = 0.5 * PointsPerInch

ThisPdf.PageSetup.Margin.Left = 0.5 * PointsPerInch

ThisPdf.IsLandscape = False

ThisPdf.PageSetup.PageHeight = 11 * PointsPerInch

ThisPdf.PageSetup.PageWidth = 8.5 * PointsPerInch

ThisPdf.TextInfo.FontName = FontName

ThisPdf.TextInfo.FontSize = FontSize

ThisPdf.PageNumberFormat = Aspose.Pdf.PageNumberFormatType.Arab

Dim Section1 As Aspose.Pdf.Section = ThisPdf.Sections.Add

Dim OfficeUseOnlyTable As Aspose.Pdf.Table = New Aspose.Pdf.Table(Section1)

Section1.Paragraphs.Add(OfficeUseOnlyTable)

OfficeUseOnlyTable.Margin.Top = 0

OfficeUseOnlyTable.PositioningType = Aspose.Pdf.PositioningType.PageRelative

OfficeUseOnlyTable.Top = 0.5 * PointsPerInch

OfficeUseOnlyTable.Left = 8 * PointsPerInch - 210 '210 is the total column width (see ColumnWidths below)

Dim ouoti As Aspose.Pdf.TextInfo = New Aspose.Pdf.TextInfo

ouoti.FontSize = FontSize - 2

ouoti.FontName = FontName

OfficeUseOnlyTable.DefaultCellTextInfo = ouoti

OfficeUseOnlyTable.ColumnWidths = "160 50"

OfficeUseOnlyTable.DefaultCellBorder = New Aspose.Pdf.BorderInfo(CType(Aspose.Pdf.BorderSide.All, Integer), 1)

Dim CellPadding As New Aspose.Pdf.MarginInfo()

CellPadding.Bottom = 6

CellPadding.Left = 6

CellPadding.Right = 6

CellPadding.Top = 6

OfficeUseOnlyTable.DefaultCellPadding = CellPadding

Dim tr1 As Aspose.Pdf.Row = OfficeUseOnlyTable.Rows.Add

Dim tc1a As Aspose.Pdf.Cell = tr1.Cells.Add("Office Use Only#$NLProgram 123")

tc1a.ColumnsSpan = 2

tc1a.VerticalAlignment = Aspose.Pdf.VerticalAlignmentType.Center

tc1a.Alignment = Aspose.Pdf.AlignmentType.Center

Dim tr2 As Aspose.Pdf.Row = OfficeUseOnlyTable.Rows.Add

Dim tc2a As Aspose.Pdf.Cell = tr2.Cells.Add("")

Dim tc2b As Aspose.Pdf.Cell = tr2.Cells.Add("Initials")

tc2b.Alignment = Aspose.Pdf.AlignmentType.Center

Dim tr3 As Aspose.Pdf.Row = OfficeUseOnlyTable.Rows.Add

Dim tc3a As Aspose.Pdf.Cell = tr3.Cells.Add("Dept. A")

Dim tc3b As Aspose.Pdf.Cell = tr3.Cells.Add()

Dim tr4 As Aspose.Pdf.Row = OfficeUseOnlyTable.Rows.Add

Dim tc4a As Aspose.Pdf.Cell = tr4.Cells.Add("Dept. B")

Dim tc4b As Aspose.Pdf.Cell = tr4.Cells.Add()

ThisPdf.Save("Sample.pdf", Aspose.Pdf.SaveType.OpenInAcrobat, System.Web.HttpContext.Current.Response)

Put padding into your code and it breaks. See below:

Dim license As Aspose.Pdf.License = New Aspose.Pdf.License

license.SetLicense("Aspose.Custom.lic")

Dim pdf1 As Aspose.Pdf.Pdf = New Aspose.Pdf.Pdf()

Dim sec1 As Aspose.Pdf.Section = pdf1.Sections.Add()

Dim tab1 As Aspose.Pdf.Table = New Aspose.Pdf.Table()

sec1.Paragraphs.Add(tab1)

Dim CellPadding As New Aspose.Pdf.MarginInfo()

CellPadding.Bottom = 6

CellPadding.Left = 6

CellPadding.Right = 6

CellPadding.Top = 6

tab1.DefaultCellPadding = CellPadding

tab1.ColumnWidths = "60 100 150"

tab1.DefaultCellBorder = New Aspose.Pdf.BorderInfo(CType(Aspose.Pdf.BorderSide.All, Integer), 0.1)

Dim row1 As Aspose.Pdf.Row = tab1.Rows.Add()

'Comment out the followig line to make the effect more noticable

'row1.Cells.Add("Line 1 #$NLLine 2 #$NLLine 3 #$NLLine 4 #$NLLine 5 #$NLLine 6#$NLLine 7#$NLLine 8")

row1.Cells.Add("col2")

Dim tc1a As Aspose.Pdf.Cell = row1.Cells.Add("Line 1#$NLLine 2")

tc1a.ColumnsSpan = 2

tc1a.VerticalAlignment = Aspose.Pdf.VerticalAlignmentType.Center

tc1a.Alignment = Aspose.Pdf.AlignmentType.Center

pdf1.Save("Sample.pdf", Aspose.Pdf.SaveType.OpenInAcrobat, System.Web.HttpContext.Current.Response)

Hello David,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I have tested the code using Aspose.Pdf v3.7.0.0 and I am able to reproduce the problem. For the correction purpose, I have tested it with the latest hotfix of Aspose.Pdf v3.7.0.8 and in this scenario the issue is resolved. I have attached my resultant Pdf and hotfix. Please take a look, and in case the issue still persists, feel free to share.

I’m glad it’s been fixed. How do I install that hotfix?

Hello David,

There is no need to install the hotfix, you simply need to remove the previous version from project properties and add this hotfix as a new reference.

Open project explorer, right click the solution and select properties, select references from left menu, select previous version from list and press remove. Now select Add button, and locate the hotfix.

Incase of any further query, please feel free to share.