Hello Aspose Team,
I have encountered an issue where Aspose.Words wraps text / inserts line breaks differently than Microsoft Word when converting a DOCX document to PDF.
Could you please investigate this layout calculation issue and let me know if there is a workaround or if this is a bug in the layout engine?
TestAspose.zip (610.0 KB)
@InfoPlus There is no bug here. Your document uses Aptos, which is cloud font, so it is not installed by default and is downloaded by MS Word on demand. Aspose.Words does not download cloud fonts.
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/
You can download Aptos fonts from here .
PS: After providing Aptos the document is rendered properly: out.pdf (120.4 KB)
1 Like
I have edited the document to avoid font substitution. I also implemented IWarningCallback to verify that no substitution occurs, but the line wrapping issue still remains. I have verified that it is not related to font substitution. However, your response includes a link to a PDF where the line wraps are handled correctly, and I am wondering how you generated this PDF. Could additional settings be required?
in.docx (14.3 KB)
@InfoPlus The problem occurs because kerning is enabled for text in the table in your document, and code changes are required on your side in order to get the correct 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("in.docx");
// Configure shaping in order to support font kerning.
doc.LayoutOptions.TextShaperFactory = Aspose.Words.Shaping.HarfBuzz.HarfBuzzTextShaperFactory.Instance;
doc.Save("out_HarfBuzz.pdf");
See more about advanced typograph features in the documentation: https://docs.aspose.com/words/net/enable-opentype-features/
Here is the output document produced on my side using the latest 26.9 version of Aspose.Words and the above code:
out_HarfBuzz.pdf (35.5 KB)
1 Like