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

Free Support Forum - aspose.com

Converting Documents to PDF

Hi, I have a word document that I’ve used nested data tables with and the document looks fine, however the conversion to PDF has overlapped the tables. I’m hoping you can help me out as this is causing quite an issue for me and I’d hate to revert back to some older code that works but doesn’t use the nesting of data tables which is far more elegant than manually inserting data into the tables after they’ve been merged.
I’ve attached 3 documents, one is the template being used, one is the document and one is the pdf. I’m using version 9.3, I’m aware there were table issues but thought these had been fixed by this release. I’m not sure if 10 is expected to fix this issue or not.

_doc.Save(@"d:\temp\test.pdf", SaveFormat.Pdf);
_doc.Save(@"d:\temp\test.docx", SaveFormat.Docx);

Thanks a lot for you help with this.

Hi Nolan,
Thanks for your inquiry.
I can’t seem to spot the issue in the input and output documents you attached - both input document and PDF look the same. I cannot find any nested tables within your template as well.
Could you please clarify where the issue is located in the rendered output and I will take another look?

Hi Adam,
Thanks for you’re prompt reply. I believe the issue may not be with the tables themselves, but the way I’m removing the paragraphs from the tables.
In the document template, the structure is as follows
TableStart:Claims TableStart:Messages TableEnd:Messages TableEnd:Claims
TableEnd: ClaimTypes
So, for each claim type, there is a list of claims, and each claim can have a list of messages. Now, when there are messages, they are linked correctly tot the Claims Table, however, for each claim record in the datatable, a new table is created in the document. I believe this is because the table start/end of claims is not contained in the same row in the table (which just isn’t possible as the messages must be after the claim row)
So to get around this in the document, I removed each of the paragraphs around each of the tables, which appeared to join all the tables to be one big ClaimTypes table, which is visible in the document supplied.
After review of the xml of the document, it hasn’t actaully merged the tables at all (even though word interpretes it that way when viewing the document) so when it’s saved to pdf, it renders the tables as it sees them. I wouldn’t care if it left the spaces there between each of the tables, but if you review the documents side by side, you’ll see that some of the claim types from the first table actually span through and under the 2nd table, which is clearly not right.
I believe the way I need to format my data is causing this issue, e.g the table layout, however, I cannot se that this can be resolved. What I need to try and do I believe is merge the tables together where I’m currently just removing the paragraphs.
Any help you can give would be much appreciated. Following is my code used to join the tables and remove the paragraphs.

ClaimTypeTable = DataSourceDataSet.Tables[1];
ClaimsTable = DataSourceDataSet.Tables[2];
Messages = DataSourceDataSet.Tables[3];
DataRelation claimTypeRelation;
DataColumn[] master1 = new DataColumn[]
DataColumn[] slave1 = new DataColumn[]
claimTypeRelation = new DataRelation("claimTypeRelation", master1, slave1);
DataRelation messageRelation;
DataColumn[] master2 = new DataColumn[]
    ClaimsTable.Columns["ClaimNo"], ClaimsTable.Columns["ClaimLineNo"]
DataColumn[] slave2 = new DataColumn[]
    Messages.Columns["ClaimNo"], Messages.Columns["ClaimLineNo"]
messageRelation = new DataRelation("messageRelation", master2, slave2);
DocumentBuilder builder = new DocumentBuilder(_doc);
foreach(Table table in builder.CurrentStory.Tables)
    if (table.PreviousSibling.NodeType == NodeType.Paragraph)
    if (table.NextSibling.NodeType == NodeType.Paragraph)
    ForceNewPagePerTable(_doc, table);
_doc.Save(documentName, SaveFormat.Docx);
_doc.Save(@"D:\Test\temp.pdf", SaveFormat.Pdf);

Thanks for you time and assistance.

Hi Nolan,
Thanks for this additional information and for providing a clear description.
Ah I see what you mean now. You are correct when saying the tables aren’t actually one single table, they are only interpreted as being so by MS Word. This is why in your other thread I reluctantly said “the tables will be combined into ‘one’”.
To get around this as you suggested you can properly combine all these tables. I have tested this and the output appears to look properly now. The code is from this API page here.

Document doc = new Document("test.docx");
Table firstTable = doc.FirstSection.Body.Tables[0];
foreach(Table table in doc.FirstSection.Body.Tables)
    if (table != firstTable)
        // Append all rows from the current table to the next.
        // Due to the design of tables even tables with different cell count and widths can be joined into one table.
        while (table.HasChildNodes)
doc.Save("test out.pdf");

If you have any further queries please feel free to ask.

Hi, thanks for that Adam, while I still had to do quite a bit of messing around with it, you’re solution eventually provided me with the glue to hold it together.
The extra challenge I had was that there could be multiple claim type tables, and a summary line in between them so I couldn’t simply iterate over all tables and join them, however, as I knew the number of records for each of the claim types, I was able to use that number and iterate over the tables a specific number of times.
All in all, it works and looks great.
Thanks for your help.