Word to TIFF Conversion

Hi All,

We are seeing an issue when converting Word document to TIFF where the conversion is not happening as-is and we see content is not aligned correctly in page.

We are using the below code snippet:

LoadOptions loadOptions = new LoadOptions();
loadOptions.setLoadFormat(LoadFormat.AUTO);
wordDocument = new Document(inputStream, loadOptions);
for (Field field : wordDocument.getRange().getFields())
{
    field.isLocked(true);
}
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.TIFF);
options.setTiffCompression(TiffCompression.CCITT_4);
options.setResolution(300);
wordDocument.save(targetStream, options);

@hemassridhar Could you please attach your input and output documents here for testing? We will check the issue and provide you more information.

The problem with document layout might occur because the fonts used the documents are not available in the environment where documents are converted to TIFF. To build an accurate document layout the fonts are required. If Aspose.Words cannot find the fonts used in the document the fonts are substituted. This might lead into the layout differences due to differences in fonts metrics. You can implement IWarningCallback to get a notification when font substitution is performed.
The following articles can be useful for you:
https://docs.aspose.com/words/java/specify-truetype-fonts-location/
https://docs.aspose.com/words/java/install-truetype-fonts-on-linux/

Hi @alexey.noskov , I have just implemented [IWarningCallback], but we are running this document in Windows machine as part of troubleshooting, it should ideally be referring to C:\Windows\Fonts folder, correct?

Unfortunately we will not be able to share document.

@alexey.noskov, found the issue as:

Font ‘Frutiger LT 55 Roman’ has not been found. Using ‘GillSans’ font instead. Reason: alternative name from document.

On the same note, is there way we build an utility to to fetch all the fonts that are in use for list of documents?

@hemassridhar Yes, by default Aspose.Words uses the fonts installed in the system.

Unfortunately, without the problematic document is it impossible to say what causes the problem on your side.

@alexey.noskov, can you take a look this please?

@hemassridhar If documents have been created using MS Word you can rely on the document font table. You can use DocumentBase.FontInfos property in this case.

But the most precise way to determine what fonts are required for document rendering is using using IWarningCallback and specifying no font sources. In this case all fonts will be substituted with the Fanwood font, which is the last resort font used by Aspose.Words. This font is embedded into Aspose.Words DLL.

Document doc = new Document(@"C:\Temp\in.docx");
doc.FontSettings = new FontSettings();
doc.FontSettings.SetFontsSources(new FontSourceBase[] { });
doc.WarningCallback = new WarningCallback();
doc.UpdatePageLayout();
private class WarningCallback : IWarningCallback
{
    public void Warning(WarningInfo info)
    {
        if (info.WarningType == WarningType.FontSubstitution)
            Console.WriteLine(info.Description);
    }
}

@alexey.noskov, quickly built an utility to fetch all the fonts and see mainly below two types of warnings:

Font ‘Helv’ has not been found. Using ‘Helvetica’ font instead. Reason: alternative name from document. - > Should I be worrying here too? Seems like just a different naming, not really sure though
Font ‘Frutiger LT 55 Roman’ has not been found. Using ‘GillSans’ font instead. Reason: alternative name from document. I understand actual font to be placed in fonts folder path
Font ‘TimesNewRomanPS’ has not been found. Using ‘Times New Roman’ font instead. Reason: font info substitution. - I am assuming even here I need to place this specific font.

Can you share the difference between Substitution & alternate name from document warning.

Also we are running this app in Linux environment and copied all the Windows fonts to a specific path and configured that path in Aspose at app startup.

@hemassridhar Aspose.Words applies several substitution rules:
https://docs.aspose.com/words/net/manipulating-and-substitution-truetype-fonts/#font-availability-and-substitution

alternative name from document.
In fonts table in the document, an alternative font might be specified. If so, Aspose.Words uses this alternative font if the specified font is not available.

font info substitution.

The substitution is determined by the information from FontInfo stored in the document. Aspose.Words takes in account font panose, unicode ranges, codepages, pitch, charset and weight of the font to select a suitable substitution.