The file “test.docx” was edited in a JS editor and saved as “test (after JS editor).docx”.
Then, the file “test (after JS editor).docx” was converted to “test.pdf” using Aspose.Words.
In “test.pdf”, the table width changed, as shown in the screenshot.
It seems the JS editor is behaving incorrectly, but it’s not critical since the file “test (after JS editor).docx” displays correctly in MS Word without distortions. Is it possible to “fix” the document upon loading the file using Aspose.Words?
When a DOCX file is edited by a third‑party JavaScript editor the internal table layout information can be left in a state that Word can still render correctly (Word “re‑calculates” the layout on the fly).
Aspose.Words, however, uses the layout data stored in the package as‑is. If that data is incomplete or contradictory, the PDF renderer will fall back to its own layout engine, which may produce a different column width.
The good news is that Aspose.Words can re‑calculate the table layout for you before the document is saved to PDF.
Quick fix: Re‑calculate the table layout
// C# example
using Aspose.Words;
using Aspose.Words.Saving;
Document doc = new Document(@"test (after JS editor).docx");
// Force Aspose.Words to rebuild the table layout information
doc.UpdateTableLayout(); // <-- this is the key line
// Optional: you can also force the modern layout algorithm
doc.LayoutOptions.TableLayout = TableLayoutType.Autofit;
// Save as PDF
PdfSaveOptions saveOptions = new PdfSaveOptions();
doc.Save(@"test.pdf", saveOptions);
// Java example
import com.aspose.words.*;
Document doc = new Document("test (after JS editor).docx");
// Re‑calculate the layout of all tables
doc.updateTableLayout(); // <-- key method
// (Optional) use the modern table layout algorithm
doc.getLayoutOptions().setTableLayout(com.aspose.words.TableLayoutType.AUTOFIT);
// Save to PDF
PdfSaveOptions pdfOpts = new PdfSaveOptions();
doc.save("test.pdf", pdfOpts);
What UpdateTableLayout() does
Parses the table grid definitions and column widths stored in the DOCX.
If some columns are missing explicit widths, Aspose.Words will auto‑fit them according to the content (the same behaviour Word shows when you open the file).
The method updates the internal layout model, so the subsequent PDF rendering uses the corrected widths.
When the simple call is not enough
If you still notice a mismatch, try the following additional tweaks:
Document doc = new Document("test (after JS editor).docx");
doc.UpdateTableLayout(); // re‑calculates table widths
doc.Save("test.pdf", new PdfSaveOptions());
Running the code above (or the equivalent Java snippet) should eliminate the table‑width distortion you see after conversion. If the problem persists, let us know the points listed under How to verify the fix and we’ll help you further.
@LogOS2 Through UpdatTableLayout works in your case, this method is deprecated. UpdateTableLayout method was the first attempt of table grid calculation algorithm implementation. Currently another implementation is used internally by Aspose.Words, so normally there is no need to call additional methods to calculate table layout. So please use UpdatTableLayout carefully. We will look what is wrong with table rendering.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): WORDSNET-28616
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.