A visible PDF signature shows who signed the document, when and why, directly on the page. This C# sample adds a second signature to a signed document with a signature image, a custom text and an exact position, and shows the same signature on several pages.

The appearance of a visible signature

  • Position: one of the corners or the middle of the page (SignaturePosition), or an exact rectangle in points (SignatureAdvancedPosition).
  • Image: a handwritten signature or a company seal (SignatureImage), next to the text or alone (SignatureImageType).
  • Text: the default text (signer, date, reason, location) or your own text (SignatureText).
  • Pages: one page (SignaturePage, int.MaxValue for the last page), several pages (SignaturePages) or every page (SignatureAppearsOnAllPages). It is one signature with several appearances.

C# code: signature with an image and a custom position

The existing signature of the document remains valid: the new signature is added in an incremental update of the PDF file.

/// <summary>
/// Adds a second signature to an already signed PDF file. The existing signature remains valid.
/// </summary>
static void AddSecondSignatureWithImage(string signedPdfFile, string signedTwicePdfFile)
{
    PdfSignature pdfSignature = new PdfSignature(LibrarySerialNumber);

    pdfSignature.LoadPdfDocument(File.ReadAllBytes(signedPdfFile));

    pdfSignature.DigitalSignatureCertificate = LoadSigningCertificate();

    pdfSignature.SigningReason = "I approve this document";
    pdfSignature.SigningLocation = "Accounting department";

    // The position of the visible signature as a rectangle: X and Y (in points, from the bottom left corner
    // of the page), width and height.
    pdfSignature.SignatureAdvancedPosition = new Rectangle(10, 10, 400, 150);

    // The signature image is displayed on the left of the signature text.
    pdfSignature.SignatureImage = File.ReadAllBytes(SampleFile("signature_image.jpg"));
    pdfSignature.SignatureImageType = SignatureImageType.ImageAndText;

    // The default text of the signature (the signer name, the date, the reason and the location) can be replaced.
    pdfSignature.SignatureText = "Signature created by: " + pdfSignature.DigitalSignatureCertificate.GetNameInfo(X509NameType.SimpleName, false)
        + Environment.NewLine + "Date: " + DateTime.Now.ToString("dd.MM.yyyy HH:mm");

    // The hash algorithm of the signature (SHA-256 is the default).
    pdfSignature.HashAlgorithm = SignLib.HashAlgorithm.SHA256;

    // PAdES signature (ETSI EN 319 142), recognized by Adobe Reader X and later. The default format is PKCS#7,
    // also recognized by the older PDF readers.
    pdfSignature.SignatureStandard = PdfSignatureStandard.Pades;

    // Optionally, the signature can be time-stamped (RFC 3161) by a Time Stamping Authority (TSA).
    // pdfSignature.TimeStamping.ServerUrl = new Uri("https://ca.signfiles.com/TSAServer.aspx");

    File.WriteAllBytes(signedTwicePdfFile, pdfSignature.ApplyDigitalSignature());

    Console.WriteLine("The second PDF signature was created." + Environment.NewLine);
}

C# code: the signature on the first and the last page

/// <summary>
/// Signs a document with 3 pages with a visible signature on the first page and on the last page. A single signature is created: its
/// appearance is displayed on every selected page.
/// </summary>
static void SignOnSeveralPages(string unsignedPdfFile, string signedPdfFile)
{
    // A document with 3 pages (the sample document repeated three times). PdfMerge can also merge different documents.
    byte[] page = File.ReadAllBytes(unsignedPdfFile);
    byte[] document = PdfMerge.MergePdfFiles(new List<byte[]> { page, page, page });

    PdfSignature pdfSignature = new PdfSignature(LibrarySerialNumber);

    pdfSignature.LoadPdfDocument(document);
    pdfSignature.DigitalSignatureCertificate = LoadSigningCertificate();
    pdfSignature.SigningReason = "I approve this document";
    pdfSignature.SignaturePosition = SignaturePosition.BottomRight;

    // The page numbers start at 1 and int.MaxValue means the last page. Other possibilities:
    //   pdfSignature.SignaturePage = 2;                          - a single page;
    //   pdfSignature.SignatureAppearsOnAllPages = true;          - every page.
    pdfSignature.SignaturePages = new List<int> { 1, int.MaxValue };

    File.WriteAllBytes(signedPdfFile, pdfSignature.ApplyDigitalSignature());

    Console.WriteLine("The PDF signature with several pages was created." + Environment.NewLine);
}

A complete sample with several signers, fonts and right-to-left text is the project PDF Digital Signature Multiple Pages and Signers, also included in the download.

Run the full sample. The complete Visual Studio project PDF Digital Signature is included in the library download, in the folder NET Sample Projects (.NET 8, .NET 9, .NET 10 and .NET 11) and in NET Framework Sample Projects (.NET Framework 4.6.2), with the test files and a test certificate. Without a serial number the library runs in demo mode. Download the library and the samples · User manual

Frequently asked questions

Can I create an invisible PDF signature?

Yes. Set VisibleSignature = false: the signature is shown only in the signature panel of the PDF reader.

Can several people sign the same PDF?

Yes. Every signature is added in an incremental update, so the previous signatures remain valid. Only the first signature of a document can be a certification signature.