I want change C# PdfFileSignature problem

I want to use Aspose.PDF for PKCS#12 digital signatures. I would like to change the signature field from “Digitally signed by ‘CN=XXXX, E=xxx@example.com, OU=xxx, O=XXXX’” to “testName”. Is there any function available for this?

@kiva_Huang

To change the signature field text in a PDF document using Aspose.PDF for C#, you can customize the appearance of the digital signature. While the default signature text includes details like the signer’s name and email, you can modify it to display a custom name, such as “testName”.

Here’s how you can achieve this:

  1. Create a PdfFileSignature object: This object will allow you to bind the PDF file you want to sign.
  2. Set the signature appearance: You can specify a custom appearance for the signature, which can include text.
  3. Use the Sign method: This method allows you to sign the PDF and specify the appearance.

Here is a sample code snippet demonstrating how to set a custom signature appearance:

using System;
using Aspose.Pdf;
using Aspose.Pdf.Facades;

namespace AsposePdfExample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Path to the PDF file
            string pdfFilePath = "path/to/your/document.pdf";
            string outputFilePath = "path/to/your/signed_document.pdf";
            string certificatePath = "path/to/your/certificate.pfx";
            string certificatePassword = "your_certificate_password";

            // Create PdfFileSignature object
            PdfFileSignature pdfSign = new PdfFileSignature();
            pdfSign.BindPdf(pdfFilePath);

            // Define the rectangle for the signature location
            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100);

            // Set the signature appearance
            pdfSign.SignatureAppearance = "testName"; // Custom text for the signature

            // Create a PKCS1 signature object
            PKCS1 signature = new PKCS1(certificatePath, certificatePassword);

            // Sign the PDF
            pdfSign.Sign(1, "Signature Reason", "Contact", "Location", true, rect, signature);

            // Save the signed PDF
            pdfSign.Save(outputFilePath);
        }
    }
}

In this example, replace the paths and password with your actual certificate and file paths. The SignatureAppearance property is set to “testName”, which will be displayed in the signature field.

For more detailed information on digitally signing PDFs with Aspose.PDF, you can refer to the official documentation here and check the provided code examples for further customization options.

Sources:
[1]: Digitally Sign In PDF File | Aspose.PDF for .NET API Reference

I can only change the background picture. but I need to change the black field to “testName”.
image.png (6.3 KB)

@kiva_Huang

Can you please share the sample PDF for our reference so that we can test the scenario in our environment and address it accordingly.

Hello, My test1 and test2 are PDFs, and I want to change the digital signatures to match the style of my testImg3, with the ability to customize the signature text. I use the attribute signature.SignatureAppearance, which only allows me to add a signature image but not text.
test1.pdf (646.9 KB)

test2.pdf (657.7 KB)

testImg3.jpg (10.3 KB)

@kiva_Huang

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-58125

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.