I’m seeing inconsistent rendering of table cell vertical alignment when converting DOCX to images with Aspose.Words.
- sample1.docx → Cell content is not vertically centered in the PNG output (unexpected).
- sample2.docx → Cell content is vertically centered (expected), but a warning is logged:
[MinorFormattingLoss] A table not supported by the new table layout logic is encountered.
Older logic that has known issues is applied.
Strangely, the document that falls back to the older table layout logic produces the expected result, whereas the one that appears to use the new table layout logic does not.
I cannot identify the reason for this difference from the document XML alone.
Sample Code
Environment:
- .NET Framework 4.8
- Aspose.Words 25.9.0
- Microsoft Word 2010 (14.0.7268.5000, 32-bit)
using Aspose.Words;
using Aspose.Words.Saving;
using Aspose.Words.Tables;
new License().SetLicense(@"licensePath");
const string fileName = "sample2"; // sample1
const string docxPath = @"inputPath\" + fileName + ".docx";
WarningCollector.Clear();
var doc = new Document(docxPath)
{
WarningCallback = new WarningCollector()
};
doc.UpdatePageLayout();
var tables = doc.GetChildNodes(NodeType.Table, true);
foreach (var node in tables)
{
var table = (Table)node;
for (var j = 0; j < table.Rows.Count; j++)
{
var row = table.Rows[j];
for (var k = 0; k < row.Cells.Count; k++)
{
var cell = row.Cells[k];
var format = cell.CellFormat;
Console.WriteLine($"\n --- Cell ({j + 1},{k + 1}) ---");
Console.WriteLine($" Vertical Alignment: {format.VerticalAlignment}");
foreach (var node1 in cell.Paragraphs)
{
var paragraph = (Paragraph)node1;
Console.WriteLine($" Paragraph Alignment: {paragraph.ParagraphFormat.Alignment}");
}
}
}
}
var saveOptions = new ImageSaveOptions(SaveFormat.Png)
{
PageLayout = MultiPageLayout.Vertical(0)
};
doc.Save(@"outputPath\" + fileName + @".png", saveOptions);
var warnings = WarningCollector.GetWarnings();
if (warnings.Any())
{
foreach (var w in warnings)
{
Console.WriteLine($"[{w.WarningType}] {w.Description}");
}
}
else
{
Console.WriteLine("(No warnings)");
}
public sealed class WarningCollector : IWarningCallback
{
private static readonly List<WarningInfo> Warnings = [];
public void Warning(WarningInfo info) => Warnings.Add(info);
public static List<WarningInfo> GetWarnings() => [..Warnings];
public static void Clear() => Warnings.Clear();
}
Attachments
Sample 1 docx:
sample1.docx (14.5 KB)
Aspose result (not vertically centered):
Expeceted result:
Sample 2 docx :
sample2.docx (15.5 KB)
Aspose Result (vertically centered (expected):