The contents in the table is abnormal when convert word to pdf

when convert word to pdf,The contents in the table is abnormal
Document WordDoc = new Document("D:/1.docx);
WordDoc.save(“D:/1.pdf”);

We expect the display of the transformed pdf to be the same as for the word, Please see 1.jpg.
But the real results are quite different, Please see 2.jpg.
How to solve this problem?
Thanks202112.zip (228.0 KB)

@hlgao MS Word 2019 on my side displays and renders document to PDF the same way as Aspose.Words does. Please see the screenshot from MS Word on my side: image.png (18.1 KB)
What version of MS Words do you use on your side for viewing the document?

MS Word 2019
Please see the images
word02.jpg (53.8 KB)
word01.jpg (138.1 KB)

@hlgao Thank you for additional information. We will further investigate the issue and provide you more information.

@hlgao I have logged this problem as WORDSNET-23261. The document was displayed improperly in MS Word on my side because preferred authoring language in MS Word was set to English. If change it to Chinese, the document looks the same as on your side.
Also, I have noticed the document has been created by Aspose.Words. Do you generate it programmatically? If so, you can use fixed layout for the table to avoid the problem.

@alexey.noskov Thank you for your answer,Yes,the document is created by Aspose.Words,but how to set table’s fixed layout?

table.autoFit(AutoFitBehavior.AUTO_FIT_TO_CONTENTS);

Is that so?
I have tried this and could not reach the desired result.
I use it correctly?
Can you provide the specific operation code use java?
Thanks

@hlgao I mean that width of cells should be explicitly specified, i.e. to be fixed.

Do you generate your table using some template or you build your table from scratch in the code?
If it possible please provide the code you use for building the table, I will take a look and help you to modify the code.

@alexey.noskov
We converted the html file to word first, After doing some operations then generated the pdf.
Please see the html file
1224.zip (1.5 KB)

@hlgao In tis case, if you have a control over the source html, you can specify fixed cells width:

<table cellspacing="0" cellpadding="0" >
    <tr style="height:15.4pt">
        <td style="padding-right:0pt; padding-left:3pt;vertical-align:top;width:15pt">
            <p style="line-height: 130%; margin-top: 0pt; margin-bottom: 0pt; font-family: Simsun; font-size: 12pt; vertical-align: middle; widows: 0; orphans: 0">
                <span style="font-family:黑体; font-weight:bold">1.</span>
            </p>
        </td>
        <td style="padding-right: 5.4pt; padding-left: 5.4pt; vertical-align: top; width: 400pt">
            <p style="line-height:130%;margin-top:0pt;margin-bottom:0pt;font-family:Simsun;font-size:12pt;vertical-align:middle;text-align:left;widows:0;orphans:0">
                <span style="font-family:黑体; font-weight:bold">【答案】</span>
                【小题1】<span style="font-family:'Times New Roman'">D</span>【小题2】<span style="font-family:'Times New Roman'">C</span>【小题3】<span style="font-family:'Times New Roman'">A</span>
            </p>
        </td>
    </tr>
    <tr>
        <td style="padding-right:0pt; padding-left:3pt;width:15pt"><span>&#xa0;</span></td>
        <td style="padding-right: 5.4pt; padding-left: 5.4pt; vertical-align: top; width: 400pt">
            <p style="line-height: 130%; margin-top: 0pt; margin-bottom: 0pt; font-family: Simsun; font-size: 12pt; vertical-align: middle; text-align: left; widows: 0; orphans: 0">
                <span style="font-family:黑体; font-weight:bold">【解析】</span><span>【小题1】<span style="font-family:等线">根据材料可知,“数字粮仓”计划通过产地直供的模式进行商品销售,这就减少了商品流通环节,①错;利用田间地头的一手信息,可以建立原产地的农业品牌,提高其产品知名度和市场竞争力,②对;农产品保质期不会因销售方式的变化而延长,③错;电商平台的商品信息传播速度快、范围广,能扩大产品的市场销售范围,④正确。故选D。</span>
            </p><p style="text-align:left;line-height:130%;margin-top:0pt;margin-bottom:0pt;font-family:Simsun;font-size:12pt;vertical-align:middle;">【小题2】<span style="font-family:等线">“数字粮仓”通过产地直供的方式,让农产品从产地直接到达消费者手中,减少了农产品收获后的储存环节,降低了农产品的仓储成本,C正确。消费者每单购买农产品的数量有限,产地直供的方式会让农产品的运输成本有所提高,A错误。“数字粮仓”计划属于销售环节,对农作物生长周期和生产环境没有影响,B、D错误。</span></p><p style="text-align:left;line-height:130%;margin-top:0pt;margin-bottom:0pt;font-family:Simsun;font-size:12pt;vertical-align:middle;">
                【小题3】<span style="font-family:等线">黑龙江位于我国东北平原,黑土广布,土壤肥沃,地广人稀,粮食商品率高,是我国主要的商品粮生产基地,A正确;甘肃气候干旱,水资源匮乏,粮食产量不高,商品率低,B错误;四川和浙江的人口密度较大,粮食的需求量大,外销数量少,C、D错误。</span></span>
            </p>
        </td>
    </tr>
</table>

and in the code disable AllowAutoFit option for this table:

table.setAllowAutoFit(false);

@alexey.noskov
thanks. The pdf generated like this is normal.
But our documentation has many tables in it, Some tables we want to automatically adapt to the content. How to add the titles to these tables, and we can get the title in the word document use this code
table.getTitle("table title");

@hlgao You can mark the tables in your document using bookmarks. For example insert a bookmark into the first table cell and then use code like the following to get the bookmarked table:

Table table = (Table)doc.getRange().getBookmarks().get("MyBookmark").getBookmarkStart().getAncestor(NodeType.TABLE);

@alexey.noskov
sorry, I think I probably did not have made it clear.
we want make the title in html’s table , then convert it to word document, find the table with special title in word document, how to do it ?

table.zip (211 Bytes)

like this ,we can use the follow code to find it
table.getTitle("tablename1")

@hlgao Thank you for additional information. Unfortunately, Aspose.Words does not import title attribute into MS Word table. That is why I advised to use bookmark to identify the tables. You can put a bookmark in your HTML, please, see the following html:

<table title="tablename1">
	<tr>
		<td><a name="test" />name</td>
		<td>type</td>
	</tr>
</table>

Then you can easily access the table with the bookmark using code like the following:

Document doc = new Document("C:\\Temp\\table.html");

// Get table by a bookmark.
Table table = (Table)doc.getRange().getBookmarks().get("test").getBookmarkEnd().getAncestor(NodeType.TABLE);

// Check if the table has a bookmarks `test`
if (table.getRange().getBookmarks().get("test") != null)
    System.out.println("The table has bookmark 'test'");

@alexey.noskov
Thanks
but MS Word table has Alt Text Title, and Aspose can get it use table.getTitle(“tablename”)
20211228083843441.jpg (43.3 KB)

@hlgao Excuse me, my mistake. Aspose.Words does not import table title attribute from HTML, so there is no way to set this attribute in your source HTML document. This feature request is logged as WORDSNET-18494. We will keep you informed and let you know once this feature is implemented.

@alexey.noskov

when we convert 1228.htm to 1228.docx, the document is fine. But when we convert 1228.docx to pdf or export table to images , it’s not fine, please see 122801.pdf and 122801.png,
if we set
table.setAllowAutoFit(false);
Please see 122802.pdf and 122802.png,

how to get the same display in word document ,please see 1228.jpg
we use the following code to export table to image, Is the code both correct and highly efficient?

Document doc = new Document(MyDir + "1228.docx");
Table table = (Table)doc.getChild(NodeType.TABLE, 0, true);
render_Node(table, new ImageSaveOptions(SaveFormat.PNG)); 

Thanks

1228.zip (191.4 KB)

@hlgao The problem occurs because MS Word changes it’s behavior depending on the preferred authoring language. Aspose.Words renders the document as if English is the preferred language. Please see the attached PDF documents produced by MS Word with different language settings. ms_chinese.pdf (74.8 KB)
ms_en.pdf (74.7 KB)
I have logged this problem as WORDSNET-23276. We will keep you informed and let you know once it is resolved or we have more information for you.

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