Hello,
We are evaluating the application migration to Linux and are facing issue with the HTML to PDF functionality not working there.
To be more explicit, we are running code like below in Azure App Service for Linux:
private Stream GenerateBodyStream(string html, string title)
{
var stream = new MemoryStream();
using (var streamProvider = new StreamProvider())
{
using (var document = new HTMLDocument(html, "."))
{
var options = new PdfSaveOptions();
options.PageSetup.AnyPage = new Page(
new Size(612, 792),
new Margin(0, 100, 0, 85));
options.DocumentInfo.Title = title;
Converter.ConvertHTML(document, options, streamProvider);
var memory = streamProvider.Streams.First();
memory.Seek(0, SeekOrigin.Begin);
memory.CopyTo(stream);
}
}
stream.Seek(0, SeekOrigin.Begin);
return stream;
}
And get the exception:
System.TypeInitializationException: The type initializer for 'Gdip' threw an exception.
---> System.PlatformNotSupportedException: System.Drawing.Common is not supported on non-Windows platforms. See https://aka.ms/systemdrawingnonwindows for more information.
at System.Drawing.SafeNativeMethods.Gdip.<>c.<.cctor>b__2_0(String _, Assembly _, Nullable`1 _)
at System.Runtime.InteropServices.NativeLibrary.LoadLibraryCallbackStub(String libraryName, Assembly assembly, Boolean hasDllImportSearchPathFlags, UInt32 dllImportSearchPathFlags)
at System.Drawing.SafeNativeMethods.Gdip.<GdiplusStartup>g____PInvoke|32_0(IntPtr* __token_native, StartupInputEx* __input_native, StartupOutput* __output_native)
at System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& token, StartupInputEx& input, StartupOutput& output)
at System.Drawing.SafeNativeMethods.Gdip..cctor()
--- End of inner exception stack trace ---
at System.Drawing.SafeNativeMethods.Gdip.GdipCreateMatrix2(Single m11, Single m12, Single m21, Single m22, Single dx, Single dy, IntPtr& matrix)
at System.Drawing.Drawing2D.Matrix..ctor(Single m11, Single m12, Single m21, Single m22, Single dx, Single dy)
at ..ctor(Single , Single , Single , Single , Single , Single )
at .CreateMatrix(Single , Single , Single , Single , Single , Single )
at .BeginPage(SizeF )
at Aspose.Html.Rendering.Device`2.BeginPage(SizeF size)
at . (IDevice , CancellationToken )
at . (Renderer , [] , IDevice , CancellationToken )
at Aspose.Html.Rendering.HtmlRenderer.(IDevice , CancellationToken , Element[] , Document[] )
at Aspose.Html.Rendering.HtmlRenderer.Render(IDevice device, TimeSpan timeout, HTMLDocument[] sources)
at Aspose.Html.Rendering.Renderer`1.Render(IDevice device, TSource source, TimeSpan timeout)
at Aspose.Html.Rendering.Renderer`1.Render(IDevice device, TSource source)
at .( , IDevice )
at . ( , PdfSaveOptions , ICreateStreamProvider )
at Aspose.Html.Converters.Converter.ConvertHTML(HTMLDocument document, PdfSaveOptions options, ICreateStreamProvider provider)
at WebApplication_forLinux.Controllers.TestController.GenerateBodyStream(String html, String title) in C:\src\WebApplication_forLinux\Controllers\TestController.cs:line 87
at WebApplication_forLinux.Controllers.TestController.GetPdf() in C:\src\WebApplication_forLinux\Controllers\TestController.cs:line 46
Full sample solution attached below. Can you please assist?
aspose_linux.zip (3.3 КБ)