After convert to pdf, the tablelayout are different with word

pdf:

word:

@softboy

It sounds like you’re experiencing layout differences between your Word document and the converted PDF, particularly with tables. This issue can arise due to various factors, such as how Word and the PDF rendering engine handle table properties, margins, or styles.

Cause: The discrepancies in layout are often due to differences in table properties and settings between Word and the PDF format.

Solution: Here are some steps you can take to troubleshoot and resolve the issue:

  1. Check Table Properties: Ensure that the table properties in your Word document are set correctly. Pay attention to settings like cell padding, spacing, and alignment.

  2. Use Fixed Widths: If your table columns are set to auto-size, try setting fixed widths for the columns. This can help maintain consistency in the layout when converting to PDF.

  3. Update Aspose.Words: Make sure you are using the latest version of Aspose.Words, as updates often include improvements and bug fixes related to document conversion.

  4. Adjust PDF Options: When converting to PDF, specify options that might help maintain the layout. For example, you can set the PdfSaveOptions to control how tables are rendered.

Here’s a simple code snippet to set fixed column widths and save the document as a PDF:

Document doc = new Document("input.docx");
Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
foreach (Row row in table.Rows)
{
    foreach (Cell cell in row.Cells)
    {
        cell.CellFormat.Width = 100; // Set a fixed width for each cell
    }
}
doc.Save("output.pdf", SaveFormat.Pdf);
  1. Review PDF Output: After making adjustments, review the PDF output to see if the layout has improved. You may need to iterate on the settings to achieve the desired result.

Next Steps: If the issue persists, please share more details about the specific table properties or any styles applied. This information will help in diagnosing the problem further.

Let me know if this resolves your issue!

no, we cannot adjust the column width, which is configued by others

@softboy Could you please attach your problematic input and output documents here for testing? We will check the issue and provide you more information. Unfortunately, it is impossible to analyze the problem using screenshots.

BCCY2025019602乳果糖口服溶液与药包材相容性研究技术报告20250724修订(增加元素验证).docx (7.5 MB)

@softboy The fronts '中文宋体' and '华文新魏' used in your document are not available on my side. Could you please attach these fonts here?

The fonts are required to build document layout. If Aspose.Words cannot find the font used in the document, the font is substituted . This might lead into fonts mismatch and document layout differences due to the different fonts metrics. You can implement IWarningCallback to get notifications when font substitution is performed.
Please see our documentation to learn where Aspose.Words looks for fonts:
https://docs.aspose.com/words/net/specifying-truetype-fonts-location/

Downloads.7z (8.9 MB)

@softboy Thank you for additional information. To get the output closer to MS Word it is required to enable open type features. Aspose.Words.Shaping.Harfbuzz package provides support for OpenType features in Aspose.Words using the HarfBuzz text shaping engine. You should enabling open type features to get the expected result. To achieve this you should add reference to Aspose.Words Shaping Harfbuzz plugin and use the following code to convert your document:

Document doc = new Document(@"C:\Temp\in.docx");
doc.LayoutOptions.TextShaperFactory = Aspose.Words.Shaping.HarfBuzz.HarfBuzzTextShaperFactory.Instance;
doc.Save(@"C:\Temp\out_HarfBuzz.pdf");

out_HarfBuzz.pdf (6.4 MB)

Hi,
I tried, but still failed. From which version, Enable OpenType Features

Another problem from your out_HafBuzz.pdf, on page 107, there is formatting problem:

out_HafBuzz.pdf:

ms word:

@softboy In MS Word I see the same result as Aspose.Words’ result on my side. Could you please convert your document to PDF using Save As in MS Word and attach the resulting document here for our reference?

in which version of aspose.words?I tried your code, but doesn’t work:

@softboy I used the latest 25.8 version of Aspose.Words for .NET in my tests.

Hi,
i see the similiar ticket at 用aspose-word24.6版本,word转pdf后,pdf页码数量会多一页,导致页码数不一致 - #6 by vyacheslav.deryushev,
which hasn’t been fixed. Is it the same issue?

@softboy The issue reported in the mentioned thread is not resolved yet. It has been postponed and is not yet scheduled for development.

before, we use 24.12, when i use 25.8, the converted format still different with word. see below:
pdf:


word:

the following is my code:

        LoadOptions loadOptions = new LoadOptions();
        loadOptions.getLanguagePreferences().setDefaultEditingLanguage(EditingLanguage.CHINESE_PRC);
        Document doc = new Document(byteArrayInputStream,loadOptions);
        doc.getLayoutOptions().setTextShaperFactory(HarfBuzzTextShaperFactory.getInstance());
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        PdfSaveOptions options = new PdfSaveOptions();
        options.setSaveFormat(SaveFormat.PDF);
        options.getOutlineOptions().setHeadingsOutlineLevels(3);
        options.getOutlineOptions().setExpandedOutlineLevels(1);
        doc.save(byteArrayOutputStream,options);

pc environment: windows 11

@softboy Could you please attach your actual PDF output produced with the above code? We will check it and provide you more information.

aspose.pdf (7.2 MB)

attatched

@softboy As I can see fonts used in your PDF document differs from fonts used in PDF produced on my side. Please try implementing IWarningCallback as suggested above to check whether font substitution is performed on your side.

On my side side I see the following warning upon rendering your document:

Layout: FontSubstitution: Font '中文宋体' has not been found. Using 'SimSun' font instead. Reason: alternative name from document.

In chinese version of windows,‘中文宋体’ is embeded, it equals ‘SimSun’, the two are the single one