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.

Thanks for your help,
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.

We apologize for your inconvenience.

@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: https://forum.aspose.com/t/pdf-conversion-with-margins-and-tables-in-doc-files/18614/3?u=serraniel

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?

Thanks for your help,
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?

@Serraniel Please upload the document here and provide the link to your old thread. I will resubmit the issue.

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: https://forum.aspose.com/t/pdf-conversion-with-margins-and-tables-in-doc-files/18614/3

Thanks for your help.

files.zip (96.9 KB)

@Serraniel Thank you for additional information. I reopened the issue as WORDSNET-22711. We will keep you informed about it’s status.

Hello,

as the UpdateTableLayout method had been marked as deprecated I have started to review older tickets related to table updates.
As it is going to be removed I think you maybe can close WORDSNET-22600 as this error does not occure without calling UpdateTableLayout and I assume fixing a deprecated method is not useful.

WORDSNET-22711 however still is an issue and will become more urgent for us, if the method will be removed sooner or later, as this is about an error which happens without calling the UpdateTableLayout method. So I wanted to ask if there is an estimation about that second issue or plans to fix the bug.

Thanks for your help,
Daniel

@Serraniel Thank you for your feedback. Currently WORDSNET-22711 is postponed. Though grid recalculation for tables with cells spanning multiple columns is released, it is still not applied to the problematic table in your document, because of form fields. Form field content metrics are not considered reliable. We will keep working on table layout algorithm improvement and let you know once this issue is resolved or we have more information for you.

The issues you have found earlier (filed as WORDSNET-22711) have been fixed in this Aspose.Words for .NET 23.12 update also available on NuGet.