We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

PDF for .NET 7.9.0.0 -- Table Cell not wrapping when it should

Using Aspose.PDF 7.9.0.0, I am having an issue with word wrapping in a table cell.

I have attached a PDF which shows 5 tables, the only difference being the column width.
The second row/cell in each table is not wrapping when the cell becomes to small.

In the first table, the first row should not wrap, but the second row should.
If you zoom all the way, you can see the text outside the bounds of the column.

Decreasing the column width shows that the second row doesn’t wrap until the column is several points smaller than the width of the text.

This issue may be related to this previous post:
<a href="https://forum.aspose.com/t/120269

Any ideas of what might be going on?

Here is the complete code to reproduce this problem:
private static void Main(string[] args)
{
const string string1 = “EVP, Operations & Customer ExperienCE”;
const string string2 = “4000 - Operations & Customer Experience”;
var pdf1 = new Pdf();
var sec = pdf1.Sections.Add();

var table1 = new Table(sec)
{
DefaultCellBorder = new BorderInfo((int)BorderSide.All, 0.01f, new Color(“Blue”)),
BackgroundColor = new Color(“LightYellow”)
};
var row1 = new Row(table1);
table1.Rows.Add(row1);
var cell1 = row1.Cells.Add(string1);
cell1.IsWordWrapped = true;
cell1.Alignment = AlignmentType.Center;
var row2 = new Row(table1);
table1.Rows.Add(row2);
var cell2 = row2.Cells.Add(string2);
cell2.IsWordWrapped = true;
cell2.Alignment = AlignmentType.Center;

var table2 = (Table)table1.CompleteClone();
var table3 = (Table)table1.CompleteClone();
var table4 = (Table)table1.CompleteClone();
var table5 = (Table)table1.CompleteClone();

//CompleteClone doesn’t seem to copy the Margin info
table2.Margin.Top = 1;
table3.Margin.Top = 1;
table4.Margin.Top = 1;
table5.Margin.Top = 1;


//Set the Widths to test word wrapping
table1.ColumnWidths = “205”;
sec.Paragraphs.Add(table1);

table2.ColumnWidths = “204”;
sec.Paragraphs.Add(table2);

table3.ColumnWidths = “203”;
sec.Paragraphs.Add(table3);

table4.ColumnWidths = “202”;
sec.Paragraphs.Add(table4);

table5.ColumnWidths = “201”;
sec.Paragraphs.Add(table5);


const string filePath = @“C:\Development\Practice\AsposePDF\TextWrapping-test.pdf”;
pdf1.Save(filePath);

//open the pdf
System.Diagnostics.Process.Start(filePath);
}

Hi Joey,


Thanks for your inquiry. I've managed to reproduce the issue at my end and logged it as PDFNEWNET-35196 in our bug tracking system for further investigation and resolution. You will be notified via this thread as soon as it is resolved.


Sorry for the inconvenience faced


Best Regards,

Hi Joey,


Thanks for your patience.

I am pleased to share that the issue reported earlier is resolved. Please try using the following code snippet based over new DOM approach. For your reference, I have also attached the resultant PDF generated over my end when using Aspose.Pdf for .NET 8.2.0.

[C#]

Document doc = new
Document();<o:p></o:p>

Page page = doc.Pages.Add();

const string string1 = "EVP, Operations & Customer ExperienCE";

const string string2 = "4000 - Operations & Customer Experience";

Aspose.Pdf.Table table1 = new Aspose.Pdf.Table();

table1.Margin.Top = 1;

table1.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.01f, Aspose.Pdf.Color.Blue);

table1.BackgroundColor = Aspose.Pdf.Color.LightYellow;

Aspose.Pdf.Row row1 = new Aspose.Pdf.Row();

table1.Rows.Add(row1);

Aspose.Pdf.Cell cell1 = row1.Cells.Add(string1);

cell1.IsWordWrapped = true;

cell1.Alignment = Aspose.Pdf.HorizontalAlignment.Center;

Aspose.Pdf.Row row2 = new Aspose.Pdf.Row();

table1.Rows.Add(row2);

Aspose.Pdf.Cell cell2 = row2.Cells.Add(string2);

cell2.IsWordWrapped = true;

cell2.Alignment = Aspose.Pdf.HorizontalAlignment.Center;

Aspose.Pdf.Table table2 = (Aspose.Pdf.Table)table1.Clone();

Aspose.Pdf.Table table3 = (Aspose.Pdf.Table)table1.Clone();

Aspose.Pdf.Table table4 = (Aspose.Pdf.Table)table1.Clone();

Aspose.Pdf.Table table5 = (Aspose.Pdf.Table)table1.Clone();

//Set the Widths to test word wrapping

table1.ColumnWidths = "190";

page.Paragraphs.Add(table1);

table2.ColumnWidths = "189";

page.Paragraphs.Add(table2);

table3.ColumnWidths = "188";

page.Paragraphs.Add(table3);

table4.ColumnWidths = "187";

page.Paragraphs.Add(table4);

table5.ColumnWidths = "186";

page.Paragraphs.Add(table5);

doc.Save(“c:/pdftest/TextWrapping_35196.pdf”);

The issues you have found earlier (filed as PDFNEWNET-35196) have been fixed in Aspose.Pdf for .NET 8.2.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
Thank you for your reply that the issue has been fixed.
And I'm sorry for the late response, but we just now encountering this issue again.
I tried version 8.2, but using the code in my original post, the issue does NOT appear to be resolved.
The tables with incorrect word-wrapping look exactly the same as they did in version 7.9.

We have a lot of legacy code that uses the Aspose.Pdf.Generator namespace, and thus do not have the luxury of simply switching to a new namespace/object model.
In other words, we cannot use the different DOM approach, as you suggest.

I've attached an updated PDF showing the version number, and here is the code that generates that PDF:
private static void Main(string[] args)
		{
			var license = new License();
			license.SetLicense("Aspose.Total.lic");
			license.Embedded = true;
		<span style="color:#569cd6;">const</span> <span style="color:#569cd6;">string</span> <span style="font-weight:bold;color:violet;">filePath</span> <span style="color:#b4b4b4;">=</span> <span style="color:#d69d85;">@"C:\Development\Practice\AsposePDF\TextWrapping-test_82.pdf"</span>;
	
		<span style="color:#569cd6;">var</span> <span style="color:white;">pdf1</span> <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> <span style="color:lightblue;">Pdf</span>();
		<span style="color:#569cd6;">var</span> <span style="color:white;">sec</span> <span style="color:#b4b4b4;">=</span> <span style="color:white;">pdf1</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">Sections</span><span style="color:#b4b4b4;">.</span><span style="color:cyan;">Add</span>();

		<span style="color:#569cd6;">var</span> <span style="color:white;">fileVersionInfo</span> <span style="color:#b4b4b4;">=</span> <span style="color:lightblue;">FileVersionInfo</span><span style="color:#b4b4b4;">.</span><span style="color:cyan;">GetVersionInfo</span>(<span style="color:#d69d85;">@"C:\Development\Practice\AsposePDF\AsposePdfPractice\packages\Aspose.Pdf.8.2.0\lib\net40-client\Aspose.Pdf.dll"</span>);
		<span style="color:white;">sec</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">Paragraphs</span><span style="color:#b4b4b4;">.</span><span style="color:cyan;">Add</span>(<span style="color:#569cd6;">new</span> <span style="color:lightblue;">Text</span>(<span style="color:white;">sec</span>, <span style="color:white;">fileVersionInfo</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">FileDescription</span>));
		<span style="color:white;">sec</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">Paragraphs</span><span style="color:#b4b4b4;">.</span><span style="color:cyan;">Add</span>(<span style="color:#569cd6;">new</span> <span style="color:lightblue;">Text</span>(<span style="color:white;">sec</span>, <span style="color:white;">fileVersionInfo</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">FileVersion</span>));

		<span style="color:#569cd6;">const</span> <span style="color:#569cd6;">string</span> <span style="font-weight:bold;color:violet;">string1</span> <span style="color:#b4b4b4;">=</span> <span style="color:#d69d85;">"EVP, Operations & Customer ExperienCE"</span>;
		<span style="color:#569cd6;">const</span> <span style="color:#569cd6;">string</span> <span style="font-weight:bold;color:violet;">string2</span> <span style="color:#b4b4b4;">=</span> <span style="color:#d69d85;">"4000 - Operations & Customer Experience"</span>;

		<span style="color:#569cd6;">var</span> <span style="color:white;">table1</span> <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> <span style="color:lightblue;">Table</span>(<span style="color:white;">sec</span>)
		{
			<span style="color:violet;">DefaultCellBorder</span> <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> <span style="color:lightblue;">BorderInfo</span>((<span style="color:#569cd6;">int</span>)<span style="color:lightblue;">BorderSide</span><span style="color:#b4b4b4;">.</span><span style="font-weight:bold;color:violet;">All</span>, <span style="color:#b5cea8;">0.01f</span>, <span style="color:#569cd6;">new</span> <span style="color:lightblue;">Color</span>(<span style="color:#d69d85;">"Blue"</span>)),
			<span style="color:violet;">BackgroundColor</span> <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> <span style="color:lightblue;">Color</span>(<span style="color:#d69d85;">"LightYellow"</span>),
			<span style="color:violet;">Margin</span> <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> <span style="color:lightblue;">MarginInfo</span> { <span style="color:violet;">Top</span> <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">200</span>, <span style="color:violet;">Left</span> <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">100</span> }
		};
		<span style="color:#569cd6;">var</span> <span style="color:white;">row1</span> <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> <span style="color:lightblue;">Row</span>(<span style="color:white;">table1</span>);
		<span style="color:white;">table1</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">Rows</span><span style="color:#b4b4b4;">.</span><span style="color:cyan;">Add</span>(<span style="color:white;">row1</span>);
		<span style="color:#569cd6;">var</span> <span style="color:white;">cell1</span> <span style="color:#b4b4b4;">=</span> <span style="color:white;">row1</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">Cells</span><span style="color:#b4b4b4;">.</span><span style="color:cyan;">Add</span>(<span style="font-weight:bold;color:violet;">string1</span>);
		<span style="color:white;">cell1</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">IsWordWrapped</span> <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">true</span>;
		<span style="color:white;">cell1</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">Alignment</span> <span style="color:#b4b4b4;">=</span> <span style="color:lightblue;">AlignmentType</span><span style="color:#b4b4b4;">.</span><span style="font-weight:bold;color:violet;">Center</span>;
		<span style="color:#569cd6;">var</span> <span style="color:white;">row2</span> <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> <span style="color:lightblue;">Row</span>(<span style="color:white;">table1</span>);
		<span style="color:white;">table1</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">Rows</span><span style="color:#b4b4b4;">.</span><span style="color:cyan;">Add</span>(<span style="color:white;">row2</span>);
		<span style="color:#569cd6;">var</span> <span style="color:white;">cell2</span> <span style="color:#b4b4b4;">=</span> <span style="color:white;">row2</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">Cells</span><span style="color:#b4b4b4;">.</span><span style="color:cyan;">Add</span>(<span style="font-weight:bold;color:violet;">string2</span>);
		<span style="color:white;">cell2</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">IsWordWrapped</span> <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">true</span>;
		<span style="color:white;">cell2</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">Alignment</span> <span style="color:#b4b4b4;">=</span> <span style="color:lightblue;">AlignmentType</span><span style="color:#b4b4b4;">.</span><span style="font-weight:bold;color:violet;">Center</span>;

		<span style="color:#569cd6;">var</span> <span style="color:white;">table2</span> <span style="color:#b4b4b4;">=</span> (<span style="color:lightblue;">Table</span>)<span style="color:white;">table1</span><span style="color:#b4b4b4;">.</span><span style="color:cyan;">CompleteClone</span>();
		<span style="color:#569cd6;">var</span> <span style="color:white;">table3</span> <span style="color:#b4b4b4;">=</span> (<span style="color:lightblue;">Table</span>)<span style="color:white;">table1</span><span style="color:#b4b4b4;">.</span><span style="color:cyan;">CompleteClone</span>();
		<span style="color:#569cd6;">var</span> <span style="color:white;">table4</span> <span style="color:#b4b4b4;">=</span> (<span style="color:lightblue;">Table</span>)<span style="color:white;">table1</span><span style="color:#b4b4b4;">.</span><span style="color:cyan;">CompleteClone</span>();
		<span style="color:#569cd6;">var</span> <span style="color:white;">table5</span> <span style="color:#b4b4b4;">=</span> (<span style="color:lightblue;">Table</span>)<span style="color:white;">table1</span><span style="color:#b4b4b4;">.</span><span style="color:cyan;">CompleteClone</span>();

		<span style="color:#608b4e;">//CompleteClone doesn't seem to copy the Margin info</span>
		<span style="color:white;">table2</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">Margin</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">Top</span> <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">1</span>;
		<span style="color:white;">table3</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">Margin</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">Top</span> <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">1</span>;
		<span style="color:white;">table4</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">Margin</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">Top</span> <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">1</span>;
		<span style="color:white;">table5</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">Margin</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">Top</span> <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">1</span>;


		<span style="color:#608b4e;">//Set the Widths to test word wrapping</span>
		<span style="color:white;">table1</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">ColumnWidths</span> <span style="color:#b4b4b4;">=</span> <span style="color:#d69d85;">"205"</span>;
		<span style="color:white;">sec</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">Paragraphs</span><span style="color:#b4b4b4;">.</span><span style="color:cyan;">Add</span>(<span style="color:white;">table1</span>);

		<span style="color:white;">table2</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">ColumnWidths</span> <span style="color:#b4b4b4;">=</span> <span style="color:#d69d85;">"204"</span>;
		<span style="color:white;">sec</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">Paragraphs</span><span style="color:#b4b4b4;">.</span><span style="color:cyan;">Add</span>(<span style="color:white;">table2</span>);

		<span style="color:white;">table3</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">ColumnWidths</span> <span style="color:#b4b4b4;">=</span> <span style="color:#d69d85;">"203"</span>;
		<span style="color:white;">sec</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">Paragraphs</span><span style="color:#b4b4b4;">.</span><span style="color:cyan;">Add</span>(<span style="color:white;">table3</span>);

		<span style="color:white;">table4</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">ColumnWidths</span> <span style="color:#b4b4b4;">=</span> <span style="color:#d69d85;">"202"</span>;
		<span style="color:white;">sec</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">Paragraphs</span><span style="color:#b4b4b4;">.</span><span style="color:cyan;">Add</span>(<span style="color:white;">table4</span>);

		<span style="color:white;">table5</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">ColumnWidths</span> <span style="color:#b4b4b4;">=</span> <span style="color:#d69d85;">"201"</span>;
		<span style="color:white;">sec</span><span style="color:#b4b4b4;">.</span><span style="color:violet;">Paragraphs</span><span style="color:#b4b4b4;">.</span><span style="color:cyan;">Add</span>(<span style="color:white;">table5</span>);

		<span style="color:white;">pdf1</span><span style="color:#b4b4b4;">.</span><span style="color:cyan;">Save</span>(<span style="font-weight:bold;color:violet;">filePath</span>);

		<span style="color:#608b4e;">//open the pdf</span>
		<span style="color:lightblue;">System</span><span style="color:#b4b4b4;">.</span><span style="color:lightblue;">Diagnostics</span><span style="color:#b4b4b4;">.</span><span style="color:lightblue;">Process</span><span style="color:#b4b4b4;">.</span><span style="color:cyan;">Start</span>(<span style="font-weight:bold;color:violet;">filePath</span>);
	}</pre></div><div><br></div></blockquote>As you can see, the word-wrapping still behaves as it did in version 7.9.</div><div>Is there any other version that fixes this issue within the "Generator" namespace?</div><div><br></div><div>Thank you,</div><div>Joey</div>

Hi Joey,


Thanks for your inquiry. Please use code suggested in above post that involves new Generator (Aspose.Pdf.Document). Please noteAspose.Pdf.Generator is old generator and it is obsolete now. We are making changes and improvements in new generator Aspose.Pdf (DOM approach). It is more improved and efficient. Hopefully new suggested code will help you to accomplish the task.

We are sorry for the inconvenience caused.

Best Regards,