How to create 10 columns with aspose.pdf

How to create 10 columns with aspose.pdf? I am not able to create more than 3 columns. I have to create 18 row and 10 columns with this.

I wrote following snippet:
Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
//Instantiate License class and call its SetLicense method to use the license
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(“Aspose.Pdf.lic”);
//Add a section into the pdf document
Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();
Aspose.Pdf.Generator.Table tab1 = new Aspose.Pdf.Generator.Table();
//Add the table in paragraphs collection of the desired section
sec1.Paragraphs.Add(tab1);
//Set with column widths of the table
tab1.ColumnWidths = “50 50 50 “;


//Set default cell border using BorderInfo object
tab1.DefaultCellBorder = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All, 0.1F);
//Set table border using another customized BorderInfo object
tab1.Border = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All, 1F);
//Create MarginInfo object and set its left, bottom, right and top margins
Aspose.Pdf.Generator.MarginInfo margin = new Aspose.Pdf.Generator.MarginInfo();
margin.Top = 1f;
margin.Left = 1f;
margin.Right = 1f;
margin.Bottom = 1f;

//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.Generator.Row row1 = tab1.Rows.Add();
row1.FixedRowHeight = 20;
row1.Cells.Add(“test”);
row1.DefaultCellTextInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Left;
row1.DefaultCellTextInfo.FontSize = 10;
row1.Cells.Add(””);
row1.Cells.Add("");

Aspose.Pdf.Generator.Row row2 = tab1.Rows.Add();
row2.Cells.Add(“test:”);
row2.DefaultCellTextInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Left;
row2.Cells.Add("");
row2.Cells.Add(“test”);


pdf1.Save(“d:\test.pdf”);



Appreciate a quick response

Hi Arunava,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

You need to define the same number of cells in a row as the number of columns you specify in the ColumnWidths property e.g. if you define Table.ColumnWidths =”50 50 50 50” then you need to define 4 cells against each row to make four columns visible. Please see the following updated code to create 10 columns in a table.

//Instantiate License class and call its SetLicense method to use the license

Aspose.Pdf.License license = new Aspose.Pdf.License();

license.SetLicense(@"D:\AP Data\Aspose.Total.lic");

Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

//Add a section into the pdf document

Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();

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

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

sec1.Paragraphs.Add(tab1);

//Set with column widths of the table

tab1.ColumnWidths = "50 50 50 50 50 50 50 50 50 50";

tab1.ColumnAdjustment = ColumnAdjustmentType.Customized;

//Set default cell border using BorderInfo object

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

//Set table border using another customized BorderInfo object

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

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

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

margin.Top = 1f;

margin.Left = 1f;

margin.Right = 1f;

margin.Bottom = 1f;

//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.Generator.Row row1 = tab1.Rows.Add();

row1.FixedRowHeight = 20;

row1.Cells.Add("test");

row1.DefaultCellTextInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Left;

row1.DefaultCellTextInfo.FontSize = 10;

row1.Cells.Add("");

row1.Cells.Add("");

row1.Cells.Add("");

row1.Cells.Add("");

row1.Cells.Add("");

row1.Cells.Add("");

row1.Cells.Add("");

row1.Cells.Add("");

row1.Cells.Add("");

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

row2.Cells.Add("test:");

row2.DefaultCellTextInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Left;

row2.Cells.Add("");

row2.Cells.Add("test");

row2.Cells.Add("");

row2.Cells.Add("");

row2.Cells.Add("");

row2.Cells.Add("");

row2.Cells.Add("");

row2.Cells.Add("");

row2.Cells.Add("");

pdf1.Save("d:\\AP Data\\test.pdf");

If you have any further query or need any further assistance, please feel free to contact support.

Thank You & Best Regards,

I used this snippet as you said but it is not showing more than 3 columns in PDF…Could u tell me the reasons of that??
tab1.ColumnWidths = “50 50 50 50 50 50 50 50 50 50”;
tab1.ColumnAdjustment = Aspose.Pdf.Generator.ColumnAdjustmentType.Customized;

I used following license: Aspose.Pdf.lic
thanks


Hi Arunava,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I think you are still not specifying the Row.Cells equal to the number of columns in your code. Please see the bold code segment and change your code accordingly.

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

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

row1.FixedRowHeight = 20;

row1.Cells.Add("test");

row1.DefaultCellTextInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Left;

row1.DefaultCellTextInfo.FontSize = 10;

row1.Cells.Add("");

row1.Cells.Add("");

row1.Cells.Add("");

row1.Cells.Add("");

row1.Cells.Add("");

row1.Cells.Add("");

row1.Cells.Add("");

row1.Cells.Add("");

row1.Cells.Add("");

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

row2.Cells.Add("test:");

row2.DefaultCellTextInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Left;

row2.Cells.Add("");

row2.Cells.Add("test");

row2.Cells.Add("");

row2.Cells.Add("");

row2.Cells.Add("");

row2.Cells.Add("");

row2.Cells.Add("");

row2.Cells.Add("");

row2.Cells.Add("");

Please do let us know if you still face any problem.

Thank You & Best Regards,

thanks It is working…

is it possible to merge cells ?
Aspose.Pdf.Generator.Row row17 = tab1.Rows.Add();
row17.DefaultCellTextInfo.FontSize = 7;
row17.Cells.Add(“Approved By:”);
row17.Cells.Add("");
row17.Cells.Add("");
row17.Cells.Add(""); /want to merge these two cells…
row17.Cells.Add("");/

row17.Cells.Add("");
row17.Cells.Add("");
row17.Cells.Add("");
row17.Cells.Add("");
row17.Cells.Add("");

Hi Arunava,

From cell marge, do you mean you need to span a single cell over multiple columns ? If so is the case, then please visit the following link for required information on
Set Width and Span of the Column.

In case I have not properly understood your requirement, please share some details.

Aspose.Pdf.Generator.Row row17 = tab1.Rows.Add();
row17.DefaultCellTextInfo.FontSize = 7;
row17.Cells.Add(“Approved By:”);
row17.Cells.Add("");
row17.Cells.Add("");
row17.Cells.Add(""); //1
row17.Cells.Add("");//2
row17.Cells.Add("");//3
row17.Cells.Add("");
row17.Cells.Add("");
row17.Cells.Add("");
row17.Cells.Add("");
I want to merge these 1,2,3 cells. What 'll be the code???

Hi Arunava,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

As informed by Nayyer, you can use the Cell’s ColumnsSpan feature to achieve your desired result. Please see the following updated code for your reference:

Aspose.Pdf.Generator.Row row17 = tab1.Rows.Add();

row17.DefaultCellTextInfo.FontSize = 7;

row17.Cells.Add("Approved By:");

row17.Cells.Add("");

row17.Cells.Add("");

row17.Cells.Add("");//1

row17.Cells.Add("");//2

row17.Cells.Add("");//3

row17.Cells.Add("");

row17.Cells.Add("");

//As Column Span will be set to 3 columns,

//so last 2 columns in the row will not be required.

// row17.Cells.Add("");

// row17.Cells.Add("");

// Get the column at index 3 and set the span

Cell cell = row17.Cells[3];

cell.ColumnsSpan = 3;

Please try it and let us know if this feature fits your need.

Thank You & Best Regards,

Perfect!!!
Thanks…a lot to ASPOSE team…