Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Sep 20, 2024 9:45 am

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!

msigvnit
 
Posts: 3
Joined: Fri Jul 22, 2022 6:05 am

Mon Sep 23, 2024 8:10 am

Hello,

Thanks for your inquiry. From .NET 6, System.Drawing.Common.dll is no longer supported on non-Windows systems. Please install our Spire.PDFfor.NETStandard instead which is dependent on "SkiaSharp". Also please install the "SkiaSharp.NativeAssets.Linux.NoDependencies" for testing. If you have any further questions, please feel free to provide feedback.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 283
Joined: Mon Jul 15, 2024 5:40 am

Mon Sep 23, 2024 8:57 am

Thank you for your advice. We will test and feedback to you!

msigvnit
 
Posts: 3
Joined: Fri Jul 22, 2022 6:05 am

Fri Sep 27, 2024 9:17 am

Hi E-IceBlue support,

We used your suggested package and now our application can run normally. It was the correct answer to our issue. Thank you!

msigvnit
 
Posts: 3
Joined: Fri Jul 22, 2022 6:05 am

Fri Sep 27, 2024 9:30 am

Hello,

Thanks for your feedback. I'm glad to hear this news. If you have any other questions, please feel free to write to me.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 283
Joined: Mon Jul 15, 2024 5:40 am

Return to Spire.PDF

cron