NuGet을 통해 설치됨
PM> Install-Package Spire.PDF
관련된 링크들
PDF 문서가 비즈니스에서 점점 더 인기를 끌면서 문서의 신뢰성을 보장하는 것이 주요 관심사가 되었습니다. 인증서 기반 서명으로 PDF에 서명하면 콘텐츠를 보호할 수 있으며 문서에 서명하거나 승인한 사람을 다른 사람에게 알릴 수도 있습니다. 이 기사에서는 다음 방법을 배웁니다 보이지 않거나 보이는 서명을 사용하여 PDF에 디지털 서명을 하고, 그리고 어떻게 PDF에서 디지털 서명 제거 Spire.PDF for .NET 사용합니다.
Spire.PDF for .NET 설치
저 Spire.PDF for.NET 패키지에 포함된 DLL 파일을 .NET 프로젝트의 참조로 추가해야 합니다. DLL 파일은 이 링크 에서 다운로드하거나 NuGet을 통해 설치할 수 있습니다.
PM> Install-Package Spire.PDF
PDF에 보이지 않는 디지털 서명 추가
다음은 Spire.PDF for .NET 사용하여 PDF에 보이지 않는 디지털 서명을 추가하는 단계입니다.
- PdfDocument 개체를 만듭니다.
- PdfDocument.LoadFromFile() 메서드를 사용하여 샘플 PDF 파일을 로드합니다.
- PdfCertificate 객체를 초기화하는 동안 pfx 인증서 파일을 로드합니다.
- 인증서를 기반으로 PdfSignature 개체를 만듭니다.
- PdfSignature 개체를 통해 문서 권한을 설정합니다.
- PdfDocument.SaveToFile() 메서드를 사용하여 문서를 다른 PDF 파일에 저장합니다.
- C#
- VB.NET
using Spire.Pdf;
using Spire.Pdf.Security;
namespace AddInvisibleSignature
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Load a sample PDF file
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pdf");
//Load the certificate
PdfCertificate cert = new PdfCertificate("C:\\Users\\Administrator\\Desktop\\MyCertificate.pfx", "e-iceblue");
//Create a PdfSignature object
PdfSignature signature = new PdfSignature(doc, doc.Pages[doc.Pages.Count - 1], cert, "MySignature");
//Set the document permission to forbid changes but allow form fill
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges | PdfCertificationFlags.AllowFormFill;
//Save to another PDF file
doc.SaveToFile("InvisibleSignature.pdf");
doc.Close();
}
}
}

PDF에 보이는 디지털 서명 추가
다음은 Spire.PDF for .NET 사용하여 PDF에 눈에 보이는 디지털 서명을 추가하는 단계입니다.
- PdfDocument 개체를 만듭니다.
- PdfDocument.LoadFromFile() 메서드를 사용하여 샘플 PDF 파일을 로드합니다.
- PdfCertificate 객체를 초기화하는 동안 pfx 인증서 파일을 로드합니다.
- PdfSignature 개체를 만들고 문서에서 위치와 크기를 지정합니다.
- 날짜, 이름, 위치, 사유, 자필 서명 이미지, 문서 권한 등 서명 세부 사항을 설정합니다.
- PdfDocument.SaveToFile() 메서드를 사용하여 문서를 다른 PDF 파일에 저장합니다.
- C#
- VB.NET
using System;
using System.Drawing;
using Spire.Pdf;
using Spire.Pdf.Security;
using Spire.Pdf.Graphics;
namespace AddVisibleSignature
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Load a sample PDF file
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pdf");
//Load the certificate
PdfCertificate cert = new PdfCertificate("C:\\Users\\Administrator\\Desktop\\MyCertificate.pfx", "e-iceblue");
//Create a PdfSignature object and specify its position and size
PdfSignature signature = new PdfSignature(doc, doc.Pages[doc.Pages.Count - 1], cert, "MySignature");
RectangleF rectangleF = new RectangleF(doc.Pages[0].ActualSize.Width - 260 - 54 , 200, 260, 110);
signature.Bounds = rectangleF;
signature.Certificated = true;
//Set the graphics mode to ImageAndSignDetail
signature.GraphicsMode = GraphicMode.SignImageAndSignDetail;
//Set the signature content
signature.NameLabel = "Signer:";
signature.Name = "Gary";
signature.ContactInfoLabel = "Phone:";
signature.ContactInfo = "0123456";
signature.DateLabel = "Date:";
signature.Date = DateTime.Now;
signature.LocationInfoLabel = "Location:";
signature.LocationInfo = "USA";
signature.ReasonLabel = "Reason:";
signature.Reason = "I am the author";
signature.DistinguishedNameLabel = "DN:";
signature.DistinguishedName = signature.Certificate.IssuerName.Name;
//Set the signature image source
signature.SignImageSource = PdfImage.FromFile("C:\\Users\\Administrator\\Desktop\\handwrittingSignature.png");
//Set the signature font
signature.SignDetailsFont = new PdfTrueTypeFont(new Font("Arial Unicode MS", 12f, FontStyle.Regular));
//Set the document permission to forbid changes but allow form fill
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges | PdfCertificationFlags.AllowFormFill;
//Save to file
doc.SaveToFile("VisiableSignature.pdf");
doc.Close();
}
}
}

PDF에서 디지털 서명 제거
다음은 Spire.PDF for .NET 사용하여 PDF에서 디지털 서명을 제거하는 단계입니다.
- PdfDocument 개체를 만듭니다.
- PdfDocument.Form 속성을 통해 문서에서 양식 위젯을 가져옵니다.
- 위젯을 반복하고 특정 위젯이 PdfSignatureFieldWidget인지 확인합니다.
- PdfFieldCollection.RemoveAt() 메서드를 사용하여 서명 위젯을 제거합니다.
- PdfDocument.SaveToFile() 메서드를 사용하여 문서를 다른 PDF 파일에 저장합니다.
- C#
- VB.NET
using Spire.Pdf;
using Spire.Pdf.Widget;
namespace RemoveSignature
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument("C:\\Users\\Administrator\\Desktop\\VisiableSignature.pdf");
//Get form widgets from the document
PdfFormWidget widgets = doc.Form as PdfFormWidget;
//Loop through the widgets
for (int i = 0; i < widgets.FieldsWidget.List.Count; i++)
{
//Get the specific widget
PdfFieldWidget widget = widgets.FieldsWidget.List[i] as PdfFieldWidget;
//Determine if the widget is a PdfSignatureFieldWidget
if (widget is PdfSignatureFieldWidget)
{
//Remove the widget
widgets.FieldsWidget.RemoveAt(i);
}
}
//Save the document to another PDF file
doc.SaveToFile("RemoveSignatures.pdf");
}
}
}
임시 라이센스 신청
생성된 문서에서 평가 메시지를 제거하고 싶거나, 기능 제한을 없애고 싶다면 30일 평가판 라이센스 요청 자신을 위해.