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

Free Support Forum - aspose.com

Setting the Border on specific cells within Table

Hello, I’m using Aspose.Pdf.Generator version 8.3.1.0 and I’m trying to change the border on certain cells within my Table such that when a specific value is encountered, I want to set the top border to a blue line. However, this is not working properly as only the top border of the table is changing whereas I want the border on the individual cells to be changed . Here is my code:


using Aspose.Pdf.Generator;
dataTable.ImportDataTable(ConstructDummyDataTable(), false, 0,0);

foreach (Row row in dataTable.Rows)
{
string value = row.Cells[Constants.ICDDESCRIPTION_IDX].GetText();
if (value.Equals(“Total”))
{
GraphInfo line = new GraphInfo();
line.DashLengthInBlack = 2.5F;
line.LineWidth = 2.0F;
line.IsAddedArrowAtEnd = true;
line.Color = new Color(“Blue”);

BorderInfo bdrTotalCell = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.Top, line);

Aspose.Pdf.Generator.TextInfo txtBoldInfo = new Aspose.Pdf.Generator.TextInfo();
txtBoldInfo.IsTrueTypeFontBold = true;
txtBoldInfo.FontSize = 10F;
txtBoldInfo.FontName = “Calibri”;
row.DefaultCellTextInfo = txtBoldInfo;

row.Cells[Constants.LOCALINPUT_IDX].Border = bdrTotalCell;
row.Cells[Constants.USADJ_IDX].Border = bdrTotalCell;
row.Cells[Constants.USGAAP_IDX].Border = bdrTotalCell;
}
}

Please note that for some reason the borders on the individual cells are not appearning. Please help. I’ve been working over the thanksgiving holiday to get this to work properly and I’ve tried everything.

Thanks.

Hi Henry,


Thanks for contacting support and sorry for the inconvenience which you have been facing.

Please note that Aspose.Pdf.Generator namespace has some issues when creating table, row, cells objects. Therefore in order to produce correct output, please try using the new Document Object Model approach of Aspose.Pdf for .NET. Please take a look over following code snippet in which I have tried setting the top border of one row as Blue and its properly appearing. For your reference, I have also attached the resultant PDF generated with Aspose.Pdf for .NET 8.6.0.

[C#]

//Instntiate the Document object by
calling its empty constructor
<o:p></o:p>

Document doc = new Document();

Page page = doc.Pages.Add();

//Instantiate a table object

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

//Add the table in paragraphs collection of the desired section

page.Paragraphs.Add(tab1);

//Set with column widths of the table

tab1.ColumnWidths = "50 50 200";

//Set default cell border using BorderInfo object

tab1.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F);

//Set table border using another customized BorderInfo object

tab1.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 1F);

//Create MarginInfo object and set its left, bottom, right and top margins

Aspose.Pdf.MarginInfo margin = new Aspose.Pdf.MarginInfo();

margin.Top = 5f;

margin.Left = 5f;

margin.Right = 5f;

margin.Bottom = 5f;

//Set the default cell padding to the MarginInfo object

tab1.DefaultCellPadding = margin;

//Create rows in the table and then cells in the rows

Aspose.Pdf.Row row1 = tab1.Rows.Add();

row1.Cells.Add("col1");

row1.Cells.Add("col2");

row1.Cells.Add();

TextFragment mytext = new TextFragment("col3 with large text string");

//row1.Cells.Add("col3 with large text string to be placed inside cell");

row1.Cells[2].Paragraphs.Add(mytext);

row1.Cells[2].IsWordWrapped = false;

row1.Cells[2].Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.Top, Aspose.Pdf.Color.Blue);

//row1.Cells[2].Paragraphs[0].FixedWidth= 80;

Aspose.Pdf.Row row2 = tab1.Rows.Add();

row2.Cells.Add("item1");

row2.Cells.Add("item2");

row2.Cells.Add("item3");

//Save the Pdf

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

Hi there, do you have any code samples using the Aspose.PDF namespace and not the Aspose.PDF.Generator namespace. It looks like I’m going to have to redo my entire solution using the Aspose.PDF namespace and I need some samples. The samples provided on your website are in the Aspose.Pdf.Generator namespace. I would like code samples of how to create a header/footer on each page, how to set the page to a landscape on the margins, and how to import data from a datatable. I’m not very satisfied with the product now considering that everything that I have written will now have to be rewritten.

Thanks.

Hi Henry,


Due to technical difficulties and limitations in legacy Aspose.Pdf.Generator namespace, we had to rework and introduce the new Document Object Model based on Aspose.Pdf namespace. With every new release, we are trying our level best to introduce same set of features/functionalities in Aspose.Pdf namespace as present in Aspose.Pdf.Generator. Please visit the following links for further details on


I am afraid currently Aspose.Pdf namespace does not support the feature to convert Portrait page to Landscape orientation. However for the sake of implementation, I have logged this issue as PDFNEWNET-36115 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.

<o:p></o:p>

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


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

Hi Henry,


Thanks for your patience. As stated above your reported issue is resolved in Aspose.Pdf for .NET 9.6.0. Please note Rotation property changes orientation of entire page including its contents. In order to change page size you can set MediaBox of the page in the following way.

Document doc = new
Document(“PdfWithText.pdf”);<o:p></o:p>

foreach (Page page in doc.Pages)

{

Aspose.Pdf.Rectangle r = page.MediaBox;

double newHeight = r.Width;

double newWidth = r.Height;

double newLLX = r.LLX;

//we must to move page upper in order to compensate changing page size (lower edge of the page is 0,0 and information is usually placed from the top of the page. That's why we move lover edge upper on difference between old and new height.

double newLLY = r.LLY + (r.Height - newHeight);

page.MediaBox = new Aspose.Pdf.Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight);

//sometimes we also need to set CropBox (if it was set in original file)

page.CropBox = new Aspose.Pdf.Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight);

}

doc.Save("36115.pdf");


Please note that in that case you can cut some contents of the document (because we decrease height)
in order to avoid this you can increase width proportionally and leave height intact as following:

Aspose.Pdf.Rectangle r = page.MediaBox;

//new height the same

double newHeight = r.Height;

//new width is expanded proportionally to make orientation landscape (we assume that previous orientation is portrait)

double newWidth = r.Height * r.Height / r.Width;


Other option is to use PdfPageEditor facade (it can apply zoom to page contents)


Document doc = new Document("PdfWithText.pdf");

Aspose.Pdf.Rectangle r = doc.Pages[1].Rect;

PdfPageEditor ppe = new PdfPageEditor();

ppe.BindPdf("PdfWithText.pdf");

ppe.Zoom = (float)(r.Width / r.Height);

ppe.PageSize = new Aspose.Pdf.PageSize((float)r.Height, (float)r.Width);

ppe.Save("36115-1.pdf");

Please feel free to contact us for any further assistance.


Best Regards.