HI Support
I am writing a DataTable (PENTEST_01c: System Surface Components) to pdf with Aspose Pdf component. The problem is that Aspose is only exporting first 4 columns of DataTable to pdf file where as there are 7 columns in DataTable. I have attached a run time image “imageruntimeaspose.jpg” of my DataTable and also the output Pdf “Test5.pdf” which is generated by Aspose.
Please suggest me how can I export all columns of table “PENTEST_01c: System Surface Components” to pdf. The code I am writing is also shown in image I attached.
Thanks.
Hi Farhan,
Hi Farhan
Thanks for your reply. We already have bought a license for Aspose Total for .Net. Still we have a problem. Can you please figure out other causes of this problem.
Best regards
Daniyal
Hi Farhan
Here is the code that we are writing. We are setting license like this
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(“Aspose.Total.lic.xml”);
Pdf docPDF = new Pdf();
Section pdfSec1 = docPDF.Sections.Add();
PDFDBList(dbList, docPDF,pdfSec1);
foreach (DictionaryEntry entry in hash)
{
PDFTableRules(hash1, docPDF, pdfSec1);
}
docPDF.Save(reportFileName + “.pdf”);
Console.WriteLine("Created report " + reportFileName + “.pdf”);
private void PDFTableRules(Hashtable hash, Pdf pdf, Section pdfSec2)
{
ArrayList dbList = new ArrayList();
dbList = (ArrayList)hash[“tablerules”];
DataTable dataTable = new DataTable();
for (int i = 0; i < dbList.Count; i++)
{
String tableName = dataTable.TableName;
//ImportText(tableName, sheet);
dataTable = (DataTable)dbList[i];
if (dataTable.Rows.Count > 0)
{
Section pdfSec1 = pdf.Sections.Add();
//Add a text element for the document header
Text pdfHeadText = new Text(tableName);
//Define the text style for the header
pdfHeadText.TextInfo.FontName = “Arial”;
pdfHeadText.TextInfo.IsTrueTypeFontBold = true;
pdfHeadText.TextInfo.FontSize = 10;
pdfHeadText.TextInfo.LineSpacing = 5;
pdfSec1.Paragraphs.Add(pdfHeadText);
//Create a new table for the customer data
Aspose.Pdf.Generator.Table pdfTab = new Aspose.Pdf.Generator.Table();
pdfTab.Margin.Top = 10;
pdfSec1.PageInfo.PageWidth = 5760;
pdfSec1.PageInfo.PageHeight = 707.5F;
pdfSec1.Paragraphs.Add(pdfTab);
//Set with column widths of the table
// pdfTab.ColumnWidths = “800 800”;
//Create a default style for table text
TextInfo pdfTabTextInf = new TextInfo();
pdfTabTextInf.FontName = “Arial”;
// pdfTabTextInf.FontSize = 10;
// pdfTabTextInf.LineSpacing = 3;
pdfTab.DefaultCellTextInfo = pdfTabTextInf;
//Set column widths of the table
pdfTab.ColumnWidths = “40 100 100 100”;
//Set default cell border of the table using BorderInfo object
pdfTab.DefaultCellBorder = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All, 0.1F);
//Import data into the Table object from the DataTable created above
pdfTab.ImportDataTable(dataTable, true, 0, 0,dataTable.Rows.Count,dataTable.Columns.Count);
//Get 1st row from the table
Aspose.Pdf.Generator.Row row1 = pdfTab.Rows[0];
//Iterate through all cells in the row and set their background color to blue
foreach (Aspose.Pdf.Generator.Cell curCell in row1.Cells)
curCell.BackgroundColor = new Aspose.Pdf.Generator.Color(“SkyBlue”);
}
// sheet.Cells.ImportDataTable(dataTable, true, sheet.Cells.MaxRow + 2, 1);
}
}
Hi Daniyal,
pdfTab.ColumnWidths = “40 100 100 100 100 100 100”;
Hi Tilal
Thanks for solution. Now I am able to export 7 columns to PDF instead of 4 but some of my tables have more than 7 columns and thats why not all of columns of tables are getting exported.
Regards
Dani
Hi Dani,
Hi Tilal
Thanks for the code snippet. I have tried this code but I think that it doesn’t fit well to my need
as I have a lot of DataTable objects from database during runtime. If I use above snippet or code then I will have to change first Data.DataTable to Aspose Generator.DataTable and then export it to PDF,
I will prefer to use instead the function
pdfTab.ImportDataTable(dataTable, true, 0, 0,dataTable.Rows.Count,dataTable.Columns.Count);
to export data to PDF.
Can you please do
1. A simple connection to some database, retrieve some DataTable having more than 20 columns
2. Export it to PDF with AsposePDF using routine
ImportDataTable(dataTable, true, 0, 0,dataTable.Rows.Count,dataTable.Columns.Count);
and tell me how you can export 20 column table to aspose PDF correctly. Hopefully it will satisfy my needs.
Thanks.
Regards
Dani
Hi Dani,
Hi Dani,
Hi
Thanks for prividing the solution. The code you sent me works when dtc < 20. If there are more than 20 columns then these columns dont appear in output, Can you please increase dbc to 40 like
for (int dtc = 0; dtc < 40; dtc++)
dt.Columns.Add(“Head” + dtc, typeof(string));
and see what happens.
Thanks.
Best regards
Dani
Hi Dani,