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

# Table layout broken in PDF after UpdateTable

Hello,

we noticed a bug with broken table layouts in pdf documents, after calling UpdateTable(). Saving the document as .docx works fine. Converting the altered .docx file to PDF with Microsoft Word also works fine.

I noticed, that in the original document, at some point the colums do not match any more exactly:
2021-08-11_13-10-52.png (7.9 KB)

I also discovered, as a workaround, that moving the column at the broken row back into position, as shown in the gif, fixes the issue:
2021-08-11_13-11-19.gif (61.0 KB)

However, with the original document without the manual workaround still seems to be a bug in Aspose, as the pdf conversion with Office is working fine.

Test code:

            var doc = new Document(@"S:\tmp\in.docx");
doc.UpdateTableLayout();
doc.Save(@"S:\tmp\out.pdf");


in.docx -> original input file
out.pdf -> PDF generated with Aspose with broken table (Broken)
out.docx -> Altered document saved as docx with Aspose
out_word.pdf -> out.docx converted to PDF with MS Word 2019 (Working)

in_edited.docx -> original input file with workaround as shown in the gif
out_edited.pdf -> in_edited.docx converted to PDF by Aspose (Working)

files.zip (303.3 KB)

I hope you can look into the issue and the information about the workaround helps to identify the issue maybe.

Daniel

@Serraniel

We have tested the scenario and managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-22600. You will be notified via this forum thread once this issue is resolved.

@Serraniel Normally it is not recommended to call Document.UpdateTableLayout method. See Remarks section for more information. In your case if do not call this method the generated PDF document looks perfectly.
Is there a reason why you call this method before saving your document to PDF?

Hi Alexey,

thanks for your reply. We introduced the UpdateTableLayout method call in 2017, after we had been suggested here: PDF conversion with margins and tables in doc files

It had been a fix to (several) other issues with tables we have had in the past. I sadly cannot access the attachments any more (I assume it had been from the old forum) to validate, if the issue from back then would still occure in a current Aspose version, if we would not use the UpdateTableLayout.
In general, our customers could upload any type of document and we have sticked with calling the function for a while now.
Or is there any way to dynamically decide by code, whether to call UpdateTableLayout or not, when converting documents to PDF, when you know there those who only will work with it being called and those which only work correctly, if it is not called?

Daniel

@Serraniel I will consult with the responsible developer and provide you more information.

@Serraniel Excuse me for a late response, the responsible developer was on his vacation.
It is strongly not recommended to call Document.UpdateTableLayout method. This was the first attempt to mimic MS Word behavior on table rendering and this attempt was not quite successful. Document.UpdateTableLayout method quite rarely gives good result and unfortunately there is no method to programmatically detect whether Document.UpdateTableLayout will give good result.
Currently another algorithm is under development and it is already partially used by Aspose.Words. Document.UpdateTableLayout method will be marked as deprecated after the next update of the new algorithm and then will be fully removed.

Thanks for your reply. We have decided to not use the UpdateTableLayout method any more.

However, I was able to find the old document in our Jira which was having issues when we not call the UpdateTableLayout method and I can confirm, this issue still exists in the current version of Aspose. If possible we would like to resubmit this issue again then, as it is not working as intended. Should I upload the document here or should I just update the old topic of 2017, in which he had been suggested to use the UpdateTableLayout method workaround for this?

Yes. I attached a zip with the document and the PDF result (out.pdf). I also included a pdf file, how it is expected to look like (reproduced by opening the document with word and setting margins to 4cm in word and exporting to pdf with word).

Testcode:

            var doc = new Document(@"S:\tmp\table\original.doc");

// 4 cm border
var pageSetup = new DocumentBuilder(doc).PageSetup;
var margin = ConvertUtil.MillimeterToPoint(40);

pageSetup.TopMargin = margin;
pageSetup.RightMargin = margin;
pageSetup.BottomMargin = margin;
pageSetup.LeftMargin = margin;

doc.Save(@"S:\tmp\table\out_withUpdate.pdf");


The old topic was: PDF conversion with margins and tables in doc files