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?