Aspose.PDF.Table defined in XML how to bind it with .NET DataTable

Hello, I have a .NET DataTable containing the data, instead of defining the Table(Aspose.pdf.table) in the code I have defined it in the XML file now I want to bind the rows and columsn of my .NET DataTable to this XML table and to populate my report.

can you please guide how can I do that.

Hi,

Thank you for considering Aspose.

You can do that by following the below mentioned steps:

1. Create a Pdf instance and bind the XML template file to Pdf instance. Please refer to following code:

Pdf pdf1 = new Pdf();
pdf1.BindXML("Template.xml",null);

//Get the section and then table from the obtained section of the Pdf that
//is built from the XML template
Section sec1 = pdf1.Sections["Section1"];
Table table1 = sec1.Paragraphs["Table1"] as Table;

2. Now, use this table and then get the data from the Datatable. Please refer to the following article:

If you need more help please do let us know.

Thanks.

Adeel Ahmad
Support Developer
Aspose Changsha Team

Hello thankx for the reply, dont know what I am doing wrong once again I am describing my self please help me out...thankx

Ok I did a HELLO WORLD example in arabic and wrote some arabic text(إيداع نقدي فرع)using a XML file and able to write arabic data successfully based on the configured XML file and C# code. I figured out that I am able to write the arabic text by setting these properties of Segment

  • FontName="Times New Roman"
  • FontSize="14"
  • IsUnicode="true"
  • IsRightToLeft="true"

Upto here no question.

Now the issue is when I am trying to write the real data which is a .NET DataTable column containing arabic data using C# code I am lost and not able to write the arabic data successfully, can you please provide me some sample code or some example, I tried the example available at your wiki but its not working for me. coz I need to write the dynamic data the example at wiki is good for a static string

My target is to write that arabic text column in the pdf either way using a C# code or by defining and configuring the table in the xml and setting the properties of segment as mentioned above.

I hope the above problem will give you good idea.

I am lost some where plz help me....

Thankx and best regards

Khurram Shahzad

Hi,

I think this task can be achieved like:

1. when you are defining the table in Aspose.Pdf then create a textInfo class object.

2. Set textInfo properties like :

  • FontName =“Times New Roman”
  • FontSize=“14”
  • IsUnicode=“true”
  • IsRightToLeft="true"
3. Assign table.DefaultCellTextInfo to the object of TextInfo defined in step 2

4. Now, call ImportDatatable containing Arabic text

Hope it works. If it still won’t work then I think it need to change the Arabic unicode text to Ascii string and then save it in Datatable and then call importDatatable method.

Thanks.

Thankx for the reply, I am trying your suggested solution, but I think by it will convert the whole table in unicode format while writing to pdf, my concern is that only the description column should be written in arabic not the whole table, is there a way that we can define only 1 column in a table to written as unicode and set its properties from RIGHTTOLEFT etc...

Thankx for the support....

Khurram

AdeelTaseer:
Hi,

I think this task can be achieved like:

1. when you are defining the table in Aspose.Pdf then create a textInfo class object.

2. Set textInfo properties like :
  • FontName ="Times New Roman"
  • FontSize="14"
  • IsUnicode="true"
  • IsRightToLeft="true"

3. Assign table.DefaultCellTextInfo to the object of TextInfo defined in step 2

4. Now, call ImportDatatable containing Arabic text

Hope it works. If it still won't work then I think it need to change the Arabic unicode text to Ascii string and then save it in Datatable and then call importDatatable method.

Thanks.

dear I tried your suggested approach but it did not work... please i am stuck in the middle please help me out..

thankx

Hi,

To set one Column Format in a table. Please check:

http://www.aspose.com/wiki/default.aspx/Aspose.Pdf/SettingRowAndColumnFormat.html

If it is still won’t works, then can you provide your source code?

Thanks.

Thanks dear it workd but instead of using the import table , I am creating a row object of Aspose.pdf.table and then writing and formatting it, which is working fine for the time being, now there is a serious issue., when we are generating a arabic report and trying to save, it is taking 30 seconds to save to the disk where as the english report is being saved on the disk in a flash....

for both arabic and english reports we are using the same Data Access Routines and methods but dont know why this arabic report is taking soo much time....plz need your expertise here....help us...coz due to this issue we cannot go live.....

Hi,

Please try adding these two lines of code before Save and then let us know the results.

pdf.IsTruetypeFontMapCached = true;
pdf.TruetypeFontMapPath = Path.GetTempPath();

Thanks.

AdeelTaseer:
Hi,

Please try adding these two lines of code before Save and then let us know the results.

pdf.IsTruetypeFontMapCached = true;
pdf.TruetypeFontMapPath = Path.GetTempPath();

Thanks.

Thankx this solution worked and now arabic reports are almost taking the same amount of time as of english reports.