Dear E-iceblue support team,
I am using Spire.PDF in .Net 8 to develop service to processing PDF: set password for PDF, add digital signature ...
The program works on a Windows machine, but when I publish it to a Debian Linux server, the application crashes with error:
fail: SkiaSharpTester.Controllers.SkiaSharpController[0]
CreatePdfWithSkiaSharp error: System.TypeInitializationException: The type initializer for 'Gdip' threw an exception.
---> System.PlatformNotSupportedException: System.Drawing.Common is not supported on non-Windows platforms. See hxxps[:]//aka[.]ms/systemdrawingnonwindows for more information.
at System.Drawing.LibraryResolver.EnsureRegistered()
at System.Drawing.SafeNativeMethods.Gdip.PlatformInitialize()
at System.Drawing.SafeNativeMethods.Gdip..cctor()
--- End of inner exception stack trace ---
at System.Drawing.SafeNativeMethods.Gdip.GdipCreateMatrix(IntPtr& matrix)
at System.Drawing.Drawing2D.Matrix..ctor()
at spr哹..ctor()
at Spire.Pdf.Graphics.PdfCanvas.TranslateTransform(Single offsetX, Single offsetY)
at Spire.Pdf.PdfPageBase.쐫(Boolean A_0, Boolean A_1, PdfCanvas& A_2)
at Spire.Pdf.PdfPageBase.get_Canvas()
I think it's because "System.Drawing" is not supported on Linux, but how can I deploy spire.PDF to work correctly on linux?
There are code for functions i am using as below:
public async Task<IActionResult> SignPdf()
{
await Task.Delay(0);
try
{
string pdfPath = Path.Combine(Path.GetTempPath(), "sample.pdf");
string signaturePath = Path.Combine(Path.GetTempPath(), "Certificate/signature.png");
string outputFolder = Path.Combine(Path.GetTempPath(), "output");
string certificatePath = Path.Combine(Path.GetTempPath(), "Certificate/filename_cert.pfx");
if (!Directory.Exists(outputFolder))
{
Directory.CreateDirectory(outputFolder);
}
_logger.LogInformation($"pdfPath: {pdfPath}");
_logger.LogInformation($"signaturePath: {signaturePath}");
_logger.LogInformation($"outputFolder: {outputFolder}");
_logger.LogInformation($"certificatePath: {certificatePath}");
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile(pdfPath);
PdfPageBase page = pdf.Pages[0];
PdfImage image = PdfImage.FromFile(signaturePath);
page.Canvas.DrawImage(image, 350, 600);
//Load the certificate
PdfCertificate cert = new PdfCertificate(certificatePath, "Password");
//Create a PdfSignature object
PdfSignature signature = new PdfSignature(pdf, page, cert, "signature");
//Set the document permission to forbid changes but allow form fill
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges | PdfCertificationFlags.AllowFormFill;
//save pdf to PDF file in the output folder
pdf.SaveToFile(Path.Combine(outputFolder, "output.pdf"));
return Ok(new { Status = 0, Message = "PDF signed successfully" });
}
catch (Exception ex)
{
_logger.LogError($"SignPdf error: {ex.ToString()}");
return Ok(new { Status = -1, Message = ex.Message });
}
}
I can't find the reason to fix. Your comments and advice are highly appreciated!
Thanks!