Articles in this section

How to get page number from signature field in a PDF document using C# and VB.NET

The Syncfusion Essential® PDF is a feature-rich and high-performance .NET PDF library that is used to create, read, and edit the PDF documents programmatically without Adobe dependencies. This library also offers functionality to merge, split, stamp, forms, compress, and secure the PDF files. Using this library, you can get a page number from the signature field in a PDF document.

Steps to get a page number from the signature field in a PDF document using C# programmatically

1. Create a new C# console application project.

Create a console application.

2. Install the Syncfusion.PDF.WinForms NuGet packages as a reference to your .NET Framework application from NuGet.org.

Install the nuget packages

3. Include the following namespaces in the Program.cs file.

C#

using Syncfusion.Pdf;
using Syncfusion.Pdf.Parsing;

 

VB.NET

Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Parsing

 

4. The following code example shows how to get a page number from the signature field in a PDF document using C#.

C#

PdfLoadedDocument document = new PdfLoadedDocument(@"../../Data/Input.pdf");
 
//Load the page collections.
PdfLoadedPageCollection loadedPages = document.Pages;
int pageIndex = -1;
 
var pdfForm = document.Form;
 
//Existing PDF document pages.
for (int i = 0; i < loadedPages.Count; i++)
{
    PdfLoadedPage loadedPage = loadedPages[i] as PdfLoadedPage;
    if (pdfForm != null)
    {
       foreach (PdfLoadedField field in pdfForm.Fields)
          {
              if (field is PdfLoadedSignatureField)
                 {
                    // Get the page number of the `signatureField`?
                    if (loadedPage == field.Page)
                       {
                          pageIndex = i + 1;
                          Console.WriteLine(field.Name + " is in the page of " + pageIndex);
                       }
                 }
          }
 
    }
}
Console.ReadKey();
 

 

VB.NET

        Dim document As PdfLoadedDocument = New PdfLoadedDocument("../../Data/Input.pdf")
        Dim loadedPages As PdfLoadedPageCollection = document.Pages
        Dim pageIndex As Integer = -1
        Dim pdfForm = document.Form
        Dim signatureField As PdfLoadedSignatureField = Nothing
 
        For i As Integer = 0 To loadedPages.Count - 1
            Dim loadedPage As PdfLoadedPage = TryCast(loadedPages(i), PdfLoadedPage)
 
            If pdfForm IsNot Nothing Then
 
                For Each field As PdfLoadedField In pdfForm.Fields
 
                    If TypeOf field Is PdfLoadedSignatureField Then
 
                        If loadedPage Is field.Page Then
                            pageIndex = i + 1
                            Console.WriteLine(field.Name & " is in the page of " & pageIndex)
                        End If
                    End If
                Next
            End If
        Next
 
        Console.ReadKey()

 

A complete working sample can be downloaded from PdfSample.zip.

A complete working VB sample can be downloaded from PdfSample_VB.zip.

By executing the program, you will get the PDF document as follows.

Output screenshot

In the above-given code sample, the “pageIndex” value will hold the page number in which the given text is located.

Refer to this link to explore a rich set of Syncfusion Essential® PDF features.

Note:

Starting with v16.2.0.x, if you reference Syncfusion® assemblies from the trial setup or the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.

 

Also see:

https://help.syncfusion.com/file-formats/pdf/working-with-text

https://www.syncfusion.com/kb/9926/how-to-find-page-number-for-the-text-in-a-pdf-using-c-and-vb-net

 

Conclusion:

I hope you enjoyed learning about how to get page number from signature field in a PDF document using C# and VB.NET.

 

You can refer to our Flutter PDF feature tour page to learn about its other groundbreaking features and documentation, and how to quickly get started with configuration specifications. You can also explore our Flutter PDF Flutter PDF examples to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to explore our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied