The error you’re encountering indicates that System.Drawing.Common is not supported on non-Windows platforms, which is a common issue when running applications in Linux environments, such as Azure.
To resolve this, consider the following options:
Use a Different Rendering Engine: Instead of relying on System.Drawing, utilize a rendering engine that is compatible with Linux. Aspose.PDF for .NET does not require System.Drawing for HTML to PDF conversion, so ensure you are using the latest version of Aspose.PDF.
Check Your Code: Review your code to ensure it does not explicitly use any System.Drawing classes or methods. If it does, you will need to refactor it to eliminate those dependencies.
Use Docker: If you are deploying in Azure, consider using a Docker container based on a Windows image if your application heavily relies on System.Drawing. This allows you to run your application in a Windows environment while still utilizing Azure services.
Explore Alternative Libraries: If the issue persists, consider exploring other libraries or services that can handle HTML to PDF conversion without relying on System.Drawing.
For further guidance on converting documents in Azure using Aspose.PDF, please consult the official documentation.
namespace ConversionLibrary.Converters
{
internal class ConvertHtmlDocument : IConvertDocument
{
public async Task Convert(Stream inputStream, Stream outputStream, ILogger logger, string fileName)
{
try
{
//using var streamProvider = new OutputStreamProvider(outputStream);
using var streamProvider = new MemoryStreamProvider();
var htmlDoc = new HTMLDocument(inputStream, “.” );
var x = new Aspose.Html.Saving.PdfSaveOptions();
x.DocumentInfo.CreationDate = DateTime.UtcNow;
x.DocumentInfo.Producer = "CMG Document Converter";
x.DocumentInfo.Title = fileName;
x.DocumentInfo.Author = "";
x.DocumentInfo.Subject = "";
Aspose.Html.Converters.Converter.ConvertHTML(htmlDoc, x, streamProvider);
var memory = streamProvider.Streams.First();
memory.Seek(0, SeekOrigin.Begin);
await memory.CopyToAsync(outputStream);
await outputStream.FlushAsync();
return null;
}
catch( Exception ex )
{
logger.LogError(ex, "Exception During HTML Document Conversion");
return "Exception";
}
}
}
Please note that we have published Aspose.PDF.Drawing for .NET and Aspose.HTML.Drawing for .NET APIs separately to work in non-Windows environments. We request you please uninstall existing packages and install above mentioned packages from NuGet Package Manager. In case you still notice any errors while using these packages, please let us know.
It is nice to know that things have started working at your end. Please keep using the API and feel free to create a new topic in case you need any kind of assistance.