The save method hangs when saving Word file to PDF from version 21.6

Sample.zip (77.6 KB)
Aspose Team,
We use the Aspose Words java package to convert Microsoft Word files to PDF file and found out that the save method hangs with some document from version 21.6.
Following is the sample code that reproduces the problem and attached is the sample Word file.
The operating system is Ubuntu 18.04. Java version is 1.8. Aspose Words java package is 21.6.
Note that the problem does not exist in version 21.5. The problem also does not exist is the license is not loaded (comment out the line with setLicense();).

import com.aspose.words.ColorMode;
import com.aspose.words.FontSettings;
import com.aspose.words.Orientation;
import com.aspose.words.PaperSize;
import java.time.LocalDateTime;

public class WordToPdfHang {

    public static void main(String[] args) {
        try {
            setLicense();

            String wordFilePath = "sample_file_path/Sample.doc";
            String destFilePath = "sample_file_path/Sample.pdf";
            String orientation = "PORTRAIT";
            Boolean includeComments = true;

            System.out.println("Source file: " +  wordFilePath);
            System.out.println("Destination file: " +  destFilePath);

            // Set Aspose loading options for this Word file
            com.aspose.words.LoadOptions options = new com.aspose.words.LoadOptions();
            FontSettings fontSettings = new FontSettings();
            fontSettings.setFontsFolder("/usr/share/fonts/", true);
            options.setFontSettings(fontSettings);

            // Prepare the Word sections
            String currentOrientation = (orientation == null || orientation.isEmpty()) ? "DEFAULT" : orientation.toUpperCase().trim();
            com.aspose.words.Document document = new com.aspose.words.Document(wordFilePath, options);
            document.getLayoutOptions().setShowComments(includeComments);
            for (int i = 0; i < document.getSections().getCount(); i++) {
                if (currentOrientation.equals("LANDSCAPE") || currentOrientation.equals("PORTRAIT")) {
                    document.getSections().get(i).getPageSetup().setOrientation(currentOrientation.equals("LANDSCAPE") ? Orientation.LANDSCAPE : Orientation.PORTRAIT);
                }
                document.getSections().get(i).getPageSetup().setPaperSize(PaperSize.LETTER);
            }

            // Set save options
            com.aspose.words.PdfSaveOptions saveOptions = new com.aspose.words.PdfSaveOptions();
            saveOptions.setColorMode(ColorMode.NORMAL);
            saveOptions.setMemoryOptimization(true);

            // Save the Word file as a PDF
            System.out.println("Start time: " +  LocalDateTime.now());
            document.save(destFilePath, saveOptions);
            System.out.println("End time: " +  LocalDateTime.now());
        }
        catch(Exception ex) {
            ex.printStackTrace();
        }
    }

    private static void setLicense() {
        try {
            String asposeLicense = "license_file_path/Aspose.Total.Java.lic";
            new com.aspose.words.License().setLicense(asposeLicense);
            new com.aspose.pdf.License().setLicense(asposeLicense);
            System.out.println("License loaded successfully.");
        } catch (Exception e) {
            System.out.println("Failed to load the license: " + e.getMessage());
            System.exit(-1);
        }
    }
}

Tried with version 21.9 and the problem disappeared.

@xyang,

It is great that you were able to resolve the problem on your end when using the latest (21.9) version of Aspose.Words for Java. In case you have further inquiries or may need any help in future, please let us know by posting a new thread in Aspose.Words’ forum.