Aspose.Words 23.1.0 – Conversion Hangs(Timeout after 15 min) on wordDoc.Save(pdfStream, saveOptions)

Hi Team,

We are using Aspose.Words 23.1.0 and encountering an issue when converting a specific Word file to PDF.
The code execution gets stuck at the line wordDoc.Save(pdfStream, saveOptions); and does not proceed further.

Below is the relevant code snippet for reference:

private async Task<DocStoringDetails> ProcessForConvertWordToPDF(DocStoringDetails docDetails, ILambdaContext context)
{
    try
    {
        var logger = context.Logger;
        logger.LogInformation("Download word document started.");
        using var docStream = await DownloadFileAndSaveAsync(docDetails.DocumentKey, context);
        logger.LogInformation("Download word document completed.");

        var wordDoc = new Aspose.Words.Document(docStream);
        logger.LogInformation("Loaded Word document.");

        // Configure font settings
        var fontPath = Path.Combine("/tmp", "fonts");
        if (!Directory.Exists(fontPath))
            Directory.CreateDirectory(fontPath);

        var fontSettings = new FontSettings();
        fontSettings.SubstitutionSettings.DefaultFontSubstitution.DefaultFontName = "Times New Roman";
        fontSettings.SetFontsFolders(new[] { fontPath }, true);
        wordDoc.FontSettings = fontSettings;

        logger.LogInformation("Font settings configured.");

        // PDF save options
        var saveOptions = new PdfSaveOptions
        {
            OutlineOptions =
            {
                HeadingsOutlineLevels = 3,
                DefaultBookmarksOutlineLevel = 1
            },
            EmbedFullFonts = true,
            UseCoreFonts = false
        };

        await using var pdfStream = new MemoryStream();
        wordDoc.Save(pdfStream, saveOptions); // <-- Process hangs here
        pdfStream.Position = 0;

        var newFilePath = GetNewFilePath(docDetails);
        logger.LogInformation("Uploading converted PDF to S3...");
        await UploadFileAsync(pdfStream, context, docDetails.BucketName, newFilePath);
        logger.LogInformation("Upload completed: " + newFilePath);

        await DeleteFileFromS3Async(docDetails.BucketName, docDetails.DocumentKey);
        logger.LogInformation("Original Word file deleted from S3.");

        docDetails.DocumentKey = newFilePath;
    }
    catch (Exception ex)
    {
        context.Logger.LogError("Error during Word-to-PDF conversion: " + ex);
    }

    return docDetails;
}

We have verified that:

  • The Word document downloads correctly.
  • The issue only occurs for specific files.
  • No exception is thrown — the process simply hangs indefinitely at the Save() call.

The problematic Word file link is attached for your reference.
https://limewire.com/d/eRKp2#QH22Nm38s9
File Name-m1-01-xx.docx

Could you please help us identify the root cause or provide guidance on how to handle this scenario?

@ChetanPanchani

It seems you are experiencing a timeout issue when converting a specific Word document to PDF using Aspose.Words. Here are some steps to troubleshoot and potentially resolve the hanging issue during the Save() call:

  1. Check Document Complexity: The Word document may contain complex elements (such as large images, embedded objects, or extensive formatting) that could cause the conversion to hang. Try simplifying the document or removing complex elements to see if that resolves the issue.

  2. Increase Timeout: If possible, consider increasing the timeout settings for your operation. This can help if the document is simply taking longer to process.

  3. Use Different Save Options: You might want to try saving the document with different PDF save options. For example, set EmbedFullFonts to false to see if that helps with the conversion process.

  4. Check for Updates: Ensure you are using the latest version of Aspose.Words. If there are any updates beyond your current version, consider upgrading, as the issue may have been addressed in a newer release.

  5. Debugging: Add additional logging before and after the Save() call to determine if the process hangs at a specific point. This can help identify if the issue is related to a particular part of the document.

  6. Test with Other Documents: Try converting other Word documents to PDF to see if the issue is isolated to this specific file. This can help confirm if the problem is document-specific.

  7. Contact Support: If the issue persists, consider reaching out to Aspose support with the problematic document for further assistance. They may be able to provide insights specific to the document’s content.

Here’s a modified snippet to adjust the PDF save options:

var saveOptions = new PdfSaveOptions
{
    OutlineOptions =
    {
        HeadingsOutlineLevels = 3,
        DefaultBookmarksOutlineLevel = 1
    },
    EmbedFullFonts = false, // Try setting this to false
    UseCoreFonts = false
};

By following these steps, you should be able to identify the root cause or at least mitigate the issue. If you need further assistance, feel free to ask!

@ChetanPanchani The problem is not reproducible on my side using the latest 25.10 version of Aspose.Words and the following simple code:

Document doc = new Document(@"C:\Temp\in.docx");
doc.Save(@"C:\Temp\out.pdf");

Conversion takes about 6 minutes on my side.

Please try using the latest version and let us know if the problem still persists on your side.

Hi Alexey,
I’ve attached the URL for my entire file below. Could you please check how much time it takes with version 25.10 of Aspose.Words?

https://limewire.com/d/xFtS3#Y7qAxMxlH6
File Name- m1-01-xx - Copy.docx

Note: We are using Lamda Service of AWS for convert word file to PDF.

@ChetanPanchani It took about 29 minutes to convert the attached document. The produced PDF document size is 21MB and contains 7138 pages.

Hi Alexey, could you check same with 23.1.0 version of Aspose.Word as well.

And this same file able to convert with 23.1.0 version?

@ChetanPanchani Aspose.Words 23.1.0 is not able to convert the attached document to PDF on my side.

OK, Thank you Alexey for provide information and quick check.

1 Like