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.

Sat Jul 13, 2024 11:19 pm

I using the Spire.Pdf.Interactive.DigitalSignatures.PdfSignatureAppearance and want to utilize the

Spire PDF version 10.1.10

PdfSignatureAppearance.Generate(PdfCanvas g)

But not sure how the Generate is placing the canvas I create as it's not going into my signature field. Instead It's printing at the top of my PDF and not in the signature field placeholder.

Code: Select all

 //Create PdfOrdinarySignatureMaker
 Spire.Pdf.Interactive.DigitalSignatures.PdfOrdinarySignatureMaker signatureMaker = new Spire.Pdf.Interactive.DigitalSignatures.PdfOrdinarySignatureMaker(doc, kcertificate);

 //Set signature appearance
 Spire.Pdf.Interactive.DigitalSignatures.PdfSignatureAppearance signatureAppearance = new Spire.Pdf.Interactive.DigitalSignatures.PdfSignatureAppearance(signatureMaker.Signature);

 //Custom Appearance
 var pdfBrush = PdfBrushes.Black;
 var font = new Spire.Pdf.Graphics.PdfFont(PdfFontFamily.Helvetica, 10);
 Rectangle rec = new Rectangle(new Point(10, 20), new Size(150, 150));

 var layer = doc.Layers.AddLayer("Layer1", Spire.Pdf.Graphics.Layer.PdfVisibility.On);
 PdfCanvas graphic =  layer.CreateGraphics(doc.Pages[0].Canvas);
 graphic.DrawString("Johnathan Smith", font, PdfBrushes.Black, rec);

 signatureAppearance.Generate(graphic);

//Add the signature
signatureMaker.MakeSignature("Signature1", doc.Pages[int.Parse(coordinates["PageIndex"].ToString())], coordinates["X"] - 7, coordinates["Y"] - 10, coordinates["Width"] - 25, coordinates["Height"] + 5, signatureAppearance);


motogeek
 
Posts: 15
Joined: Tue Mar 16, 2021 4:18 am

Mon Jul 15, 2024 6:43 am

Hello,

Thanks for your inquiry.
Do you want to customize your signature? If so, the following code may be helpful. If not, please provide us with your input pdf file and screenshots to show us what you want to achieve, so that we can investigate further. Thanks in advance.
Code: Select all
    static void Main(string[] args)
        {
            X509Certificate2 x509 = new X509Certificate2(@"gary.pfx", "e-iceblue");

            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(@"test.pdf");

            PdfOrdinarySignatureMaker signatureMaker = new PdfOrdinarySignatureMaker(doc, x509);


            IPdfSignatureAppearance signatureAppearance = new PdfCustomSignatureAppearance();
            for (int i = 0; i < 3; i++)
            {
                signatureMaker.MakeSignature("signName_" + (i + 1), doc.Pages[i], 100, 100, 100, 100, signatureAppearance);
            }

            doc.SaveToFile(@"result.pdf", FileFormat.PDF);

            doc.Close();
        }

        public class PdfCustomSignatureAppearance : IPdfSignatureAppearance
        {
            public void Generate(PdfCanvas g)
            {
                float fontSize = 10;
                PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", fontSize), true);
                float lineHeight = fontSize; g.DrawString("AAAAAAAAAAA", font, PdfBrushes.Red, new PointF(0, 0));
                g.DrawImage(PdfImage.FromFile(@"logo.png"), new PointF(20, 0));
            }
        }

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 454
Joined: Mon Dec 27, 2021 2:23 am

Mon Jul 15, 2024 7:39 am

Thanks for the reply, I see you have a interface implementation example and is what I was looking for. Let me try this and get back to you. This might solve another problem I have using the layer example I did. I will reply shortly.

motogeek
 
Posts: 15
Joined: Tue Mar 16, 2021 4:18 am

Return to Spire.PDF