Aspose.words PDF creation using html is blocking the images on Azure File share

Issue Description

We are using Aspose.Words for .NET version 25.x to generate PDF files from HTML content. The HTML content includes image paths that point to files located on an Azure File Share.

However, we are experiencing an issue where:

The image files on the Azure File Share are being locked by the Aspose.Words PDF creation process.

This prevents other processes or services from accessing or modifying these image files until the PDF creation process completes — or sometimes even after that.

Questions

  1. Does Aspose.Words lock image files when rendering HTML to PDF?
  2. If so, is there a way to avoid or release these locks immediately after the PDF is generated?
  3. Is it recommended to stream the images (rather than referencing them by path) to avoid file locks?

Technical Details

  • Aspose.Words Version: 25.x
  • Input Format: HTML string with <img src="path-to-azure-fileshare/image.jpg">
  • Output Format: PDF

@Vaibhav.Nalawade

  1. Does Aspose.Words lock image files when rendering HTML to PDF?
    Yes, Aspose.Words may lock image files during the PDF generation process. This can prevent other processes from accessing or modifying these files until the PDF creation is complete.

  2. Is there a way to avoid or release these locks immediately after the PDF is generated?
    Unfortunately, there is no direct way to release these locks immediately after the PDF generation. The locks are typically released once the Aspose.Words process completes.

  3. Is it recommended to stream the images (rather than referencing them by path) to avoid file locks?
    Yes, streaming images instead of referencing them by file path can help avoid file locks. You can load images into memory and pass them directly to the HTML content, which may prevent the locking issue.

Here’s a minimal example of how you might stream images:

using Aspose.Words;
using Aspose.Words.Saving;
using System.IO;

// Load HTML content
string htmlContent = "<html><body><img src='data:image/jpeg;base64,{base64ImageData}' /></body></html>";

// Create a Document from HTML
Document doc = new Document(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(htmlContent)));

// Save as PDF
doc.Save("output.pdf", SaveFormat.Pdf);

In this example, replace {base64ImageData} with the actual base64 string of your image. This approach helps you avoid file locks associated with file paths.

@Vaibhav.Nalawade No, Aspose.Words does not lock images when rendering HTML to PDF. Images are downloaded automatically by Aspose.Words, but the images must be accessible.

You can use IResourceLoadingCallback to control how resources are loaded or implement your own method to download external resources.