ByteScout PDF SDK - C# - Sign PDF and Set Security - ByteScout

ByteScout PDF SDK – C# – Sign PDF and Set Security

  • Home
  • /
  • Articles
  • /
  • ByteScout PDF SDK – C# – Sign PDF and Set Security

How to sign PDF and set security in C# using ByteScout PDF SDK

Write code in C# to sign PDF and set security with this step-by-step tutorial

ByteScout tutorials are designed to explain the code for both C# beginners and advanced programmers. What is ByteScout PDF SDK? It is the library for pdf documents generation, modification and updates. Can also generate and fill PDF forms. Provides support for text (fonts, style, size, font family), layers, pdf form fields, vector and raster drawings. It can help you to sign PDF and set security in your C# application.

This code snippet below for ByteScout PDF SDK works best when you need to quickly sign PDF and set security in your C# application. This C# sample code is all you need for your app. Just copy and paste the code, add references (if needs to) and you are all set! Enjoy writing a code with ready-to-use sample codes in C#.

Trial version of ByteScout PDF SDK is available for free. Source code samples are included to help you with your C# app.

On-demand (REST Web API) version:
 Web API (on-demand version)

On-premise offline SDK for Windows:
 60 Day Free Trial (on-premise)

Program.cs
      
using System.Diagnostics; using System.Drawing; using Bytescout.PDF; using Font = Bytescout.PDF.Font; using SolidBrush = Bytescout.PDF.SolidBrush; using StringFormat = Bytescout.PDF.StringFormat; namespace Signing { /// <summary> /// This example demonstrates how to digitally sign PDF document. /// </summary> class Program { static void Main() { // Create new document Document pdfDocument = new Document(); pdfDocument.RegistrationName = "demo"; pdfDocument.RegistrationKey = "demo"; // Add page Page page = new Page(PaperFormat.A4); pdfDocument.Pages.Add(page); // Add sample page content SolidBrush brush = new SolidBrush(); Font font = new Font("Arial", 16); RectangleF rect = new RectangleF(0, 50, page.Width, 100); StringFormat stringFormat = new StringFormat(); stringFormat.HorizontalAlign = HorizontalAlign.Center; page.Canvas.DrawString("Signature Test", font, brush, rect, stringFormat); // Signing parameters string certficateFile = ".\\demo_certificate.pfx"; string certficatePassword = "123"; // Optional parameters string signingReason = "Approval"; string contactName = "John Smith"; string location = "Corporate HQ"; // Invisible signature //pdfDocument.Sign(certficateFile, certficatePassword); // Visible signature RectangleF signatureRect = new RectangleF(400, 50, 150, 100); pdfDocument.Sign(certficateFile, certficatePassword, signatureRect, signingReason, contactName, location); // Save document to file pdfDocument.Save("result.pdf"); // Cleanup pdfDocument.Dispose(); // Open result document in default associated application (for demo purpose) ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf"); processStartInfo.UseShellExecute = true; Process.Start(processStartInfo); } } }

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF SDK Home Page

Explore ByteScout PDF SDK Documentation

Explore Samples

Sign Up for ByteScout PDF SDK Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

VIDEO

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF SDK Home Page

Explore ByteScout PDF SDK Documentation

Explore Samples

Sign Up for ByteScout PDF SDK Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next