Program Guide WPF (29)
This section will introduce a solution to add two types of hyperlinks in PDF document via a WPF PDF component. One is a hyperlink directly displayed as url address in the PDF file, suppose it is named Hyperlink1; The other is a hyperlink in place of text, you can call it hyperlink2. Both of the two hyperlinks can automatically take you to a webpage, a file or an image when you click them. Before you start, it is very necessary to know some information of this PDF component
Spire.PDF for WPF enables you to directly generate, read, write and manipulate PDF files in your WPF applications without installing Adobe Acrobat or any third party library. Using Spire.PDF for WPF, you can easily add PDF hyperlink by three key steps. Please Download Spire.PDF for WPF and view the effective screenshot of this task as below picture:

Step 1: Set the link location in PDF page.
After you loading an existing PDF file or creating a new PDF file(a PDF file is imported from system in this step), please set the approximate location of hyperlink in PDF page by calling the Spire.Pdf.PdfPageBase: Canvas.ClientSize.Height.
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(@"..\image to pdf.pdf");
PdfPageBase page = doc.Pages[0];
PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
PdfMargins margin = new PdfMargins();
margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
margin.Bottom = margin.Top;
margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
margin.Right = margin.Left;
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Verdana", 17));
float space = font.Height * 0.75f;
float y = page.Canvas.ClientSize.Height*0.6f - margin.Bottom + space;
Dim doc As New PdfDocument()
doc.LoadFromFile("D:\michelle\my file\image to pdf.pdf")
Dim page As PdfPageBase = doc.Pages(0)
Dim unitCvtr As New PdfUnitConvertor()
Dim margin As New PdfMargins()
margin.Top = unitCvtr.ConvertUnits(2.54F, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point)
margin.Bottom = margin.Top
margin.Left = unitCvtr.ConvertUnits(3.17F, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point)
margin.Right = margin.Left
Dim font As New PdfTrueTypeFont(New Font("Verdana", 17))
Dim space As Single = font.Height * 0.75F
Dim y As Single = page.Canvas.ClientSize.Height * 0.6F - margin.Bottom + space
Step 2: Add Hyperlink1 in PDF.
In this step, you can draw a string in PDF page by calling Spire.Pdf. PdfPageBase method: PdfPageBase.Canvas.DrawString(string s, PdfFontBase font, PdfBrush brush, float x, float y, PdfStringFormat format) method. As the string format is a url address, a link can be drawn. Also by calculating the string width of label, link and PDF page, both link label location and link location can be set. In this method, link label and link are set in the middle.
String label = "Image Source: ";
PdfStringFormat format = new PdfStringFormat();
format.MeasureTrailingSpaces = true;
float x1 = font.MeasureString(label, format).Width;
PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Verdana", 17, System.Drawing.FontStyle.Bold));
String url1 = "http://www.e-iceblue.com";
float x2 = font2.MeasureString(url1, format).Width;
float x =( page.Canvas.ClientSize.Width-x1-x2)/2;
page.Canvas.DrawString(label, font, PdfBrushes.DeepSkyBlue, x, y, format);
x += x1;
page.Canvas.DrawString(url1, font2, PdfBrushes.DeepSkyBlue, x, y);
y = y + font2.MeasureString(url1).Height;
Dim label As [String] = "Image Source: "
Dim format As New PdfStringFormat()
format.MeasureTrailingSpaces = True
Dim x1 As Single = font.MeasureString(label, format).Width
Dim font2 As New PdfTrueTypeFont(New Font("Verdana", 17, System.Drawing.FontStyle.Bold))
Dim url1 As [String] = "http://www.e-iceblue.com"
Dim x2 As Single = font2.MeasureString(url1, format).Width
Dim x As Single = (page.Canvas.ClientSize.Width - x1 - x2) / 2
page.Canvas.DrawString(label, font, PdfBrushes.DeepSkyBlue, x, y, format)
x += x1
page.Canvas.DrawString(url1, font2, PdfBrushes.DeepSkyBlue, x, y)
y = y + font2.MeasureString(url1).Height
Step 3: Add hyperlink 2 in place of text.
Use the method in step2 to draw a link label and add hyperlink2 in place of text by the method Spire.Pdf.Annotations. PdfTextWebLink to set link properties such as text, url and so on. Finally, invoke DrawTextWebLink(PdfCanvas graphics, PointF location) method to draw the PDF hyperlink in place of text.
label = "Simple Link: ";
x -= x1;
page.Canvas.DrawString(label, font, PdfBrushes.DarkViolet, x, y, format);
float xoffset2 = font.MeasureString(label, format).Width;
x += xoffset2;
String text = "e-iceblue";
PdfTextWebLink link2 = new PdfTextWebLink();
link2.Text = text;
link2.Url = url1;
link2.Font = font2;
link2.Brush = PdfBrushes.DarkViolet;
link2.DrawTextWebLink(page.Canvas, new PointF(x, y));
label = "Simple Link: " x -= x1 page.Canvas.DrawString(label, font, PdfBrushes.DarkViolet, x, y, format) Dim xoffset2 As Single = font.MeasureString(label, format).Width x += xoffset2 Dim text As [String] = "e-iceblue" Dim link2 As New PdfTextWebLink() link2.Text = text link2.Url = url1 link2.Font = font2 link2.Brush = PdfBrushes.DarkViolet link2.DrawTextWebLink(page.Canvas, New PointF(x, y))
Spire.PDF is a PDF document creation component that enables your WPF applications to read, write and manipulate PDF documents without using Adobe Acrobat. Now, the new version added Silverlight platform which makes it more powerful.
PDF Split is always needed by programmers and developers. It is very convenient to split a PDF file to multiple files by using online PDF split tools, you can split PDF in a page range as well as only extract a unique page. However, if you want to split a huge PDF document to hundreds of files, you have to try at least dozens of times, which, undoubtedly, takes too much time. Furthermore, when the network goes slowly, an error is likely to occur, sometimes, the file is reported to be damaged or corrupted. While using Spire.PDF for WPF, you can easily split huge PDF document up to hundreds of pages without any worry of the document safety in your WPF application.
By using Spire.PDF, you can achieve the effect as below:

Spire.PDF for WPF, as a WPF PDF component, allows users to create, read, write and manipulate PDF documents without using Adobe Acrobat or any third party component library. As for PDF split task, you can realize it by below methods:
doc.Split(pattern):
When splitting a PDF document to multiple PDF files, each PDF file is made of one page from the original PDF file. Split method works well since it can quickly split your PDF file and there is only one parameter passed to provide a template name of the destination PDF file.
String.Format(pattern, doc.Pages.Count - 1):
"String.Format" method provides great convenience for you to preview an existing file by returning the PDF file name that you want to process. The second parameter String.Format method is used to point out the index item which starts from 0.
The key step of PDF split task only requires four lines of code, before your start your PDF split project, please download Spirel.PDF for WPF first, then you can invoke the key code below to split any PDF you want.
String pattern = "SplitDocument-{0}.pdf";
doc.Split(pattern);
String lastPageFileName= String.Format(pattern, doc.Pages.Count - 1);
doc.Close();
Dim pattern As String = "SplitDocument-{0}.pdf"
doc.Split(pattern)
Dim lastPageFileName As String = String.Format(pattern, doc.Pages.Count - 1)
doc.Close()
Obviously, using this WPF PDF component, PDF can be split absolutely according to your requirements. Enjoy fast speed, high quality and free choices to build your application to split PDF right now.
Digital signature is more advanced and more popular to detect forgery and tampering today compared with traditional handwritten signature. Especially in business world, digital signature becomes an effective method to safeguard and authenticate your documents. As long as a digital signature is created and singed, the document has not been tampered and the recipients can view both the document version history and any changes that were made to it. Now, it is time to see how to create a PDF digital signature via a WPF PDF component Spire.PDF for WPF.
Spire.PDF for WPF, as a PDF component, enables you to create PDF digital signature in a simple way which can not only ensure your data information has not been altered since it was sent but also verify the signer's digital identity. The key procedure only requires six lines of code. Please preview the effective screenshot below, and then, view the key code.

Please feel free to Download Spire.PDF for WPF first before the key code below. In this solution, for constructing one instance of a Spire.Pdf.Sercurity.PdfCertificate class named cert, we reference a certificate file and its file protect password as parameters. Then, cert is applied to create an instance of a PdfSignature class we name it signature. Setting signature “page” parameter allows you to sign the digital signature of any PDF page. And DocumentPermissions, one property of signature, can be set: AllowComments, AllowFormFill and ForbidChanges.
Core Code:
String pfxPath = @"..\Data\Demo.pfx"; PdfCertificate cert = new PdfCertificate(pfxPath, "e-iceblue"); PdfSignature signature = new PdfSignature(doc, page, cert, "demo"); signature.ContactInfo = "Harry Hu"; signature.Certificated = true; signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill;
Dim pfxPath As String = "..\Data\Demo.pfx" Dim cert As New PdfCertificate(pfxPath, "e-iceblue") Dim signature As New PdfSignature(doc, page, cert, "demo") signature.ContactInfo = "Harry Hu" signature.Certificated = True signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill
For PDF security, people are more likely to encrypt PDF file by setting up to two passwords: owner password and user password. The essential difference between these two passwords is that people can fully control the document by owner password, while only can open or have to subject to some restrictions by user password. This section will introduce a solution to easily encrypt your PDF by the two passwords via Spire.PDF for WPF.
Spire.PDF for WPF is a WPF PDF component, which can encrypt your PDF not only by owner password but also by restricting nine permissions when setting user password. In the solution, these two passwords are set by an object of PDFSecurity class which is contained in the namespace Spire.PDFDocument.Security.
Before you start, please feel free to download Spire.PDF for WPF first and encrypt your PDF file by below key steps after loading it.
Step1: Set PDF password size
In this step, three kinds of key size are applicable by the enum Spire.Pdf.Security.PdfEncryptionKeySize. They are: Key128Bit, Key256Bit and Key40Bit. You can choose any of the three according to your own situation.
doc.Security.KeySize = PdfEncryptionKeySize.Key256Bit;
doc.Security.KeySize = PdfEncryptionKeySize.Key256Bit
Step 2: Secure PDF file by passwords
Owner password and user password are set to encrypt your PDF file. Please make sure that the password size should not be over the key size you set in last step.
doc.Security.OwnerPassword = "e-iceblue"; doc.Security.UserPassword = "pdf";
doc.Security.OwnerPassword = "e-iceblue" doc.Security.UserPassword = "pdf"
Step 3: Restrict certain permissions of user password
Nine access permissions of user password can be specified in the step, you can view them as below picture:

- AccessibilityCopyContent: copy accessibility content.
- AssembleDocument: assemble document permission. (Only for 128 bits key).
- CopyContent: copy content.
- Default: default value means users are authorized all permissions.
- EditAnnotations: add or modify text annotations, fill in interactive form fields.
- EditContent: edit content.
- FillFields: fill form fields. (Only for 128 bits key).
- FullQualityPrint: print document with full quality.
- Print: print document.
Here, three permissions are authorized: AccessibilityCopyContent, Print and EditAnnotations. Now, see following code:
doc.Security.Permissions = PdfPermissionsFlags.AccessibilityCopyContent | PdfPermissionsFlags.Print | PdfPermissionsFlags.EditAnnotations;
doc.Security.Permissions = PdfPermissionsFlags. AccessibilityCopyContent Or PdfPermissionsFlags. Print Or PdfPermissionsFlags.EditAnnotations
After you run the project, appears a dialog box in which you need to input password before opening the PDF document. You can look at the effective screenshot below:

This section will introduce an easy solution to convert image to PDF in WPF. In my method, image to PDF conversion is just a piece of cake since various image formats such as jpg, png and bmp, even images of gif, tif and ico can be converted to PDF through two key steps for Spire.PDF users.
Spire.PDF for WPF,a professional WPF PDF component, enables your WPF applications to read, write and manipulate PDF document without Adobe Acrobat or any third party component library. As for image to PDF conversion, apart from clearly converting images of different formats to PDF, Spire.PDF for WPF also allows you to directly load your images to PDF files from stream. Please feel free to Download Spire.PDF and give it a try following our programming guide below. The following is a picture which we will convert to PDF. At the bottom of this article, a target PDF will be presented.

Now it's time for the key procedure of image to PDF conversion. To realize the key procedure, we need below two steps.
Step 1: Load an image file from system
An image file is required in this step. The image format can be any format among jpg, png, bmp, gif, tif and ico. Here a jpg image is loaded.
//Load a jpg image from system PdfImage image = PdfImage.FromFile(@"..\sky.jpg");
'Load a jpg image from system
Dim image As PdfImage = PdfImage.FromFile("..\sky.jpg")
Step 2: Set the image location and size to fit PDF page
Spire.PDF for WPF contains a namespace “Spire.Pdf.Graphics” in which image size and location are set through four parameters: Width/Height for image size and fitWidth/fitHeight for image location.
//Set image display location and size in PDF float widthFitRate = image.PhysicalDimension.Width / page.Canvas.ClientSize.Width; float heightFitRate = image.PhysicalDimension.Height / page.Canvas.ClientSize.Height; float fitRate = Math.Max(widthFitRate, heightFitRate); float fitWidth = image.PhysicalDimension.Width / fitRate; float fitHeight = image.PhysicalDimension.Height / fitRate; page.Canvas.DrawImage(image, 30, 30, fitWidth, fitHeight);
'Set image display location and size in PDF Dim widthFitRate As Single = image.PhysicalDimension.Width / page.Canvas.ClientSize.Width Dim heightFitRate As Single = image.PhysicalDimension.Height / page.Canvas.ClientSize.Height Dim fitRate As Single = Math.Max(widthFitRate, heightFitRate) Dim fitWidth As Single = image.PhysicalDimension.Width / fitRate Dim fitHeight As Single = image.PhysicalDimension.Height / fitRate page.Canvas.DrawImage(image, 30, 30, fitWidth, fitHeight)
After this coding, run your application, you can find a target PDF as below.

HTML to PDF solution can be quite a few when people search on google. However, most solutions are not proper in use since what you view on webpage is not always completely same with what you get on your PDF. Some information such as dynamic image and anchor text in HTML are easily lost. This section will introduce a simple method to clearly convert HTML to PDF without any cut on WPF platform.
Spire.PDF for WPF, as a professional PDF component, allows you to clearly convert HTML to PDF only by three lines of key code on WPF platform. In the solution, you only need to load HTML file with four parameters:
- URL, the url of the webpage which will be converted to PDF file.
- Enable JavaScrpit, indicates whether enables the JavaScript of the webpage.
- Enable hyperlink, indicates whether enables the hyperlink of the webpage.
- Auto detect page break, indicates whether splits auto the web page in the result PDF file.
Then, save your html as PDF to file by calling the method PdfDocument.LoadFromHTM. Please preview the result screenshot of the whole project first as prove:

Before demonstrating the code, please feel free to download Spire.PDF and install it on system. Now, you can view the full code below:
using Spire.Pdf;
namespace WPFhtmltopdf
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
[STAThread]
private void button1_Click(object sender, RoutedEventArgs e)
{
//Create a new pdf document.
PdfDocument doc = new PdfDocument();
//load the webpage
String url = "http://msdn.microsoft.com/";
doc.LoadFromHTML(url, false, true, true);
//Save html webpage as pdf file.
doc.SaveToFile("sample.pdf");
doc.Close();
}
}
}
Imports Spire.Pdf
Namespace WPFhtmltopdf
'''
''' Interaction logic for MainWindow.xaml
'''
Public Partial Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
_
Private Sub button1_Click(sender As Object, e As RoutedEventArgs)
'Create a new pdf document.
Dim doc As New PdfDocument()
'load the webpage
Dim url As = "http://msdn.microsoft.com/"
doc.LoadFromHTML(url, False, True, True)
'Save html webpage as pdf file.
doc.SaveToFile("sample.pdf")
doc.Close()
End Sub
End Class
End Namespace
Obviously, using this WPF PDF component, the webpage is easily converted to PDF. Both text and images are clearly shown in PDF file. Besides, Spire.PDF for WPF is a 100% secure PDF component software. No Malware, No Spyware and No Virus.
This section is designed to introduce a simple method to clearly convert text to PDF for WPF. During the text to PDF conversion task, font, font color, line space and other text format also can be quickly set according to your own need via a WPF PDF component Spire.PDF for WPF.
Spire.PDF for WPF will display a solution of two key steps to realize text to PDF task as well as customize text in PDF. Compared with some text to PDF converters, Spire.PDF for WPF not only has the function of convert HTML, text and image to PDF, but also owns the ability to read, write and manipulate PDF document without Adobe Acrobat or any third party component library.
Below screenshot gives you a clear view of the text to PDF conversion effect:

Please download Spire.PDF for WPF on system. Then, perform your text to PDF by below key steps.
Step1: Read all text information to s string
In this step, you need to read all the text from a text file to a string.
string text = File.ReadAllText(@"..\texttopdf.txt");
Dim text As String = File.ReadAllText("..\texttopdf.txt")
Step2: Draw string to PDF document with custom layout.
This step allows you to set the text font, font color, text format and position in PDF document at your own will by below code:
PdfPageBase page = section.Pages.Add();
PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 11);
PdfStringFormat format = new PdfStringFormat();
format.LineSpacing = 20f;
float pageWidth = page.Canvas.ClientSize.Width;
PdfBrush brush = PdfBrushes.DarkBlue;
float y = 30;
PdfStringLayouter textLayouter = new PdfStringLayouter();
PdfStringLayoutResult result
= textLayouter.Layout(text, font, format, new SizeF(pageWidth, 0));
foreach (LineInfo line in result.Lines)
{
page.Canvas.DrawString(line.Text, font, brush, 0, y, format);
y = y + result.LineHeight;
}
Dim page As PdfPageBase = section.Pages.Add() Dim font As New PdfFont(PdfFontFamily.Helvetica, 11) Dim format As New PdfStringFormat() format.LineSpacing = 20F Dim pageWidth As Single = page.Canvas.ClientSize.Width Dim brush As PdfBrush = PdfBrushes.DarkBlue Dim y As Single = 30 Dim textLayouter As New PdfStringLayouter() Dim result As PdfStringLayoutResult = textLayouter.Layout(text, font, format, New SizeF(pageWidth, 0)) For Each line As LineInfo In result.Lines page.Canvas.DrawString(line.Text, font, brush, 0, y, format) y = y + result.LineHeight Next
Now that is all the core codes for draw text in PDF. Apart from converting text to PDF, Spire.PDF for WPF also can extract PDF text.

doc.LoadFromFile(@"..\Sample.pdf"); System.Drawing.Image image = System.Drawing.Image.FromFile(@"..\MS.jpg");
doc.LoadFromFile("..\Sample.pdf")
Dim image As System.Drawing.Image = System.Drawing.Image.FromFile("..\MS.jpg")
//adjust image size int width = image.Width; int height = image.Height; float schale = 0.7f; System.Drawing.Size size = new System.Drawing.Size((int)(width * schale), (int)(height * schale)); Bitmap schaleImage = new Bitmap(image, size); //draw image into the first PDF page at specific position PdfImage pdfImage = PdfImage.FromImage(schaleImage); PdfPageBase page0 = doc.Pages[0]; PointF position = new PointF((page0.Canvas.ClientSize.Width - schaleImage.Width) / 8, 10); page0.Canvas.DrawImage(pdfImage, position);
'adjust image size Dim width As Integer = image.Width Dim height As Integer = image.Height Dim schale As Single = 0.7F Dim size As New System.Drawing.Size(CInt(Math.Truncate(width * schale)), CInt(Math.Truncate(height * schale))) Dim schaleImage As New Bitmap(image, size) 'draw image into the first PDF page at specific position Dim pdfImage__1 As PdfImage = PdfImage.FromImage(schaleImage) Dim page0 As PdfPageBase = doc.Pages(0) Dim position As New PointF((page0.Canvas.ClientSize.Width - schaleImage.Width) / 8, 10) page0.Canvas.DrawImage(pdfImage__1, position)
Before we start our topic, let us first play a game. At the top of this page, there are nine categories. When we move our mouse on .NET, a dropdown list which shows all e-iceblue .NET products is displayed as the picture below:

Imagine, if we demonstrate every product on .NET out of the dropdown list on the top, what will this page be? The webpage will be rambling and disordered. As a result, visitors will hardly search what they want and finally have to leave disappointedly.
By the same token, if we do not merge PDF files of similar content to one document, all the information of various classes will mix together. We have no choice but to spend much time on finding the right files. While our work turns more efficient when we use PDF merge function. Furthermore, opening more PDF files at the same time always annoys people in that the windows are mistakenly switched. Finally, merge PDF does not mean gathering tens of PDF files into one. More reasonable choice is to amalgamate PDF files of few pages into single one. Those of numerous pages should be combined with merged PDF files in one folder for the convenience of reading.
Spire.PDF for WPF, as a professional PDF component, is a best hand for users to merge multiple PDF files on WPF application with C#, VB.NET. The whole procedure can be performed by below three simple steps.
Step 1. Create a C#/VB.NET Project
- Free download and correctly install Spire.PDF for WPF on system.
- Create “PDF merge” project in WPF Application with C#/VB.NET.
- Add a button in MainWindow.
- Add Spire.Pdf.Wpf.dll and System.Drawing as references.
Step 2 Merge PDF Files into One
//pdf document list
String[] files = new String[]
{
@"D:\e-iceblue\Spire.PDF\Demos\Data\DigitalSignature.pdf",
@"D:\e-iceblue\Spire.PDF\Demos\Data\Sample2.pdf",
@"D:\e-iceblue\Spire.PDF\Demos\Data\ImageWaterMark.pdf"
};
'pdf document list
Dim files As [String]() = New [String]() {"D:\e-iceblue\Spire.PDF\Demos\Data\DigitalSignature.pdf", "D:\e-iceblue\Spire.PDF\Demos\Data\Sample2.pdf", "D:\e-iceblue\Spire.PDF\Demos\Data\ImageWaterMark.pdf"}
Step 2. Open the three PDF files in a new document and import all pages into a new one
//open pdf documents
PdfDocument[] docs = new PdfDocument[files.Length];
for (int i = 0; i < files.Length; i++)
{
docs[i] = new PdfDocument(files[i]);
}
//append document
docs[0].AppendPage(docs[1]);
//import pages
for (int i = 0; i < docs[2].Pages.Count; i = i + 2)
{
docs[0].InsertPage(docs[2], i);
}
'open pdf documents
Dim docs As PdfDocument() = New PdfDocument(files.Length - 1) {}
For i As Integer = 0 To files.Length - 1
docs(i) = New PdfDocument(files(i))
Next
'append document
docs(0).AppendPage(docs(1))
'import pages
Dim i As Integer = 0
While i < docs(2).Pages.Count
docs(0).InsertPage(docs(2), i)
i = i + 2
End While
Step 3. Save and Preview the Merged PDF File
docs[0].SaveToFile("MergeDocuments.pdf");
foreach (PdfDocument doc in docs)
{
doc.Close();
}
PDFDocumentViewer("MergeDocuments.pdf");
docs(0).SaveToFile("MergeDocuments.pdf")
For Each doc As PdfDocument In docs
doc.Close()
Next
PDFDocumentViewer("MergeDocuments.pdf")
Effective Screeshot

Spire.PDF is a PDF document creation component that enables your .NET/Silverlight/WPF applications to read, write and manipulate PDF documents without using Adobe Acrobat.
Digital Certificate, known as identity certificate, is an electronic document that uses a digital signature to bind together a public key with an identity. As long as the PDF digital certificate is created, it demonstrates the authority of a digital document. This section will introduce a solution to create PDF digital certificate for WPF via a WPF PDF component.
Spire.PDF for WPF , a WPF library which can fully control your PDF documents, enables you to create PDF digital certificate in a simple way. First, please see the effect of this digital certificate task as below picture:

Before viewing the code, please Download Spire.PDF for WPF and install it in system.
In this solution, first you need to load your .pfx file from system. Then, create a new instance of Spire.Pdf.Security.PdfCertificate class with two parameters passed, one is the certificate file and the other is the password of the imported .pfx file. After creating a PdfSignature class instance, you can add DocumentPermissions to be AllowComments, AllowFormFill and ForbidChanges.
When you create the PdfSignature class instance, there are four parameters. The parameter "page" enables you to choose which PDF page you decide to sign the digital certificate.
String pfxPath = @"..\Data\Demo.pfx"; PdfCertificate cert = new PdfCertificate(pfxPath, "e-iceblue"); PdfSignature signature = new PdfSignature(doc, page, cert, "demo"); signature.ContactInfo = "Harry Hu"; signature.Certificated = true; signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill;
Dim pfxPath As String = "..\Data\Demo.pfx" Dim cert As New PdfCertificate(pfxPath, "e-iceblue") Dim signature As New PdfSignature(doc, page, cert, "demo") signature.ContactInfo = "Harry Hu" signature.Certificated = True signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill
Spire.PDF for WPF enables your WPF applications to read, write and manipulate PDF documents without using Adobe Acrobat or any third party component library, click to know more about this WPF PDF component.