Preserve Table Column Cell Widths Layout - Convert Word DOCX Document to PDF using Java

I have generated a table in doc and pdf both. The table generated in the doc is retaining all the property whatever we have set. But in pdf getting in a distorted format. I have attached the pdf and doc file for the same.

New Imaging_Board Meeting_agenda (15).pdf (70.9 KB)
New Imaging_Board Meeting_agenda (29).zip (150.0 KB)

For pdf saving, i am using below code

genFileWithPath = PDF_FOLDER + asposeGeneratedFileName;
PdfSaveOptions options = new PdfSaveOptions();
options.getOutlineOptions().setDefaultBookmarksOutlineLevel(1);
options.getOutlineOptions().setHeadingsOutlineLevels(2);
// options.setFontEmbeddingMode(PdfFontEmbeddingMode.EMBED_ALL);
// options.setPreserveFormFields(true); 
document.save(genFileWithPath,options);

Do we need to set any other property to in pdf save option to retain the table?

@Gptrnt,

We tested the scenario and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-19933. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.

Hi @awais.hafeez

Is there any release ETA available for the issue WORDSNET-19933 created? Let us know as this is blocking a critical feature release for us.

@Gptrnt,

The issue actually depends on the resolution of an internal extremely complex issue (WORDSNET-832). Therefore, WORDSNET-19933 is postponed until at least WORDSNET-832 is resolved, we will review your issue after the resolution of WORDSNET-832. Unfortunately, there is no ETA available at the moment. We will inform you via this thread as soon as this issue will be resolved or any further updates may be available. We apologize for your inconvenience.

P.S. You may re-save the document via MS Word as a workaround.

@awais.hafeez
We are doing this programmatically and there are other PDF operations we do (like stitching multiple documents) in case of PDF generation. Let us know if there is any way to expedite the fix for this issue.

@roshanhadal,

The underlying core issue WORDSNET-832 already has the highest priority level set in our issue tracking system. Unfortunately, the issue is related to a tricky area of MS Word Table Column width calculation logic which is currently not fully understood. Rest assured, you will be notified via this thread as soon as your issue will be resolved in future. Sorry for the inconvenience.

How do I find what WORDSNET-832 is? I am currently having issues with a Docx being converted to PDF in Aspose.Words .Net where i see a lot of
Table column widths may need to be calculated. Rendered column widths could differ.
At Table 1, Section 1
For 4 identical tables (checked the docx source) and only the last table have a correct rendering in the PDF.

@Robert_Karlsson,

WORDSNET-832 is about making the Table layout as close to MS Word as possible during rendering to PDF, XPS or Image formats etc. We are striving hard to remove differences between the Table Column widths we calculate and the widths MS Word calculates. Unfortunately, there is no direct way that you can use to track issues or check details of issues by yourself. But, you are welcome to ask your issue status via forum threads. We will verify the status from our internal issue tracking system and then reply you back.

Do you have any other Word documents where you are seeing corrupt table layout in Aspose.Words generated PDF? If yes, please feel free to share other documents as well. Thanks for your cooperation.

The issues you have found earlier (filed as WORDSNET-19933) have been fixed in this Aspose.Words for Java 23.8 update.

@Gptrnt @Robert_Karlsson @cimplyfive The issue with table column widths has been fixed by a recent WORDSNET-25594 integration.

However, in order to get the correct result, you should change the code so that an advanced typography feature (kerning) is supported.

Some contents in the problematic table have font kerning enabled. Content metrics taking kerning into account are needed in order to get the correct table layout.
Kerning is an advanced typography feature which is supported by Aspose.Words via Aspose.Words.Shaping.HarfBuzz nuget package.
You should install the above package and modify the code as shown below:

Document doc = new Document("E:\\Temp\\New Imaging_Board Meeting_agenda (29)\\New Imaging_Board Meeting_agenda (29).docx"); 
// Configure shaping before saving to pdf or accessing the document layout model in any other way. 
doc.LayoutOptions.TextShaperFactory = Aspose.Words.Shaping.HarfBuzz.HarfBuzzTextShaperFactory.Instance; 
...

See more about advanced typograph features in the documentation: https://docs.aspose.com/words/net/enable-opentype-features/.

Hi,

I am using spring boot with Maven and I couldn’t find any package for Java in Aspose.Words.Shaping.HarfBuzz nuget package. This package is only for dot net.

Thank you

@Gptrnt Aspose.Words.Shaping.HarfBuzz is also available for Java. You can get it from here:
https://releases.aspose.com/words/java/
Or you can see reference to it using maven:

...
<dependency>
	<groupId>com.aspose</groupId>
	<artifactId>aspose-words</artifactId>
	<version>23.8</version>
	<classifier>jdk17</classifier>
</dependency>
<dependency>
	<groupId>com.aspose</groupId>
	<artifactId>aspose-words</artifactId>
	<version>23.8</version>
	<classifier>shaping-harfbuzz-plugin</classifier>
</dependency>
...