I am getting an error when processing a PDF:
Method not found: ‘Void System.Drawing.Graphics.Clear(System.Drawing.Color)’.
My code (error when I add an image to html):
var tmpDoc = new Aspose.Pdf.Document(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(htmlText)), htmlLoadOptions);
The code does work on Windows.
We are deploying this .net 6 app onto a Linux machine which runs .net apps through Docker.
@Petr.Litvin
Please provide a more complete code snippet that you are using.
Because from .Net 6 System.Drawing.Common is not supported on non-Windows platform (on Linux in particular) - use the Aspose.Pdf.Drawing library (instead of Aspose.Pdf). This library uses Aspose.Drawing instead of System.Drawing.Common. Its main limitation is that api printing is not supported at the moment.
I’m checking for Aspose.pdf version 23.5
My code
public int LoadHtmlString(string htmlText, int orientation = 0, string filePath)
{
try
{
Aspose.Pdf.HtmlLoadOptions htmlLoadOptions = new Aspose.Pdf.HtmlLoadOptions (ResourcesDirectoryPath);
htmlLoadOptions.PageInfo.Margin.Bottom = 0;
htmlLoadOptions.PageInfo.Margin.Top = 0;
htmlLoadOptions.PageInfo.Margin.Left = 0;
htmlLoadOptions.PageInfo.Margin.Right = 0;
if (orientation == 1)
{
htmlLoadOptions.PageInfo.Height = 595;
htmlLoadOptions.PageInfo.Width = 842;
htmlLoadOptions.PageInfo.IsLandscape = true;
}
document = new Aspose.Pdf.Document(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(htmlText)), htmlLoadOptions);
document.Save(filePath);
return 1;
}
catch (Exception ex)
{
error = ex.Message;
error_stack_trace = ex.StackTrace;
return 0;
}
}
Error:
at System.Drawing.SafeNativeMethods.Gdip.GdipCreateRegion(IntPtr& region)
at System.Drawing.Region…ctor()
at #=zh2gh7BGs1_9elwbn0TGkyeXW5GgXK9inHw==.#=zA_$QpAA=(#=zDKIqL9wclfATDDT4Glps4wIkmPkRLZsFyg== #=zquKRdD0=)
at #=zUBunkDvVRFFoSIYEdn4alDOHmXeINjr1GyFneEQ=.Clone()
at #=zGdHZs0WmwWmut_2iJaNo_k7LW8PXoAERu2d1InA=.#=zNfW65OI=()
at #=zD$7WDHC4Rnm9X05V9xcUi4w0pFo0WsIiwCQRzUs=.#=zNfW65OI=()
at #=zzAjgeHcqlY5VlunKtSla6rMrlauj.#=z6HNhxgHP$7Ne()
at #=ziC1xS1m2bPxnyyAg1NRDCBR1yga0DlWZVsD2_IS1RVa_.#=z6HNhxgHP$7Ne()
at #=ziC1xS1m2bPxnyyAg1NRDCBR1yga0DlWZVsD2_IS1RVa_.#=zklgfLC5qvY6d()
at #=ziC1xS1m2bPxnyyAg1NRDCBR1yga0DlWZVsD2_IS1RVa_.#=zKGMd8D0=()
at #=zqJg20T2wNGfRaLq7M13GMmlF$pmw7u6IMYaiHnKcKGmw.#=zF8IeIS8=(#=zV4g6jrTtsXwNjsW2ycqsIWDxRlBT #=zse3_FA0=, #=zLlnBg5ePulKGl4$kf$7ZvEtYnATLZXiwsw== #=zRYBv7Rc=, #=zvmT2K6VohzhrfF$bu7blG5PIWC7p6RZMg8NYWijQnH3G #=zFtkiu8o=)
at Aspose.Pdf.Page.CalculateContentBBox()
at Aspose.Pdf.Page.#=zUKoOYm8=(Page #=zRYBv7Rc=)
at Aspose.Pdf.Document.ProcessParagraphs()
at Aspose.Pdf.Document.#=zbAOeeeYythXv(Stream #=zoCD3uWg=, SaveOptions #=z2dTTs$g4811l)
at Aspose.Pdf.Document.#=zvzBsOnnh675n(String #=zmvJG7_5iBqTP)
at Aspose.Pdf.Document.Save(String outputFileName)
at Websoft.Office.Pdf.Generator.Save(String filePath)
@Petr.Litvin
Because from .Net 6 System.Drawing.Common is not supported on non-Windows platform (on Linux in particular) - use the Aspose.Pdf.Drawing library (instead of Aspose.Pdf). This library uses Aspose.Drawing instead of System.Drawing.Common.
@Petr.Litvin
To reproduce the issue, I need the input htmlText
and preferably the dockerfile you are using.
@Petr.Litvin
Thanks for the provided data.
When running in a container for Linux, in the line that you indicated, an exception System.NullReferenceException occurs: “Object reference not set to an instance of an object.”
But the project got together and launched.
What version of the library are you using?
@Petr.Litvin
As I understand it, your project does not even start?
I’ll attach my project with the provided code snippet and file for you to try running it in your environment.
@Petr.Litvin
I attached a link to archive of my project.
Try running it in your environment.
This project is not running on docker.
The Aspose library uses System.Drawing.Common.dll (you have it in your project)
@Petr.Litvin
I apologize for my mistake - I missed that the code goes into the catch section. There is an error, it is not related to the lack of fonts and I will set a task to the development team.
@Petr.Litvin
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFNET-55492
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.