|
@@ -5,7 +5,13 @@ using ComPDFKit.PDFDocument;
|
|
|
using ComPDFKit.PDFPage;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Diagnostics;
|
|
|
+using System.Drawing;
|
|
|
using System.IO;
|
|
|
+using System.Runtime.InteropServices;
|
|
|
+using System.Security.AccessControl;
|
|
|
+using System.Xml.Linq;
|
|
|
+using ImageMagick;
|
|
|
|
|
|
namespace DigitalSignatureTest
|
|
|
{
|
|
@@ -34,6 +40,29 @@ namespace DigitalSignatureTest
|
|
|
Directory.CreateDirectory(trustedFolder);
|
|
|
}
|
|
|
CPDFSignature.SignCertTrustedFolder = trustedFolder;
|
|
|
+
|
|
|
+
|
|
|
+ // Get the access control of the directory
|
|
|
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
+ {
|
|
|
+ DirectoryInfo directoryInfo = new DirectoryInfo(outputPath);
|
|
|
+ DirectorySecurity directorySecurity = directoryInfo.GetAccessControl();
|
|
|
+ directorySecurity.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow));
|
|
|
+ directoryInfo.SetAccessControl(directorySecurity);
|
|
|
+ }
|
|
|
+ else if(RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
|
+ {
|
|
|
+ // Set the access control of the directory
|
|
|
+ string[] args = { "chmod", "-R", "777", outputPath };
|
|
|
+ Process process = new Process();
|
|
|
+ process.StartInfo.FileName = "/bin/chmod";
|
|
|
+ process.StartInfo.Arguments = string.Join(" ", args);
|
|
|
+ process.StartInfo.UseShellExecute = false;
|
|
|
+ process.StartInfo.RedirectStandardOutput = true;
|
|
|
+ process.Start();
|
|
|
+ process.WaitForExit();
|
|
|
+ }
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
#region Sample 0: Create certificate
|
|
@@ -100,7 +129,7 @@ namespace DigitalSignatureTest
|
|
|
|
|
|
string info = "/C=SG/O=ComPDFKit/D=R&D Department/CN=Alan/emailAddress=xxxx@example.com";
|
|
|
string password = "ComPDFKit";
|
|
|
- string filePath = outputPath + "\\Certificate.pfx";
|
|
|
+ string filePath = "Certificate.pfx";
|
|
|
if (CPDFPKCS12CertHelper.GeneratePKCS12Cert(info, password, filePath, CPDFCertUsage.CPDFCertUsageAll, true))
|
|
|
{
|
|
|
Console.WriteLine("File saved in " + filePath);
|
|
@@ -168,11 +197,16 @@ namespace DigitalSignatureTest
|
|
|
"DN: " + DN + "\n",
|
|
|
IsContentAlignLeft = false,
|
|
|
IsDrawLogo = true,
|
|
|
- // Note: No logo bitmap
|
|
|
- //LogoBitmap = new Bitmap("Logo.png"),
|
|
|
TextColor = new float[] { 0, 0, 0 },
|
|
|
ContentColor = new float[] { 0, 0, 0 }
|
|
|
};
|
|
|
+ using (var image = new MagickImage("Logo.png"))
|
|
|
+ {
|
|
|
+ byte[] byteArray = image.ToByteArray(MagickFormat.Bgra);
|
|
|
+ signatureConfig.LogoData = byteArray;
|
|
|
+ signatureConfig.LogoHeight = image.Height;
|
|
|
+ signatureConfig.LogoWidth = image.Width;
|
|
|
+ }
|
|
|
string filePath = outputPath + "\\" + document.FileName + "_Signed.pdf";
|
|
|
signatureField.UpdataApWithSignature(signatureConfig);
|
|
|
if (document.WriteSignatureToFilePath(signatureField,
|