Hi.
We have very simple Word document, which we would like to save as PDF using Aspose.Words latest version 25.3.0.
Unfortunately this operation corrupts document markup (Tabs are lost). Please see attached source document.
TestTabPlacement.docx (13.3 KB)
The code :
Dim AsposeDocument As New Aspose.Words.Document("TestTabPlacement.docx")
AsposeDocument.FieldOptions.FieldUpdateCultureSource = Aspose.Words.Fields.FieldUpdateCultureSource.FieldCode
AsposeDocument.Save("converted.pdf", Aspose.Words.SaveFormat.Pdf)
Can it be fixed by parameters? Or is it a bug ?
Thank you.
@sergii.chyzh
It seems that you are experiencing issues with tab markup being lost when converting a Word document to PDF using Aspose.Words version 25.3.0. This can sometimes occur due to the way the document is rendered during the conversion process.
To address this issue, you can try using the PdfSaveOptions
class to specify additional settings that may help preserve the formatting, including tab stops. Here’s an example of how you can implement this:
Dim AsposeDocument As New Aspose.Words.Document("TestTabPlacement.docx")
' Create PdfSaveOptions and set properties
Dim saveOptions As New Aspose.Words.Saving.PdfSaveOptions()
saveOptions.ExportDocumentStructure = True ' This may help in preserving the document structure
' Save the document as PDF with the specified options
AsposeDocument.Save("converted.pdf", saveOptions)
In this code, the ExportDocumentStructure
property is set to True
, which can help maintain the structure of the document during conversion. You might also want to explore other properties of PdfSaveOptions
that could affect the output, such as EmbedFullFonts
or UseHighQualityRendering
, depending on your specific needs.
If the issue persists, it may be worth checking if this is a known bug in the version you are using. You can also consider reaching out to Aspose support for further assistance or checking their documentation for any updates or patches that might address this issue.
For more detailed information on the PdfSaveOptions
class and its properties, you can refer to the official documentation here.
If you have any further questions or need additional help, feel free to ask!
@sergii.chyzh The problem is not repressible on my side.
out.pdf (10.3 KB)
Usually, the such problems occur because the fonts used in your input document are not available on the machine where document is converted to PDF. 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/
Hi @alexey.noskov ,
Missing fonts could be the reason, but the document is converted on the same machine, also I have tried with other standard fonts (ex. Arial). Anyway, thank you, I will try implementing IWarningCallback to see what is going on.
@sergii.chyzh In your document Aptos
font is used. This is a cloud font and MS Word downloads it on demand. You can download it from here:
https://www.microsoft.com/en-us/download/details.aspx?id=106087
You are right. I have downloaded Aptos font and it worked. However, before it I have tried with Arial font, which is present in Windows - didn’t work. With “Times New Roman” is worked.
So, the way is to use installed font.
@sergii.chyzh Could you please attach the document with Arial font where layout is incorrect after rendering? We will check the issue on our side.
Hi @alexey.noskov ,
The document with Arial font:
TestTabPlacement.docx (13.4 KB)
Thank you.
@sergii.chyzh Thank you for additional information. The problem occurs because by default MS Word uses font 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:
Hyphenation.RegisterDictionary("de-CH", @"C:\Temp\hyph_de_CH.dic");
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 (20.1 KB)
@alexey.noskov , thank you !
Will try it.
1 Like