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?
@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.
@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)
@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:
@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 ?
@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:
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'");
@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.
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));
@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.