Table Width Shrinks When Images Are Present

Hi

I’m using Visual Studio 2015, with Aspose Words for .Net version 16.12. This was also an issue with earlier versions.

The problem occurs when I generate a single-cell table, with the table width set to 100% and an image in the cell. If I save as docx, everything is fine, but if I save it as PDF, the width of the table shrinks slightly. This causes other text in the table cell to wrap differently, causing inconsistent results. Another single-cell table containing no images renders fine in both DOCX and PDF format.

Here is some sample code:

LoadAsposeLicence();
DocumentBuilder builder = new DocumentBuilder();
Table table = builder.StartTable();
builder.InsertCell();
builder.Writeln("This table contains a single cell, containing text and an image.");
builder.InsertImage(ImageFileName);
builder.Writeln();
builder.Write("Some more text.");
builder.EndRow();
table.SetShading(TextureIndex.TextureNone, Color.Empty, Color.LightGray);
table.ClearBorders();
table.LeftIndent = 0;
table.PreferredWidth = PreferredWidth.FromPercent(100);
builder.EndTable();
builder.Writeln();
builder.Writeln("Some text to separate the two tables.");
builder.Writeln();
table = builder.StartTable();
builder.InsertCell();
builder.Writeln("This table contains a single cell, containing text but no image.");
builder.Write("Some more text.");
builder.EndRow();
table.SetShading(TextureIndex.TextureNone, Color.Empty, Color.LightGray);
table.ClearBorders();
table.LeftIndent = 0;
table.PreferredWidth = PreferredWidth.FromPercent(100);
builder.EndTable();
builder.Document.Save(DocumentFileName, SaveFormat.Docx);
builder.Document.Save(PdfFileName, SaveFormat.Pdf);

I have also attached the output files generated by the above sample.

EDIT: I am also experiencing a similar problem in a multi-cell, multi-row table (without images) where there are merged cells across the width of the row. The width of the table shrinks noticeably.

Can you advise if this is a bug, or if it’s something I’ve done wrong?
Thanks
Chris Fairall.

Hi Chris,

Thanks for your inquiry. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-14626. You will be notified via this forum thread once this issue is resolved. We apologize for your inconvenience.

ChrisFairall:
I am also experiencing a similar problem in a multi-cell, multi-row table (without images) where there are merged cells across the width of the row. The width of the table shrinks noticeably.

Could you please share the code example along with documents here for testing? We will investigate the issue on our side and provide you more information.

Here is some sample source code illustrating the multi-cell table problem:

LoadAsposeLicence();
DocumentBuilder builder = new DocumentBuilder();
Table table = builder.StartTable();
builder.InsertCell();
builder.Write("Cell 1");
builder.InsertCell();
builder.Write("Cell 2");
builder.EndRow();
builder.InsertCell();
builder.Write("This row contains a merged cell.");
builder.CellFormat.HorizontalMerge = CellMerge.First;
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.EndRow();
builder.InsertCell();
builder.Write("Cell 5");
builder.CellFormat.HorizontalMerge = CellMerge.None;
builder.InsertCell();
builder.Write("Cell 6");
builder.EndRow();
table.SetShading(TextureIndex.TextureNone, Color.Empty, Color.LightGray);
table.ClearBorders();
table.LeftIndent = 0;
table.PreferredWidth = PreferredWidth.FromPercent(100);
builder.EndTable();
builder.Writeln();
builder.Writeln("Some text to separate the two tables.");
builder.Writeln();
table = builder.StartTable();
builder.InsertCell();
builder.Write("Single-cell table set to 100% for comparison.");
builder.EndRow();
table.SetShading(TextureIndex.TextureNone, Color.Empty, Color.LightGray);
table.ClearBorders();
table.LeftIndent = 0;
table.PreferredWidth = PreferredWidth.FromPercent(100);
builder.EndTable();
builder.Document.Save(DocumentFileName, SaveFormat.Docx);
builder.Document.Save(PdfFileName, SaveFormat.Pdf);

I have also attached the sample output documents for comparison

Chris.

Hi Chris,

Thanks for sharing the detail. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-14634. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

The issues you have found earlier (filed as WORDSNET-14634) have been fixed in this Aspose.Words for .NET 22.2 update also available on NuGet.

The issues you have found earlier (filed as WORDSNET-14626) have been fixed in this Aspose.Words for .NET 23.7 update also available on NuGet.