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

Free Support Forum - aspose.com

Cell Border Issue

Hi,


We are trying to upgrade our version of Aspose.Pdf from version 4.1.1.0 (very old version) to 12.0.0.0. The reason we are upgrading is due to a bug putting a boxed border around the table of contents heading text. The behavior of the latest version has changed and does not seem correct. In the old version Example1 below would work correctly giving three rows with a left border, three rows with a top border, three rows with a right border, and three rows with a bottom border. The latest version does not put a top border. In the second example no borders are added. The only way to get the border to appear is if we set the first row’s bottom border and the second row’s top border.

private void AddRow(Table pTable, BorderSide? pBorderSide)
{
Row vRow = pTable.Rows.Add();
Cell vCell = vRow.Cells.Add();

vCell.Paragraphs.Add(new Text(pTable.Rows.Count.ToString()));

if (pBorderSide != null)
{
vCell.Border = new BorderInfo((int)pBorderSide.Value, 1, new Aspose.Pdf.Generator.Color(0));
}
}

private Pdf Example1()
{
Pdf vPdf = new Pdf();
Section vSection = new Section();

Table vTable = new Table();

this.AddRow(vTable, BorderSide.Left);
this.AddRow(vTable, BorderSide.Left);
this.AddRow(vTable, BorderSide.Left);

this.AddRow(vTable, BorderSide.Top);
this.AddRow(vTable, BorderSide.Top);
this.AddRow(vTable, BorderSide.Top);

this.AddRow(vTable, BorderSide.Right);
this.AddRow(vTable, BorderSide.Right);
this.AddRow(vTable, BorderSide.Right);

this.AddRow(vTable, BorderSide.Bottom);
this.AddRow(vTable, BorderSide.Bottom);
this.AddRow(vTable, BorderSide.Bottom);

vSection.Paragraphs.Add(vTable);
vPdf.Sections.Add(vSection);

return vPdf;
}

private Pdf Example2()
{
Pdf vPdf = new Pdf();
Section vSection = new Section();

Table vTable = new Table();

this.AddRow(vTable, BorderSide.Bottom);
this.AddRow(vTable, null);

vSection.Paragraphs.Add(vTable);
vPdf.Sections.Add(vSection);

return vPdf;
}

Hi Rajesh,


Thanks for contacting support.

I have tested the scenario using Aspose.Pdf for .NET 12.0.0 where I have used following code snippet based on new Document Object Model of Aspose.Pdf namespace and as per my observations, the output is properly being generated. For your reference, I have also attached the output generated over my end.

Aspose.Pdf.Generator is a legacy approach, so we recommend using new Document Object Model.

[C#]

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

Page vSection = vPdf.Pages.Add();

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

this.AddRow(vTable, Aspose.Pdf.BorderSide.Left);

this.AddRow(vTable, Aspose.Pdf.BorderSide.Left);

this.AddRow(vTable, Aspose.Pdf.BorderSide.Left);

this.AddRow(vTable, Aspose.Pdf.BorderSide.Top);

this.AddRow(vTable, Aspose.Pdf.BorderSide.Top);

this.AddRow(vTable, Aspose.Pdf.BorderSide.Top);

this.AddRow(vTable, Aspose.Pdf.BorderSide.Right);

this.AddRow(vTable, Aspose.Pdf.BorderSide.Right);

this.AddRow(vTable, Aspose.Pdf.BorderSide.Right);

this.AddRow(vTable, Aspose.Pdf.BorderSide.Bottom);

this.AddRow(vTable, Aspose.Pdf.BorderSide.Bottom);

this.AddRow(vTable, Aspose.Pdf.BorderSide.Bottom);

vSection.Paragraphs.Add(vTable);

vPdf.Pages.Add(vSection);

vPdf.Save("c:/pdftest/Cell_Border_Issue.pdf");

private Document Example2()

{

Document vPdf = new Document();

Page vSection = vPdf.Pages.Add();

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

this.AddRow(vTable, Aspose.Pdf.BorderSide.Bottom);

this.AddRow(vTable, null);

vSection.Paragraphs.Add(vTable);

vPdf.Pages.Add(vSection);

return vPdf;

}

private void AddRow(Aspose.Pdf.Table pTable, Aspose.Pdf.BorderSide? pBorderSide)

{

Aspose.Pdf.Row vRow = pTable.Rows.Add();

Aspose.Pdf.Cell vCell = vRow.Cells.Add();

vCell.Paragraphs.Add(new Aspose.Pdf.Text.TextFragment(pTable.Rows.Count.ToString()));

if (pBorderSide != null)

{

vCell.Border = new Aspose.Pdf.BorderInfo(pBorderSide.Value, 1, Aspose.Pdf.Color.Blue);

}

}

Thank you for your response.


I have tried using the Aspose.Pdf DOM and it does not have the problem, Aspose.Pdf.Generator does have the problem which I was able to find a solution to. If Aspose.Pdf.Generator is now legacy we would like to use Aspose.Pdf instead and are facing a couple more issues.

1. Setting the cell border to All creates a thick border between two adjacent cells because of the Right and Left borders for two horizontally adjacent cells or the Bottom and Top for two vertically adjacent cells.

2. The Table class used to provide a method SetColumnWidth where you can set the width of a single column and the rest were auto-calculated. What is the equivalent in the Aspose.Pdf namespace? I only see ColumnWidths which seems to require all columns be specified.

rsharma:
1. Setting the cell border to All creates a thick border between two adjacent cells because of the Right and Left borders for two horizontally adjacent cells or the Bottom and Top for two vertically adjacent cells.
Hi Rajesh,

Thanks for sharing the updates.

In order to control the border, you can specify the side of cell border which you need to render. Please take a look over following code line.

pTable.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.Left
| Aspose.Pdf.BorderSide.Right, Aspose.Pdf.Color.Brown);

rsharma:
2. The Table class used to provide a method SetColumnWidth where you can set the width of a single column and the rest were auto-calculated. What is the equivalent in the Aspose.Pdf namespace? I only see ColumnWidths which seems to require all columns be specified.
I am afraid currently Aspose.Pdf namespace does not support this feature. However for the sake of implementation, we already have logged it as PDFNEWNET-38548 in our issue tracking system. We will further look into the details of this problem and will keep you updated on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

We are having many problems trying to switch the new DOM. The behavior of the new DOM is different and does not seem to work as one would expect. Here is an example of the old and new having a table with two rows and an image in each cell. The old Generator version correctly breaks to the next page and the new version shrinks the second image to fit on the same page. I have tried many combinations of table/row breaking properties with no luck. The only way I can get the second row on the next page is to set vRow2.IsInNewPage = true; which is not a practical solution because this should be handled internally like the Generator does.


FYI in the new version if you set
vTable.Broken = Aspose.Pdf.TableBroken.Vertical; or
vTable.Broken = Aspose.Pdf.TableBroken.VerticalInSamePage;
it will crash on Save


Here is the code

private Aspose.Pdf.Generator.Pdf CreateUsingGenerator()
{
Aspose.Pdf.Generator.Pdf vPdf = new Aspose.Pdf.Generator.Pdf();

Bitmap vBitmap = new Bitmap(500, 500);
Graphics vGraphics = Graphics.FromImage(vBitmap);

vGraphics.FillRectangle(Brushes.LightGray, 0, 0, vBitmap.Width, vBitmap.Height);
vGraphics.FillEllipse(Brushes.Blue, vBitmap.Width * 0.10f, vBitmap.Height * 0.10f, vBitmap.Width * 0.80f, vBitmap.Height * 0.80f);

MemoryStream vMemoryStream = new MemoryStream();
vBitmap.Save(vMemoryStream, System.Drawing.Imaging.ImageFormat.Bmp);

Aspose.Pdf.Generator.Image vImage = new Aspose.Pdf.Generator.Image();
vImage.ImageInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Center;
vImage.ImageInfo.ImageStream = vMemoryStream;
vImage.ImageInfo.FixHeight = 500;
vImage.ImageInfo.FixWidth = 300;

Aspose.Pdf.Generator.Table vTable = new Aspose.Pdf.Generator.Table();

Aspose.Pdf.Generator.Row vRow1 = vTable.Rows.Add();

Aspose.Pdf.Generator.Cell vCell1 = vRow1.Cells.Add();
vCell1.Border = new Aspose.Pdf.Generator.BorderInfo((int)BorderSide.All, 1, new Aspose.Pdf.Generator.Color(“Red”));

Aspose.Pdf.Generator.Row vRow2 = vTable.Rows.Add();

Aspose.Pdf.Generator.Cell vCell2 = vRow2.Cells.Add();
vCell2.Border = new Aspose.Pdf.Generator.BorderInfo((int)BorderSide.All, 1, new Aspose.Pdf.Generator.Color(“Green”));

vCell1.Paragraphs.Add(vImage);
vCell2.Paragraphs.Add(vImage);

Aspose.Pdf.Generator.Section vPage = vPdf.Sections.Add();

vTable.ColumnWidths = (vPage.PageInfo.PageWidth - (vPage.PageInfo.Margin.Left + vPage.PageInfo.Margin.Right)).ToString();
vPage.Paragraphs.Add(vTable);

vPage.Paragraphs.Add(new Aspose.Pdf.Generator.Text(“After Table”));
vPage.Paragraphs.Add(new Aspose.Pdf.Generator.Text(“More Content”));

return vPdf;
}

private Aspose.Pdf.Document CreateUsingNewDocument()
{
Aspose.Pdf.Document vPdf = new Aspose.Pdf.Document();

Bitmap vBitmap = new Bitmap(500, 500);
Graphics vGraphics = Graphics.FromImage(vBitmap);

vGraphics.FillRectangle(Brushes.LightGray, 0, 0, vBitmap.Width, vBitmap.Height);
vGraphics.FillEllipse(Brushes.Blue, vBitmap.Width * 0.10f, vBitmap.Height * 0.10f, vBitmap.Width * 0.80f, vBitmap.Height * 0.80f);

MemoryStream vMemoryStream = new MemoryStream();
vBitmap.Save(vMemoryStream, System.Drawing.Imaging.ImageFormat.Bmp);

Aspose.Pdf.Image vImage = new Aspose.Pdf.Image();
vImage.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
vImage.ImageStream = vMemoryStream;
vImage.FixHeight = 500;
vImage.FixWidth = 300;

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

Aspose.Pdf.Row vRow1 = vTable.Rows.Add();

Aspose.Pdf.Cell vCell1 = vRow1.Cells.Add();
vCell1.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 1, Aspose.Pdf.Color.Red);

Aspose.Pdf.Row vRow2 = vTable.Rows.Add();

Aspose.Pdf.Cell vCell2 = vRow2.Cells.Add();
vCell2.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 1, Aspose.Pdf.Color.Green);

vCell1.Paragraphs.Add(vImage);
vCell2.Paragraphs.Add(vImage);

Aspose.Pdf.Page vPage = vPdf.Pages.Add();

vTable.ColumnWidths = (vPage.PageInfo.Width - (vPage.PageInfo.Margin.Left + vPage.PageInfo.Margin.Right)).ToString();
vPage.Paragraphs.Add(vTable);

vPage.Paragraphs.Add(new Aspose.Pdf.Text.TextFragment(“After Table”));
vPage.Paragraphs.Add(new Aspose.Pdf.Text.TextFragment(“More Content”));

return vPdf;
}

Aspose.Pdf.Generator.Pdf vPdf = this.CreateUsingGenerator();
Aspose.Pdf.Document vDocument = this.CreateUsingNewDocument();

vPdf.Save(@“C:\DataFile\Generator.pdf”);
vDocument.Save(@“C:\DataFile\New.pdf”);

Hi Rajesh,


Thanks for your feedback. I have noticed the difference in image rendering scenario in old generator and new generator, so logged a ticket PDFNET-41553 in our issue tracking system for further investigation and rectification. We will notify you as soon as it is resolved.

We are sorry for the inconvenience.

Best Regards,

The issues you have found earlier (filed as PDFNET-41553) have been fixed in Aspose.Pdf for .NET 16.11.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi Rajesh,


Thanks for your patience.

We are pleased to share that the issue reported earlier is resolved and its fix will be included in next release of Aspose.Pdf for .NET 17.3.0. Furthermore, in order to generate correct output, please try using following code snippet.

[C#]

Table table = new Table();<o:p></o:p>

table.ColumnAdjustment = ColumnAdjustment.AutoFitToContent;

Row row = table.Rows.Add();

Cell cell = row.Cells.Add("Cell 1 text");

cell = row.Cells.Add("Cell 2 text");

table.GetWidth();

Assert.IsTrue(cell.Width ==
44.47);

The issues you have found earlier (filed as PDFNET-38548) have been fixed in Aspose.Pdf for .NET 17.3.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
(7)