푸터 콘텐츠로 바로가기
IRONPDF 사용

How to Create PDF Signatures in .NET

This article will delve into the additional features and capabilities of IronPDF, along with sample source code snippets, to help you get started with integrating digital signing into your PDF file.

Understanding Digital Signatures and IronPDF

Digital signatures serve as electronic counterparts of traditional handwritten signatures, providing an added layer of security and trustworthiness to electronic documents. Digitally signing a PDF document becomes easy with IronPDF, allowing developers to generate, validate, manage, and add digital signatures effortlessly.

Setting Up IronPDF

To ensure a smooth integration of the IronPDF library into your .NET project, it is crucial to follow these steps for setup and implementation. These instructions assume you are using Visual Studio as your development environment.

  1. Launch Visual Studio and open the application.
  2. From the "File" menu, select "New Project."
  3. In the dialog box that appears, choose the "Console App" template.
  4. Click on the Next button to proceed.

Please note that these initial steps will lay the foundation for incorporating the IronPDF library seamlessly into your project.

How to Create PDF Signature in .NET, Figure 2: Create a new project in Visual Studio Create a new project in Visual Studio

To proceed with creating your project, provide the necessary information in the designated fields. Enter a suitable name for your project in the "Project name" box, and specify the desired location for the new project in the "Location" field. Once you have entered this information, click the Next button to proceed further.

How to Create PDF Signature in .NET, Figure 3: Configure your new project Configure your new project

To configure the framework for your project, follow these steps. Start by selecting a .NET Framework from the options provided in the drop-down menu. For this scenario, .NET version 6.0 is recommended. Once you have made your selection, proceed by clicking the Create button to initiate the project creation process.

How to Create PDF Signature in .NET, Figure 4: .NET Framework selection .NET Framework selection

To proceed further, you will need to download the required IronPDF library for your solution. To achieve this, you can use the following command in the Package Manager Console.

Install-Package IronPdf

As an alternative, the NuGet Package Manager can be used to look for the IronPDF package.

How to Create PDF Signature in .NET, Figure 5: Navigate and install the IronPDF package in NuGet Package Manager UI Navigate and install the IronPDF package in NuGet Package Manager UI

Adding Digital Signatures Programmatically

Let's explore how to add digital signatures to PDF documents using IronPDF.

Creating a New PDF Document

To get started, you need to create a new PDF document using the ChromePdfRenderer. Use the RenderHtmlAsPdf method to convert an HTML string into a PDF document. Here's an example:

using IronPdf;

// Create a PDF from an HTML string
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");

// Export to a file or stream
pdf.SaveAs("output.pdf");
using IronPdf;

// Create a PDF from an HTML string
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");

// Export to a file or stream
pdf.SaveAs("output.pdf");
$vbLabelText   $csharpLabel

You can also render an HTML file into a PDF using the RenderHtmlFileAsPdf method. Here's an example:

using IronPdf;

// Create a PDF from an existing HTML file
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlFileAsPdf("example.html");

// Export to a file or stream
pdf.SaveAs("output.pdf");
using IronPdf;

// Create a PDF from an existing HTML file
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlFileAsPdf("example.html");

// Export to a file or stream
pdf.SaveAs("output.pdf");
$vbLabelText   $csharpLabel

Loading an Existing PDF Document

If you want to sign PDF documents that are ready-made, IronPDF allows you to load them using the PdfDocument.FromFile method. Here's an example:

using IronPdf;

// Load an existing PDF document
var document = PdfDocument.FromFile("path/to/document.pdf");
using IronPdf;

// Load an existing PDF document
var document = PdfDocument.FromFile("path/to/document.pdf");
$vbLabelText   $csharpLabel

Generating a Self-Signed Certificate and Signing a PDF

Before adding a digital signature, you'll need a digital certificate. You can easily create OpenSSL digital certificates using Adobe Acrobat; they can be either PFX digital certificates or P12 digital certificates. Once these certificates are generated, you can easily use them to sign a PDF using IronPDF.

In the code below, you can sign a PDF file using IronPDF with a PFX file advanced electronic signature. This tutorial shows you how to generate certificates using Adobe Acrobat.

using IronPdf;
using IronPdf.Signing;
using System;

// Create a PDF from HTML
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument doc = renderer.RenderHtmlAsPdf("<h1>foo</h1>");

// Create a digital signature
var signature = new PdfSignature("Iron.pfx", "123456")
{
    SigningContact = "support@ironsoftware.com",
    SigningLocation = "Chicago, USA",
    SigningReason = "To show how to sign a PDF"
};

// Sign the PDF document
doc.Sign(signature);

// Save the signed PDF
doc.SaveAs("signed.pdf");
using IronPdf;
using IronPdf.Signing;
using System;

// Create a PDF from HTML
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument doc = renderer.RenderHtmlAsPdf("<h1>foo</h1>");

// Create a digital signature
var signature = new PdfSignature("Iron.pfx", "123456")
{
    SigningContact = "support@ironsoftware.com",
    SigningLocation = "Chicago, USA",
    SigningReason = "To show how to sign a PDF"
};

// Sign the PDF document
doc.Sign(signature);

// Save the signed PDF
doc.SaveAs("signed.pdf");
$vbLabelText   $csharpLabel

Adding a Digital Signature to the PDF Document

To add electronic signatures to a PDF document, IronPDF provides the PdfSignature class. This method takes the certificate and other necessary parameters to create a digital signature field and embed it in the PDF document. Here's an example of digitally signing a PDF:

using IronPdf.Signing;
using IronSoftware.Drawing;

// Create a PdfSignature object
var sig = new PdfSignature("IronSoftware.pfx", "123456");
sig.SignatureImage = new PdfSignatureImage("IronSoftware.png", 0, new CropRectangle(0, 600, 100, 100));
using IronPdf.Signing;
using IronSoftware.Drawing;

// Create a PdfSignature object
var sig = new PdfSignature("IronSoftware.pfx", "123456");
sig.SignatureImage = new PdfSignatureImage("IronSoftware.png", 0, new CropRectangle(0, 600, 100, 100));
$vbLabelText   $csharpLabel

Validating Digital Signatures

IronPDF allows you to validate digital signatures in PDF documents programmatically. You can use the VerifyPdfSignatures method to verify that the signatures present in the document are still valid. Here's an example:

using IronPdf;

// Load a PDF document
PdfDocument pdf = PdfDocument.FromFile("annual_census.pdf");

// Validate the signatures
bool isValid = pdf.VerifyPdfSignatures();
using IronPdf;

// Load a PDF document
PdfDocument pdf = PdfDocument.FromFile("annual_census.pdf");

// Validate the signatures
bool isValid = pdf.VerifyPdfSignatures();
$vbLabelText   $csharpLabel

Watermarking PDFs

If a digital certificate is not available to sign a PDF document, you can always add a watermark digitally in a corner or in an empty space to hold some sort of ownership on a PDF file. In the source code below, apply a watermark to a PDF file using the ApplyWatermark method.

using IronPdf;
using IronPdf.Editing;

// Load a PDF document
var pdf = PdfDocument.FromFile("invoice.pdf");

// Apply a watermark
pdf.ApplyWatermark("<img src='signature.png'/>", 90, VerticalAlignment.Bottom, HorizontalAlignment.Right);

// Save the watermarked PDF
pdf.SaveAs("official_invoice.pdf");
using IronPdf;
using IronPdf.Editing;

// Load a PDF document
var pdf = PdfDocument.FromFile("invoice.pdf");

// Apply a watermark
pdf.ApplyWatermark("<img src='signature.png'/>", 90, VerticalAlignment.Bottom, HorizontalAlignment.Right);

// Save the watermarked PDF
pdf.SaveAs("official_invoice.pdf");
$vbLabelText   $csharpLabel

Licensing and Pricing

IronPDF is an outstanding C# library that offers developers the freedom to use it for development purposes without any cost. You can try the free trial to test all its functionality. Furthermore, it can also be licensed for commercial usage at any given time. The library caters to the needs of various entities, including individual developers, agencies, multinational organizations, as well as SaaS and OEM redistribution.

With IronPDF, there are diverse licensing options to choose from, ensuring accessibility for all. These licenses encompass a range of benefits such as a 30-day money-back guarantee, one year of comprehensive support and upgrades, validation across development, staging, and production environments, and a perpetual license, which entails a one-time purchase.

For those seeking a budget-friendly option, the Lite package is available at a fixed price of $799, which does not include any recurring expenses. If you require more detailed information or assistance in determining the most suitable license for your needs, please refer to the product licensing page, where you can find additional resources and guidance.

How to Create PDF Signature in .NET, Figure 6: IronPDF Licensing IronPDF Licensing

Conclusion

Implementing digital signatures in PDF documents is a critical aspect of ensuring document integrity, authenticity, and security.

IronPDF, a comprehensive .NET PDF signature library, simplifies this process by providing developers with powerful tools and APIs.

This article explored the features and capabilities of IronPDF, along with sample code snippets, to help you get started with adding digital signatures to your PDF documents programmatically. By leveraging IronPDF's functionalities, you can enhance the security and trustworthiness of your PDF files, enabling secure document exchange in various applications.

Additionally, IronPDF offers developers methods to render PDF documents into images and extract text and content from a PDF. IronPDF is also capable of rendering charts in PDFs, adding barcodes, watermarking, and even handling PDF forms programmatically.

Remember to refer to the official IronPDF documentation and the sample codes provided in this article for further details and comprehensive implementation guidelines. For a detailed tutorial and complete overview of the digital signature library using IronPDF, visit the following guidance.

자주 묻는 질문

.NET Core PDF 라이브러리를 프로젝트에 통합하려면 어떻게 해야 하나요?

IronPDF와 같은 .NET Core PDF 라이브러리를 프로젝트에 통합하려면 Visual Studio에서 새 콘솔 앱을 만들고 선호하는 .NET Framework를 선택한 다음 패키지 관리자 콘솔을 통해 Install-Package IronPdf 명령을 사용하여 IronPDF를 설치할 수 있습니다.

.NET PDF 라이브러리는 문서 보안을 위해 어떤 기능을 제공하나요?

IronPDF와 같은 .NET PDF 라이브러리는 문서 보안과 신뢰성을 높이기 위해 디지털 서명 추가, 암호화, 리댁션과 같은 기능을 제공합니다.

프로그래밍 방식으로 PDF 문서에 디지털 서명을 추가하려면 어떻게 해야 하나요?

디지털 인증서로 PdfSignature 개체를 생성하고 Sign 메서드를 PDF에 적용하여 IronPDF를 사용하여 PDF 문서에 디지털 서명을 추가할 수 있습니다. SaveAs 메서드를 사용하여 서명된 문서를 저장합니다.

PDF에서 디지털 서명의 유효성을 검사하는 프로세스는 무엇인가요?

PDF의 디지털 서명을 검증하려면 IronPDF의 VerifyPdfSignatures 메서드를 사용하여 서명이 진본이고 변경되지 않았는지 확인하세요.

PDF에서 디지털 서명의 대안으로 워터마크를 사용할 수 있나요?

예, 서명을 위한 디지털 인증서를 사용할 수 없는 경우 문서 소유권 또는 상태를 표시하는 대안으로 워터마크를 사용할 수 있습니다.

.NET PDF 라이브러리를 테스트할 수 있는 평가판이 있나요?

IronPDF는 개발자가 상용 라이선스를 구매하기 전에 모든 기능을 테스트할 수 있는 무료 평가판을 제공합니다.

디지털 서명으로 PDF 문서의 무결성을 어떻게 향상시킬 수 있나요?

디지털 서명은 PDF 문서의 진위 여부와 무결성을 검증하는 방법으로 서명이 적용된 이후 콘텐츠가 변경되지 않았는지 확인할 수 있습니다.

PDF 서명을 위한 자체 서명 인증서를 만드는 단계는 무엇인가요?

IronPDF에서 PDF 서명을 위한 자체 서명 인증서를 만들려면 PFX 파일을 생성하고 이를 PdfSignature 클래스와 함께 사용하여 문서에 서명할 수 있습니다.

IronPDF는 .NET 10과 완벽하게 호환되며 어떤 이점이 있나요?

예 - IronPDF는 .NET 10과 완벽하게 호환되며, 새로운 주요 런타임 및 언어 기능을 모두 지원합니다. 개발자는 해결 방법 없이 .NET 10에서 웹, 데스크톱, 마이크로서비스 및 MAUI 앱에 IronPDF를 사용할 수 있습니다. 호환성은 힙 할당 감소, 향상된 해싱과 같은 보안을 위한 최신 API, 확장 블록 및 간단한 람다 매개변수와 같은 C# 14 개선 사항에 대한 액세스를 통해 성능이 향상됨을 의미합니다. 평소와 같이 NuGet을 통해 설치하면 API가 이전 .NET 버전과 동일하게 작동합니다.

커티스 차우
기술 문서 작성자

커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.

커티스는 개발 분야 외에도 사물 인터넷(IoT)에 깊은 관심을 가지고 있으며, 하드웨어와 소프트웨어를 통합하는 혁신적인 방법을 연구합니다. 여가 시간에는 게임을 즐기거나 디스코드 봇을 만들면서 기술에 대한 애정과 창의성을 결합합니다.