Saving converted word document into PDF takes forever

Hi Team,

We are encountering an issue while converting a .docx file to PDF using Aspose. Specifically, the process hangs indefinitely at the line:

wordDoc.save(os, SaveFormat.PDF);

Here is the relevant snippet for reference:

public void convertAndAppend(DesignatedContent dc, InputStream is, Document pdfDocument)
    throws Exception {

  dc.setPage(pdfDocument.getPages().size() + 1);

  OutputStream os = pipe.createOutputStream();

  try (os) {
    com.aspose.words.Document wordDoc = new com.aspose.words.Document(is);
    FontSettings defaultInstance = FontSettings.getDefaultInstance();
    defaultInstance.getFallbackSettings().loadMsOfficeFallbackSettings();
    wordDoc.setFontSettings(defaultInstance);
    wordDoc.save(os, SaveFormat.PDF); // Hangs here
  }
}

We’ve observed that the application never progresses past the save() call. To help with investigation, I’ve uploaded the Word document causing the issue.

Could you please assist us in identifying the root cause and suggest a resolution?

Thank you in advance for your support.
file_with_issue.docx (39.5 KB)

@Abdel_rahman_Abu_taleb

It sounds like you’re experiencing a frustrating issue with the conversion of a .docx file to PDF using Aspose. When the process hangs at the save() method, it can be due to several factors, including the complexity of the document, font settings, or specific content within the document.

Cause: The issue may arise from complex elements in the document, such as large images, embedded objects, or extensive formatting.

Solution: Here are some steps you can take to diagnose and potentially resolve the issue:

  1. Check Document Complexity: Simplify the document by removing complex elements to see if that resolves the issue.

  2. Font Settings: Ensure that the font settings are correctly configured. Temporarily remove custom font settings to test if the default settings work better.

  3. Use PdfSaveOptions: Utilize PdfSaveOptions to specify additional settings that might help with the conversion. For example, you can set the TextCompression or EmbedFullFonts properties.

    Here’s a sample code snippet to illustrate how to use PdfSaveOptions:

    PdfSaveOptions options = new PdfSaveOptions();
    options.setEmbedFullFonts(true); // or false, depending on your needs
    options.setTextCompression(PdfTextCompression.FLATE); // Adjust as needed
    
    wordDoc.save(os, options);
    
  4. Memory Optimization: If the document is large, enable memory optimization by setting the MemoryOptimization property in PdfSaveOptions.

  5. Progress Callback: Implement a progress callback to monitor the saving process, which can help identify if the process is stuck at a specific point.

  6. Test with a Different Document: Convert a simpler document to see if the issue persists. This can help determine if the problem is with the specific document or the conversion process itself.

Next Steps: If these steps do not resolve the issue, please provide more details about the document’s content or any specific error messages you might be encountering.

Let me know if this helps!

@Abdel_rahman_Abu_taleb The problem is not reproducible on my side using the latest 25.7 version of Aspose.Words for Java. Please try using the latest version and let us know if the problem still persists on your side.

1 Like

Thank you @alexey.noskov!
Another question please, is there a way to time-out the conversion?

@Abdel_rahman_Abu_taleb In Aspose.Words you can use IDocumentLoadingCallback to interrupt document loading process. Also, you can use IDocumentSavingCallback to cancel save operation.
Upon saving document to PDF or any other fixed page formats, however, the most time is taken by document layout process than by saving operation. You can interrupt the layout process using IPageLayoutCallback.