In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
It is believed that many inexperienced people have no idea about how to obtain the digital signature certificate in PDF. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
The digital signature in PDF is a valid proof of the authority of the document. When we add a signature to an PDF document, we need to prepare a trusted signing certificate. At the same time, for the existing signature, the validity of the signature can be verified, and the signature certificate information in the document can also be obtained. Next, use the C# code example to show how to obtain the digitally signed certificate information in PDF.
Environmental preparation
You need to import Spire.Pdf.dll into the program. Here, take a console application as an example. Referencing dll, you can choose either of the following two methods:
Method 1: open solution Explorer, right-click "reference", "add reference":
Select Browse, Browse, and locate the Spire.Pdf.dll file under the local path BIN folder:
After adding to the reference list, check the box and click "OK" to complete the reference:
Method 2: install via NuGet.
In the VS program, open solution Explorer, right-click "reference", "manage NuGet packages":
Click "search", type in the search box, click on the package, install:
Or install it through the PM console:
Install-Package Spire.PDF-Version 7.11.1
Code example
Implement the certificate to read the signature. This code is mainly divided into the following steps:
1. Instantiate the object of the PdfDocument class, and use PdfDocument. The LoadFromFile (string filename) method loads the PDF document.
two。 Through PdfFormWidget. The FieldsWidget property gets the domain collection of the PdfFormFieldWidgetCollection class
3. Iterate through all the fields through the for loop and determine whether the fields in the collection are signed fields of the PdfSignatureFieldWidget class.
4. After getting the signature domain of the PdfSignatureFieldWidget class, through the PdfSignatureFieldWidget. The Signature.Certificate property gets the signing certificate, and more than 20 methods enumerated under this property (as shown in the following figure) to obtain the details of the certificate.
(this code simply enumerates the use of two methods to obtain certificate information. )
5. Finally, the certificate information is output through the console.
C#
Using Spire.Pdf;using Spire.Pdf.Widget;using System;namespace GetCertificateInfo {class Program {static void Main (string [] args) {/ / instantiate the object of the PdfDocument class and load the PDF document PdfDocument pdf = new PdfDocument (); pdf.LoadFromFile ("test.pdf"); / / get the domain collection PdfFormWidget pdfFormWidget = (PdfFormWidget) pdf.Form PdfFormFieldWidgetCollection pdfFormFieldWidgetCollection = pdfFormWidget.FieldsWidget; / / traversing the domain for (int I = 0; I < pdfFormFieldWidgetCollection.Count If (pdfFormFieldWidgetCollection [I] is PdfSignatureFieldWidget) {/ / get the signature domain PdfSignatureFieldWidget signatureFieldWidget = (PdfSignatureFieldWidget) pdfFormFieldWidgetCollection [I]; / / get the signature certificate string certificateInfo = signatureFieldWidget.Signature.Certificate.ToString () / / obtain certificate format string format = signatureFieldWidget.Signature.Certificate.GetFormat (); Console.WriteLine (certificateInfo+ "\ n" + "[CertificateFormat]\ n" + format);}} Console.ReadKey ();}
VB.NET
Imports Spire.PdfImports Spire.Pdf.WidgetNamespace GetCertificateInfo Class Program Private Shared Sub Main (args As String ()) 'instantiates the object of the PdfDocument class And load the PDF document Dim pdf As New PdfDocument () pdf.LoadFromFile ("test.pdf") 'get the domain collection Dim pdfFormWidget As PdfFormWidget = DirectCast (pdf.Form) PdfFormWidget) Dim pdfFormFieldWidgetCollection As PdfFormFieldWidgetCollection = pdfFormWidget.FieldsWidget 'traversal domain For i As Integer = 0 To pdfFormFieldWidgetCollection.Count-1' determine whether it is the signature domain If TypeOf pdfFormFieldWidgetCollection (I) Is PdfSignatureFieldWidget Then 'get signature domain Dim signatureFieldWidget As PdfSignatureFieldWidget = DirectCast (pdfFormFieldWidgetCollection (I)) PdfSignatureFieldWidget) 'get signing certificate Dim certificateInfo As String = signatureFieldWidget.Signature.Certificate.ToString ()' get certificate format Dim format As String = signatureFieldWidget.Signature.Certificate.GetFormat () Console.WriteLine (Convert.ToString ((certificateInfo & Convert.ToString (vbLf)) + "[CertificateFormat]" & VbLf & ") & format) End If Next Console.ReadKey () End Sub End ClassEnd Namespace read result
After reading the above, have you mastered how C # can obtain the digital signature certificate in PDF? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.