Hi Team,
I’m trying to generate a PDF by passing an HTML stream to constructor. But it seems that it fails to do so. It works fine on local but fails on server(Linux).
Following other threads which asks to get rid off Systems.Drawing.Common
I already installed follwing:
- Aspose.PDF.Drawing
- SkiaSharp
- SkiaSharp.NativeAssets.Linux
Code which causing the issue:
public static void ConvertHtmlDocToPDFDoc(byte[] doc, out Document pdfDocument)
{
//TODO: Added it to check build issue
RegisterFonts();
using var htmlStream = new MemoryStream(doc);
var loadOptions = PDFDocumentHelper.GetHtmlLoadOptions();
pdfDocument = new Document(htmlStream, loadOptions);
}
public static void RegisterFonts()
{
var fontPath = System.IO.Path.Combine(AppContext.BaseDirectory, "Resources", "Fonts");
if (Directory.Exists(fontPath))
{
FontRepository.Sources.Add(new FolderFontSource(fontPath));
}
else
{
throw new DirectoryNotFoundException($"Font folder not found: {fontPath}");
}
}
public static HtmlLoadOptions GetHtmlLoadOptions()
{
return new HtmlLoadOptions
{
InputEncoding = "UTF-8",
PageInfo =
{
Margin = new MarginInfo(45,45,45,45),
Width = PageSize.A4.Width,
Height = PageSize.A4.Height,
},
IsEmbedFonts = true
};
}
Error message is:
System.TypeInitializationException:
at System.Drawing.SafeNativeMethods+Gdip.GdipCreateMatrix2 (System.Drawing.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51)
at System.Drawing.Drawing2D.Matrix…ctor (System.Drawing.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51)
at #=zkPxZAbpo_XojO$zB1bq57VA=…ctor (Aspose.PDF, Version=25.8.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56)
at #=zPqRjsWokP$$ZAZmvsF33Gi6LBp2Jruui9g==.#=z6$ONzYzl9FqDdsXna3CQWpI= (Aspose.PDF, Version=25.8.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56)
at #=zPqRjsWokP$$ZAZmvsF33Gi6LBp2Jruui9g==.#=zjdaNgqo= (Aspose.PDF, Version=25.8.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56)
at #=z5$Srdeyr06Qc95XCXHeahHpwXBJjsXQrUCKNha8=.Render (Aspose.PDF, Version=25.8.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56)
at #=zNP9TNAY4vUJQDQx3ivlFeK_yRwsh.#=z6wvWxUb107bB (Aspose.PDF, Version=25.8.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56)
at #=zTwZXpP282jvPo2MGCxGnKhbZTabI.Render (Aspose.PDF, Version=25.8.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56)
at #=zTwZXpP282jvPo2MGCxGnKhbZTabI.Render (Aspose.PDF, Version=25.8.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56)
at #=zPAH6K6IYjBtuIwxLsoxYgc$lUnG2.Render (Aspose.PDF, Version=25.8.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56)
at #=zPAH6K6IYjBtuIwxLsoxYgc$lUnG2.Render (Aspose.PDF, Version=25.8.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56)
at #=zuu4MA6QdJMlYCxyZJDKSb2vdH2WZ.#=z0vF5BzEBoo5i (Aspose.PDF, Version=25.8.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56)
at #=zuu4MA6QdJMlYCxyZJDKSb2vdH2WZ.#=z$OFy7Ag= (Aspose.PDF, Version=25.8.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56)
at #=zuu4MA6QdJMlYCxyZJDKSb2vdH2WZ.#=z$OFy7Ag= (Aspose.PDF, Version=25.8.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56)
at Aspose.Pdf.Document.#=zUO6kUDs= (Aspose.PDF, Version=25.8.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56)
at Aspose.Pdf.Document.#=zUO6kUDs= (Aspose.PDF, Version=25.8.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56)
at Aspose.Pdf.Document…ctor (Aspose.PDF, Version=25.8.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56)
at Deloitte.APT.Infrastructure.Common.PDFHelpers.PDFDocumentHelper.ConvertHtmlDocToPDFDoc (Deloitte.APT.Infrastructure.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: