How to Ungroup Excel Cells in C#

2014-01-15 08:08:50 Written by Administrator

Group the Excel cells is to tie a range of cells together so that they can be collapsed or expanded. But usually, we also need to ungroup the Excel cells. Consequently, the articles aims at introducing how to ungroup Excel cells in C#, through a professional Excel .NET Component Spire.Xls.

Just as its name implies, ungroup Excel cells is to ungroup a range of cells that were previously grouped. Before ungroup Excel cells, we should complete the preparatory work:

  • Download the Spire.XLS and install it on your machine.
  • Add the Spire.XLS.dll files as reference.
  • Open bin folder and select the three dll files under .NET 4.0.
  • Right click property and select properties in its menu.
  • Set the target framework as .NET 4.
  • Add Spire.XLS as namespace.

Then here comes to the explanation of the code:

Step 1: Create an instance of Spire.XLS.Workbook.

[C#]
Workbook workbook = new Workbook();

Step 2: Load the file base on a specified file path.

[C#]
workbook.LoadFromFile(@"group.xlsx");

Step 3: Get the first worksheet.

[C#]
Worksheet sheet = workbook.Worksheets[0];

Step 4: Ungroup the first 5 row cells.

[C#]
sheet.UngroupByRows(1, 5);

Step 5: Save as the generated file.

[C#]
workbook.SaveToFile(@"result.xlsx", ExcelVersion.Version2010);

Full code:

[C#]
using Spire.Xls;
namespace UngroupCell
{
    class Program
    {

        static void Main(string[] args)
        {

            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"group.xlsx");
            Worksheet sheet = workbook.Worksheets[0];
            sheet.UngroupByRows(1, 5);
            workbook.SaveToFile(@"..\..\result.xlsx", ExcelVersion.Version2010);

        }
    }
}

Please preview the original group effect screenshot:

group excel cells

And the generated ungroup effect screenshot:

ungroup excel cells

Apply PDF Page Transitions in C#

2014-01-15 02:49:26 Written by Administrator

Page transitions display a decorative effect such as a dissolve or wipe when you’re turning pages in a document that is exported to PDF format. Page transitions are especially useful when you create a slideshow in PDF format. And Spire.PDF, a powerful .NET component specially designed for developers enables you to apply page transitions to PDF file.

A solution is introduced here to show how to apply page transitions to PDF using Spire.PDF. Spire.PDF provides you a class called PdfSection. PdfSection has a property called PageSettings. And PageSettings has a property called Transition. You can use this property to apply page transitions.

Step 1: Create a new section.

PdfSection section = doc.Sections.Add();
section.PageSettings.Size = PdfPageSize.A4;

Step 2: Create a new PdfPageTransition instance.

section.PageSettings.Transition = new PdfPageTransition();

Step 3: Set the style of page transition.

section.PageSettings.Transition.Style = PdfTransitionStyle.Fade;

You can assign any value that is defined in PdfTransitionStyle to Style.

Step 4: Set the duration of transition effect in seconds.

section.PageSettings.Transition.Duration = 3;

Step 5: Set the page's display duration.

section.PageSettings.Transition.PageDuration = 2;

Step 6: Add more sections and apply more page transitions.

section = doc.Sections.Add();
section.PageSettings.Size = PdfPageSize.A4;
section.PageSettings.Transition = new PdfPageTransition();
section.PageSettings.Transition.Style = PdfTransitionStyle.Box;
section.PageSettings.Transition.Motion = PdfTransitionMotion.Outward;
section.PageSettings.Transition.Duration = 3;
section.PageSettings.Transition.PageDuration = 2;

You can combine the type of PdfPageTransition with the property Direction and the property Dimension of PdfPageTransition to create new and flexible page transition. For example, in this step, the Style of page transition is PdfTransitionStyle.Box and the Motion of page transition is PdfTransitionMotion.Outward.

At last, save the file.

doc.SaveToFile("result.pdf");

To see page transitions in the PDF, open the PDF file in Full Screen.

pdf page transition

pdf page transition

pdf page transition

Here comes to the full code:

using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;


namespace PageTransitions
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument doc = new PdfDocument();

            PdfSection section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Transition = new PdfPageTransition();
            section.PageSettings.Transition.Style = PdfTransitionStyle.Fade;
            section.PageSettings.Transition.Duration = 3;
            section.PageSettings.Transition.PageDuration = 2;

            PdfNewPage page = section.Pages.Add();
            page.BackgroundColor = Color.Blue;
            page.Canvas.DrawString("This is Page One.", new PdfFont(PdfFontFamily.Helvetica, 20f), new PdfSolidBrush(Color.Black), 10, 10);

            page = section.Pages.Add();
            page.BackgroundColor = Color.Green;
            page.Canvas.DrawString("This is Page Two.", new PdfFont(PdfFontFamily.Helvetica, 20f), new PdfSolidBrush(Color.Black), 10, 10);

            section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Transition = new PdfPageTransition();
            section.PageSettings.Transition.Style = PdfTransitionStyle.Box;
            section.PageSettings.Transition.Motion = PdfTransitionMotion.Outward;
            section.PageSettings.Transition.Duration = 3;
            section.PageSettings.Transition.PageDuration = 2;

            page = section.Pages.Add();
            page.BackgroundColor = Color.Orange;
            page.Canvas.DrawString("This is Page Three.", new PdfFont(PdfFontFamily.Helvetica, 20f), new PdfSolidBrush(Color.Black), 10, 10);

            page = section.Pages.Add();
            page.BackgroundColor = Color.Brown;
            page.Canvas.DrawString("This is Page Four.", new PdfFont(PdfFontFamily.Helvetica, 20f), new PdfSolidBrush(Color.Black), 10, 10);

            section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Transition = new PdfPageTransition();
            section.PageSettings.Transition.Duration = 3;
            section.PageSettings.Transition.Style = PdfTransitionStyle.Dissolve;
            section.PageSettings.Transition.PageDuration = 2;

            page = section.Pages.Add();
            page.BackgroundColor = Color.Orange;
            page.Canvas.DrawString("This is Page Five.", new PdfFont(PdfFontFamily.Helvetica, 20f), new PdfSolidBrush(Color.Black), 10, 10);

            page = section.Pages.Add();
            page.BackgroundColor = Color.Navy;
            page.Canvas.DrawString("This is Page Six.", new PdfFont(PdfFontFamily.Helvetica, 20f), new PdfSolidBrush(Color.Black), 10, 10);

            doc.SaveToFile("result.pdf");
            doc.Close();
        }
    }
}

Watermark is a recognizable text or image that appears under document text. A watermark is useful in the examination of paper because it can be widely used for trademarks, locations and so on. This article aims at introducing how to add PDF text watermark for WPF through a simple WPF PDF API Spire.PDF for WPF. Also it can implement PDF watermark by image.

First we need to complete the preparatory work:

  • Download the latest Spire.PDF and install it on your machine.
  • Add the Spire.PDF.WPF.dll files as reference.
  • Open bin folder and select the three dll files under .NET 4.0.
  • Right click property and select properties in its menu.
  • Set the target framework as .NET 4.
  • Add Spire.PDF as namespace.

Here comes to the explanation of the code.

Step 1: Create an instance of Spire.PDF.Document

[C#]
PdfDocument doc = new PdfDocument();

Step 2: Load the file base on a specified file path

[C#]
doc.LoadFromFile(@"..\..\Sample1.pdf");

Step 3: Add the text watermark to the first page

[C#]
PdfPageBase page = doc.Pages[0];
PdfTilingBrush brush = new PdfTilingBrush(new SizeF(page.Canvas.ClientSize.Width/2, page.Canvas.ClientSize.Height/3));
brush.Graphics.SetTransparency(0.3f);
brush.Graphics.Save();
brush.Graphics.TranslateTransform(brush.Size.Width / 2, brush.Size.Height / 2);
brush.Graphics.RotateTransform(-45);
brush.Graphics.DrawString("Spire.Pdf Demo",new PdfFont(PdfFontFamily.Helvetica, 24), PdfBrushes.Violet, 0, 0,new PdfStringFormat(PdfTextAlignment.Center));
brush.Graphics.Restore();
brush.Graphics.SetTransparency(1);
page.Canvas.DrawRectangle(brush, new RectangleF(new PointF(0, 0), page.Canvas.ClientSize));

Step 4: Save the PDF file

[C#]
doc.SaveToFile("TextWaterMark.pdf");

Full code:

[C#]
private void button1_Click(object sender, RoutedEventArgs e)
 {
  PdfDocument doc = new PdfDocument();
  doc.LoadFromFile(@"..\..\Sample1.pdf");
  PdfPageBase page = doc.Pages[0];
  PdfTilingBrush brush = new PdfTilingBrush(new SizeF(page.Canvas.ClientSize.Width/2, page.Canvas.ClientSize.Height/3));
  brush.Graphics.SetTransparency(0.3f);
  brush.Graphics.Save();
  brush.Graphics.TranslateTransform(brush.Size.Width / 2, brush.Size.Height / 2);
  brush.Graphics.RotateTransform(-45);
  brush.Graphics.DrawString("Spire.Pdf Demo",new PdfFont(PdfFontFamily.Helvetica, 24), PdfBrushes.Violet, 0, 0, new PdfStringFormat(PdfTextAlignment.Center));
  brush.Graphics.Restore();
  brush.Graphics.SetTransparency(1);
  page.Canvas.DrawRectangle(brush, new RectangleF(new PointF(0, 0), page.Canvas.ClientSize));
  doc.SaveToFile("TextWaterMark.pdf");          
 }

Effect screenshot:

add pdf text watermark for wpf

We have already demonstrated how to create form fields in PDF file. This article mainly shows you how developers fill form field in PDF in C# only with 3 simple steps by using a standalone .NET PDF component Spire.PDF.

Make sure Spire.PDF for .NET has been installed correctly and then add Spire.Pdf.dll as reference in the downloaded Bin folder though the below path: "..\Spire.Pdf\Bin\NET4.0\ Spire.Pdf.dll". Here comes to the details of how developers Fill Form Fields by using Spire.PDF:

Step 1: Open the form that needs to fill the data

[C#]
//Create a pdf document
PdfDocument doc = new PdfDocument();
//Load from file
doc.LoadFromFile(@"..\..\FormField.pdf");

Step 2: Update the data to the form

[C#]
//Get form
PdfFormWidget formWidget = doc.Form as PdfFormWidget;
for (int i = 0; i < formWidget.FieldsWidget.List.Count; i++)
            {
                PdfField field = formWidget.FieldsWidget.List[i] as PdfField;


//Fill the data for textBoxField
if (field is PdfTextBoxFieldWidget)
   {
    PdfTextBoxFieldWidget textBoxField = field as PdfTextBoxFieldWidget;
    switch (textBoxField.Name)
     {

     case "email":
        textBoxField.Text = "support@e-iceblue.com";
    break;
     case "password":
        textBoxField.Password = true;
        textBoxField.Text = "e-iceblue";

//Fill the data for listBoxField
if (field is PdfListBoxWidgetFieldWidget)
  {
     PdfListBoxWidgetFieldWidget listBoxField = field as PdfListBoxWidgetFieldWidget;
     switch (listBoxField.Name)
       {

        case "email_format":
         int[] index = { 1 };
         listBoxField.SelectedIndex = index;
         break;


//Fill the data for comBoxField
if (field is PdfComboBoxWidgetFieldWidget)
  {
   PdfComboBoxWidgetFieldWidget comBoxField = field as PdfComboBoxWidgetFieldWidget;
   switch (comBoxField.Name)
    {

     case "title":
       int[] items = { 0 };
       comBoxField.SelectedIndex = items;
       break;


//Fill the data for checkBoxField
if (field is PdfCheckBoxWidgetFieldWidget)
  {
   PdfCheckBoxWidgetFieldWidget checkBoxField = field as PdfCheckBoxWidgetFieldWidget;
   switch (checkBoxField.Name)
    {

    case "agreement_of_terms":
      checkBoxField.Checked = true;
      break;

Step 3: Save and launch file

[C#]
//Save the document to file in PDF format
doc.SaveToFile(@"../../FormFieldData.pdf.pdf");
//Launch the file
System.Diagnostics.Process.Start(@"../../FormFieldData.pdf.pdf");

Effective Screenshot:

The original PDF with form fields:

before fill form fields

After fill the form fields:

after fill form fields

View the full code as below:

C#
using Spire.Pdf;
using Spire.Pdf.Fields;
using Spire.Pdf.Widget;


namespace FillFormFields
{
    class Program
    {
        static void Main(string []args){
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(@"..\..\FormField.pdf");
            PdfFormWidget formWidget = doc.Form as PdfFormWidget;
            for (int i = 0; i < formWidget.FieldsWidget.List.Count; i++)
            {
                PdfField field = formWidget.FieldsWidget.List[i] as PdfField;
                if (field is PdfTextBoxFieldWidget)
                {
                    PdfTextBoxFieldWidget textBoxField = field as PdfTextBoxFieldWidget;
                    switch (textBoxField.Name)
                    {
                        case "email":
                            textBoxField.Text = "support@e-iceblue.com";
                            break;
                        case "username":
                            textBoxField.Text = "E-iceblue";
                            break;
                        case "password":
                            textBoxField.Password = true;
                            textBoxField.Text = "e-iceblue";
                            break;
                        case "password2":
                            textBoxField.Password = true;
                            textBoxField.Text = "e-iceblue";
                            break;
                        case "company_name ":
                            textBoxField.Text = "E-iceblue";
                            break;
                        case "first_name":
                            textBoxField.Text = "James";
                            break;
                        case "last_name":
                            textBoxField.Text = "Chen";
                            break;
                        case "middle_name":
                            textBoxField.Text = "J";
                            break;
                        case "address1":
                            textBoxField.Text = "Chengdu";
                            break;
                        case "address2":
                            textBoxField.Text = "Beijing";
                            break;
                        case "city":
                            textBoxField.Text = "Shanghai";
                            break;
                        case "postal_code":
                            textBoxField.Text = "11111";
                            break;
                        case "state":
                            textBoxField.Text = "Shanghai";
                            break;
                        case "phone":
                            textBoxField.Text = "1234567901";
                            break;
                        case "mobile_phone":
                            textBoxField.Text = "123456789";
                            break;
                        case "fax":
                            textBoxField.Text = "12121212";
                            break;
                    }
                }
                if (field is PdfListBoxWidgetFieldWidget)
                {
                    PdfListBoxWidgetFieldWidget listBoxField = field as PdfListBoxWidgetFieldWidget;
                    switch (listBoxField.Name)
                    {
                        case "email_format":
                            int[] index = { 1 };
                            listBoxField.SelectedIndex = index;
                            break;
                    }
                }

                if (field is PdfComboBoxWidgetFieldWidget)
                {
                    PdfComboBoxWidgetFieldWidget comBoxField = field as PdfComboBoxWidgetFieldWidget;
                    switch (comBoxField.Name)
                    {
                        case "title":
                            int[] items = { 0 };
                            comBoxField.SelectedIndex = items;
                            break;
                    }
                }

                if (field is PdfRadioButtonListFieldWidget)
                {
                    PdfRadioButtonListFieldWidget radioBtnField = field as PdfRadioButtonListFieldWidget;
                    switch (radioBtnField.Name)
                    {
                        case "country":
                            radioBtnField.SelectedIndex = 1;
                            break;
                    }
                }

                if (field is PdfCheckBoxWidgetFieldWidget)
                {
                    PdfCheckBoxWidgetFieldWidget checkBoxField = field as PdfCheckBoxWidgetFieldWidget;
                    switch (checkBoxField.Name)
                    {
                        case "agreement_of_terms":
                            checkBoxField.Checked = true;
                            break;
                    }
                }
                if (field is PdfButtonWidgetFieldWidget)
                {
                    PdfButtonWidgetFieldWidget btnField = field as PdfButtonWidgetFieldWidget;
                    switch (btnField.Name)
                    {
                        case "submit":
                            btnField.Text = "Submit";
                            break;
                    }
                }
            }
            doc.SaveToFile(@"../../FormFieldData.pdf.pdf");
            System.Diagnostics.Process.Start(@"../../FormFieldData.pdf.pdf");
        }
    }
}
VB.NET
Imports Spire.Pdf
Imports Spire.Pdf.Fields
Imports Spire.Pdf.Widget


Namespace FillFormFields
	Class Program
		Private Shared Sub Main(args As String())
			Dim doc As New PdfDocument()
			doc.LoadFromFile("..\..\FormField.pdf")
			Dim formWidget As PdfFormWidget = TryCast(doc.Form, PdfFormWidget)
			For i As Integer = 0 To formWidget.FieldsWidget.List.Count - 1
				Dim field As PdfField = TryCast(formWidget.FieldsWidget.List(i), PdfField)
				If TypeOf field Is PdfTextBoxFieldWidget Then
					Dim textBoxField As PdfTextBoxFieldWidget = TryCast(field, PdfTextBoxFieldWidget)
					Select Case textBoxField.Name
						Case "email"
							textBoxField.Text = "support@e-iceblue.com"
							Exit Select
						Case "username"
							textBoxField.Text = "E-iceblue"
							Exit Select
						Case "password"
							textBoxField.Password = True
							textBoxField.Text = "e-iceblue"
							Exit Select
						Case "password2"
							textBoxField.Password = True
							textBoxField.Text = "e-iceblue"
							Exit Select
						Case "company_name "
							textBoxField.Text = "E-iceblue"
							Exit Select
						Case "first_name"
							textBoxField.Text = "James"
							Exit Select
						Case "last_name"
							textBoxField.Text = "Chen"
							Exit Select
						Case "middle_name"
							textBoxField.Text = "J"
							Exit Select
						Case "address1"
							textBoxField.Text = "Chengdu"
							Exit Select
						Case "address2"
							textBoxField.Text = "Beijing"
							Exit Select
						Case "city"
							textBoxField.Text = "Shanghai"
							Exit Select
						Case "postal_code"
							textBoxField.Text = "11111"
							Exit Select
						Case "state"
							textBoxField.Text = "Shanghai"
							Exit Select
						Case "phone"
							textBoxField.Text = "1234567901"
							Exit Select
						Case "mobile_phone"
							textBoxField.Text = "123456789"
							Exit Select
						Case "fax"
							textBoxField.Text = "12121212"
							Exit Select
					End Select
				End If
				If TypeOf field Is PdfListBoxWidgetFieldWidget Then
					Dim listBoxField As PdfListBoxWidgetFieldWidget = TryCast(field, PdfListBoxWidgetFieldWidget)
					Select Case listBoxField.Name
						Case "email_format"
							Dim index As Integer() = {1}
							listBoxField.SelectedIndex = index
							Exit Select
					End Select
				End If

				If TypeOf field Is PdfComboBoxWidgetFieldWidget Then
					Dim comBoxField As PdfComboBoxWidgetFieldWidget = TryCast(field, PdfComboBoxWidgetFieldWidget)
					Select Case comBoxField.Name
						Case "title"
							Dim items As Integer() = {0}
							comBoxField.SelectedIndex = items
							Exit Select
					End Select
				End If

				If TypeOf field Is PdfRadioButtonListFieldWidget Then
					Dim radioBtnField As PdfRadioButtonListFieldWidget = TryCast(field, PdfRadioButtonListFieldWidget)
					Select Case radioBtnField.Name
						Case "country"
							radioBtnField.SelectedIndex = 1
							Exit Select
					End Select
				End If

				If TypeOf field Is PdfCheckBoxWidgetFieldWidget Then
					Dim checkBoxField As PdfCheckBoxWidgetFieldWidget = TryCast(field, PdfCheckBoxWidgetFieldWidget)
					Select Case checkBoxField.Name
						Case "agreement_of_terms"
							checkBoxField.Checked = True
							Exit Select
					End Select
				End If
				If TypeOf field Is PdfButtonWidgetFieldWidget Then
					Dim btnField As PdfButtonWidgetFieldWidget = TryCast(field, PdfButtonWidgetFieldWidget)
					Select Case btnField.Name
						Case "submit"
							btnField.Text = "Submit"
							Exit Select
					End Select
				End If
			Next
			doc.SaveToFile("../../FormFieldData.pdf.pdf")
			System.Diagnostics.Process.Start("../../FormFieldData.pdf.pdf")
		End Sub
	End Class
End Namespace

Add Action Chain to PDF in C#

2014-01-08 09:11:46 Written by Administrator

PDF supports actions. And Spire.PDF, a very powerful .NET component enables developers to add action chain to PDF file. Action chain means an action get executed automatically after another one.

In this article, a solution is introduced to add action chain to PDF file.

Step 1: Set the action that gets performed right after PDF document is opened

[C#]
String script
                = "app.alert({"
                + "    cMsg: \"I'll lead; you must follow me.\","
                + "    nIcon: 3,"
                + "    cTitle: \"JavaScript Action\""
                + "});";
PdfJavaScriptAction action1 = new PdfJavaScriptAction(script);
document.AfterOpenAction = action1;

Spire.PDF provides you a class called PdfJavaScriptAction that executes JavaScript code. Create a PdfJavaScriptAction instance “action1” using JavaScript code. And set the property AfterOpenAction of “document” to action1.

Step 2: Set the action that gets performed after “action1” using the property Next

[C#]
script
                = "app.alert({"
                + "    cMsg: \"The firt page!\","
                + "    nIcon: 3,"
                + "    cTitle: \"JavaScript Action\""
                + "});";
PdfJavaScriptAction action2 = new PdfJavaScriptAction(script);
action1.Next.Add(action2);

Step 3: Set the action that gets performed after “action2”

[C#]
PdfXYZExplicitDestination dest = new PdfXYZExplicitDestination(pagetwo, 0f, 0f, 1f);
PdfGoToAction action3 = new PdfGoToAction(dest);
action2.Next.Add(action3);

PdfXYZExplicitDestination can mark a specified page or location in PDF. Create a PdfXYZExplicitDestination instance “dest” using “pagetwo”. Then create a PdfGoToAction instance “action3” using “dest”.

Step 4: Set the action that gets performed after “action3”

[C#]
script
                = "app.alert({"
                + "    cMsg: \"Oh sorry, it's the last page. I'm missing!\","
                + "    nIcon: 3,"
                + "    cTitle: \"JavaScript Action\""
                + "});";
PdfJavaScriptAction action4 = new PdfJavaScriptAction(script);
action3.Next.Add(action4);

Step 5: Save the file

[C#]
document.SaveToFile("result.pdf");

Full code:

[C#]
using Spire.Pdf;
using Spire.Pdf.Actions;
using Spire.Pdf.Destinations;
using Spire.Pdf.General;
using Spire.Pdf.Graphics;
using System;
using System.Drawing;


namespace AddActionChain
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument document = new PdfDocument();

            PdfPageBase pageone = document.Pages.Add();
            pageone.Canvas.DrawString("This is Page One.",
                                   new PdfFont(PdfFontFamily.Helvetica, 20f),
                                   new PdfSolidBrush(Color.Black),
                                   10, 10);
            PdfPageBase pagetwo = document.Pages.Add();
            pagetwo.Canvas.DrawString("This is Page Two.",
                                   new PdfFont(PdfFontFamily.Helvetica, 20f),
                                   new PdfSolidBrush(Color.Black),
                                   10, 10);

            String script
                = "app.alert({"
                + "    cMsg: \"I'll lead; you must follow me.\","
                + "    nIcon: 3,"
                + "    cTitle: \"JavaScript Action\""
                + "});";
            PdfJavaScriptAction action1 = new PdfJavaScriptAction(script);
            document.AfterOpenAction = action1;

            script
                = "app.alert({"
                + "    cMsg: \"The first page!\","
                + "    nIcon: 3,"
                + "    cTitle: \"JavaScript Action\""
                + "});";
            PdfJavaScriptAction action2 = new PdfJavaScriptAction(script);
            action1.Next.Add(action2);

            PdfXYZExplicitDestination dest = new PdfXYZExplicitDestination(pagetwo, 0f, 0f, 1f);
            PdfGoToAction action3 = new PdfGoToAction(dest);
            action2.Next.Add(action3);

            script
                = "app.alert({"
                + "    cMsg: \"Oh sorry, it's the last page. I'm missing!\","
                + "    nIcon: 3,"
                + "    cTitle: \"JavaScript Action\""
                + "});";
            PdfJavaScriptAction action4 = new PdfJavaScriptAction(script);
            action3.Next.Add(action4);

            document.SaveToFile("result.pdf");

            System.Diagnostics.Process.Start("result.pdf");
        }
    }
}

Screenshot:

add action chain in pdf

add action chain in pdf

Draw text in PDF document is an important part and it is not easy to finish. With the help of Spire.PDF, a PDF component, you can not only draw text in PDF document easily for .NET and WPF, you can do this job easily for Silverlight.

We have introduced how to draw text for PDF .NET and PDF WPF. This article will give clear information of how to draw text with C# code for Silverlight.

Make sure Spire.PDF (or Spire.Office) has been installed correctly. Add Spire.PDF.dll as reference in the downloaded Bin folder though the below path: "..\Spire.PDF\Bin\Silverlight4\ Spire.PDF.dll".

Here comes to the steps:

Step 1: Create a PDF document and a page

[C#]
//create a pdf document
PdfDocument document = new PdfDocument();
//create one page
PdfPageBase page = document.Pages.Add();

Step 2: Draw Text

[C#]
//Draw Text - alignment
PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 20f);
PdfSolidBrush brush = new PdfSolidBrush(Color.FromArgb(10, 0, 255, 0));

PdfStringFormat leftAlignment = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
page.Canvas.DrawString("Left!", font, brush, 0, 20, leftAlignment);
page.Canvas.DrawString("Left!", font, brush, 0, 50, leftAlignment);

PdfStringFormat rightAlignment = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
page.Canvas.DrawString("Right!", font, brush, page.Canvas.ClientSize.Width, 30, rightAlignment);
page.Canvas.DrawString("Right!", font, brush, page.Canvas.ClientSize.Width, 60, rightAlignment);

PdfStringFormat centerAlignment = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush, page.Canvas.ClientSize.Width / 2, 40, centerAlignment);

//Draw the text - align in rectangle
PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 10f);
PdfSolidBrush brush = new PdfSolidBrush(Color.FromArgb(10, 0, 0, 255));
RectangleF rctg1 = new RectangleF(0, 70, page.Canvas.ClientSize.Width / 2, 100);
RectangleF rctg2 = new RectangleF(page.Canvas.ClientSize.Width / 2, 70, page.Canvas.ClientSize.Width / 2, 100);
page.Canvas.DrawRectangle(new PdfSolidBrush(Color.FromArgb(1, 0, 0, 100)), rctg1);
page.Canvas.DrawRectangle(new PdfSolidBrush(Color.FromArgb(1, 0, 0, 150)), rctg2);

PdfStringFormat leftAlignment = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Top);
page.Canvas.DrawString("Left! Left!", font, brush, rctg1, leftAlignment);
page.Canvas.DrawString("Left! Left!", font, brush, rctg2, leftAlignment);

PdfStringFormat rightAlignment = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
page.Canvas.DrawString("Right! Right!", font, brush, rctg1, rightAlignment);
page.Canvas.DrawString("Right! Right!", font, brush, rctg2, rightAlignment);

PdfStringFormat centerAlignment = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Bottom);
page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush, rctg1, centerAlignment);
page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush, rctg2, centerAlignment);

//Draw text - brush
String text = "Go! Turn Around! Go! Go! Go!";
PdfPen pen = PdfPens.DeepSkyBlue;
PdfSolidBrush brush = new PdfSolidBrush(Color.FromArgb(10, 0, 0, 0));
PdfStringFormat format = new PdfStringFormat();
PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 18f, PdfFontStyle.Italic);
SizeF size = font.MeasureString(text, format);
RectangleF rctg= new RectangleF(page.Canvas.ClientSize.Width / 2 + 10, 180,
size.Width / 3 * 2, size.Height * 2);
page.Canvas.DrawString(text, font, pen, brush, rctg, format);

Step 3: Save the document to stream

[C#]
using (Stream ms = saveFiledialog.OpenFile())
{
    document.SaveToStream(ms);

}

Now check the effective screenshot:

Draw_Text_in_PDF_Document_for_Silverlight.png

Excel Freeze Panes keeps rows and columns visible while the rest of the worksheet scrolls. Likewise, we need to unfreeze Excel panes due to work needs in some cases. This article aims at introducing the solution to unfreeze the Excel top row in c# and VB.NET through a utility Excel .NET library Spire.XLS.

First we need to complete the preparatory work:

  • Download the latest Spire.XLS and install it on your machine.
  • Add the Spire.XLS.dll files as reference.
  • Open bin folder and select the three dll files under .NET 4.0.
  • Right click property and select properties in its menu.
  • Set the target framework as .NET 4.
  • Add Spire.XLS as namespace.

Here comes to the explanation of the C# code:

Step 1: Create an instance of Spire.XLS.Workbook.

Workbook workbook = new Workbook();

Step 2: Load the file base on a specified file path.

workbook.LoadFromFile("sample.xls");

Step 3: Get the first worksheet.

Worksheet sheet = workbook.Worksheets[0];

Step 4: Unfreeze the top row.

sheet.RemovePanes();

Step 5: Save as the generated file.

workbook.SaveToFile("sample.xls",ExcelVersion.Version97to2003);

Please preview the freeze panes effect screenshot:

Excel freeze panes

And the unfreeze panes effect screenshot:

Excel unfreeze panes

Here is the full code in C# and VB.NET:

[C#]
using Spire.Xls;
namespace UnfreezeExcelPane
{
    class Program
    {

        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("Sample.xls");
            Worksheet sheet = workbook.Worksheets[0];
            sheet.RemovePanes();
            workbook.SaveToFile("sample.xls", ExcelVersion.Version97to2003);

        }
    }
}
[VB.NET]
Imports Spire.Xls
Namespace UnfreezeExcelPane
	Class Program

		Private Shared Sub Main(args As String())
			Dim workbook As New Workbook()
			workbook.LoadFromFile("Sample.xls")
			Dim sheet As Worksheet = workbook.Worksheets(0)
			sheet.RemovePanes()
			workbook.SaveToFile("sample.xls", ExcelVersion.Version97to2003)

		End Sub
	End Class
End Namespace

Bookmark can locate a range. Assuming the content of the range is some html code, how to change the content of the range. Spire.Doc supports bookmarks. And you can use Spire.Doc to fulfill the job.

In this article, a solution will be introduced. Spire.Doc provides you a method:

[C#]
public void ReplaceBookmarkContent(TextBodyPart bodyPart)

Replace the content of bookmark with TextBodyPart bodyPart.

This method cannot handle html code directly. Here is what to do. First load the new html code to document. Then select the newly added data as TextBodyPart. At last, call the method to replace the content of the bookmark.

Step 1: Add bookmarks containing html code.

[C#]
Paragraph p2 = section.AddParagraph();
p2.AppendBookmarkStart("bookmark2");
p2.AppendHTML("<p><font color='blue'>This para is also Generated by Decoding HTML Code</font></p>");
p2.AppendBookmarkEnd("bookmark2");

Step 2: Add new html code to document.

[C#]
Section tempSection = document.AddSection();
String html
= "<p>This Bookmark has been <font color=\"#ff0000\">Edited</font></p>";
tempSection.AddParagraph().AppendHTML(html);

Step 3: Get the new added html as TextBodyPart.

[C#]
ParagraphBase replacementFirstItem = tempSection.Paragraphs[0].Items.FirstItem as ParagraphBase;
ParagraphBase replacementLastItem  = tempSection.Paragraphs[tempSection.Paragraphs.Count - 1].Items.LastItem as ParagraphBase;
TextBodySelection selection = new TextBodySelection(replacementFirstItem, replacementLastItem);
TextBodyPart part = new TextBodyPart(selection);

Step 4: Locate the bookmark "bookmark2" and call the method ReplaceBookmarkContent to replace the content. Then remove the temp section.

[C#]
BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
//locate the bookmark
bookmarkNavigator.MoveToBookmark("bookmark2");
//replace the content of bookmark
bookmarkNavigator.ReplaceBookmarkContent(part);
//remove temp section
document.Sections.Remove(tempSection);

Preview the original screenshot:

Edit and replace bookmark with HTML

Preview the effect screenshot:

Edit and replace bookmark with HTML

Here comes to the full code:

[C#]
 using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System;
namespace EditContent
{
    class Program
    {

        static void Main(string[] args)
        {
            Document document = new Document();
            Section section = document.AddSection();

            //create bookmarks
            Paragraph p1 = section.AddParagraph();
            p1.AppendBookmarkStart("bookmark1");
            p1.AppendHTML("<p><span style="color: blue;">This para is also Generated by Decoding HTML Code</span></p>");
            p1.AppendBookmarkEnd("bookmark1");

            Paragraph p2 = section.AddParagraph();
            p2.AppendBookmarkStart("bookmark2");
            p2.AppendHTML("<p><span style="color: blue;">This para is also Generated by Decoding HTML Code</span></p>");
            p2.AppendBookmarkEnd("bookmark2");
            document.SaveToFile("BeforeReplace.doc");

            //create a temp section to contain multiple paragraph.
            Section tempSection = document.AddSection();
            String html = "<p>This Bookmark has been <span>Edited</span></p>";
            tempSection.AddParagraph().AppendHTML(html);

            ParagraphBase replacementFirstItem = tempSection.Paragraphs[0].Items.FirstItem as ParagraphBase;
            ParagraphBase replacementLastItem = tempSection.Paragraphs[tempSection.Paragraphs.Count - 1].Items.LastItem as ParagraphBase;
            TextBodySelection selection = new TextBodySelection(replacementFirstItem, replacementLastItem);
            TextBodyPart part = new TextBodyPart(selection);

            BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
            //locate the bookmark
            bookmarkNavigator.MoveToBookmark("bookmark2");
            //replace the content of bookmark
            bookmarkNavigator.ReplaceBookmarkContent(part);
            //remove temp section
            document.Sections.Remove(tempSection);

            document.SaveToFile(@"AfterReplace.doc");

        }
    }
}

Sometimes we need to insert a symbol or special character in the paragraph. The article is introducing the solution to insert a symbol in Word with c# code. We will use Ä and Ë as the symbol examples to complete the process, with the help of a Word .NET API called Spire.Doc.

First we need to complete the preparatory work:

  • Download the latest Spire.Doc and install it on your machine.
  • Add the Spire.Doc.dll files as reference.
  • Open bin folder and select the three dll files under .NET 4.0.
  • Right click property and select properties in its menu.
  • Set the target framework as .NET 4.
  • Add Spire.Doc as namespace.

Here comes to the explanation of the code.

Step 1: Create an instance of Spire.Doc.Document.

[C#]
Document document = new Document();

Step 2: Add a section.

[C#]
Section section = document.AddSection();

Step 3: Add a paragraph.

[C#]
Paragraph paragraph = section.AddParagraph();

Step 4: Use unicode characters to create symbol Ä.

[C#]
TextRange tr = paragraph.AppendText('\u00c4'.ToString());

In fact, the following step5 and step6 are just the option according to your requirement.

Step 5: Set the color of symbol Ä.

[C#]
tr.CharacterFormat.TextColor = Color.Red;

Step 6: Add symbol Ë.

[C#]
paragraph.AppendText('\u00cb'.ToString());

Step 7: Save to Word file.

[C#]
document.SaveToFile("sample.docx", FileFormat.Docx);

Here is the full code:

[C#]
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace InsertSymbol
{

    class Program
    {
        static void Main(string[] args)
        {
            Document document = new Document();
            Section section = document.AddSection();
            Paragraph paragraph = section.AddParagraph();
            TextRange tr = paragraph.AppendText('\u00c4'.ToString());
            tr.CharacterFormat.TextColor = Color.Red;
            paragraph.AppendText('\u00cb'.ToString());
            document.SaveToFile("sample.docx", FileFormat.Docx);
        }

    }
}

Preview the effect screenshot:

insert symbol in word

C# Digitally Signing PDF Files

Digital signatures provide authenticity, integrity, and non-repudiation for PDF documents, making them essential for legal contracts, financial documents, and other sensitive materials. In this comprehensive tutorial, we'll explore how to digitally sign PDFs in C# using the powerful Spire.PDF for .NET library. We'll cover basic signing, custom appearances, timestamps, and signature fields with detailed code explanations.

Table of Contents:

.NET Library for Adding Digital Signatures to PDF

Spire.PDF for .NET is a robust library that enables developers to create, read, edit, and convert PDF documents programmatically. For digital signatures, it provides comprehensive support through key classes in the Spire.Pdf.Interactive.DigitalSignatures namespace:

  • PdfOrdinarySignatureMaker : The primary class for creating standard PDF signatures
  • PdfSignature : Represents a digital signature in a PDF document
  • PdfSignatureAppearance : Controls the visual representation of the signature
  • PdfPKCS7Formatter : Handles cryptographic formatting including timestamps
  • PdfSignatureField : Represents a signature field in an interactive PDF form

Before implementing any signature functionality, ensure you have:

  • Spire.PDF for .NET installed via NuGet
  • A valid digital certificate (PFX file) with private key access
  • Proper permissions to sign documents

How to Digitally Sign PDFs in C#

  • Step 1. Install Spire.PDF for .NET.
  • Step 2. Use PdfDocument to load the PDF file.
  • Step 3. Load the digital certificate file using X509Certificate2.
  • Step 4. Use PdfOrdinarySignatureMaker to create and apply the digital signature.
  • Step 5. Save the signed PDF with the embedded signature.

Digitally Sign a PDF with a Certificate

To sign a PDF, you need a digital certificate, usually in PFX format. This certificate serves to verify the identity of the signer. Below is a code snippet demonstrating how to sign a PDF using a digital certificate.

Code Example:

using Spire.Pdf;
using Spire.Pdf.Interactive.DigitalSignatures;
using System.Security.Cryptography.X509Certificates;

namespace DigitallySignPdf
{
    class Program
    {
        static void Main(string[] args) 
        {
            // Create a PdfDocument object to work with PDF files
            PdfDocument doc = new PdfDocument();

            // Load an existing PDF file from the specified path
            doc.LoadFromFile("C:/Users/Administrator/Desktop/Input.pdf");

            // Specify the path to the PFX certificate and its password
            string filePath = "C:/Users/Administrator/Desktop/certificate.pfx";
            string password = "e-iceblue";

            // Load the X.509 certificate from the PFX file
            X509Certificate2 x509 = new X509Certificate2(filePath, password,
                X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.EphemeralKeySet);

            // Create a PdfOrdinarySignatureMaker to handle the signature process using the loaded certificate
            PdfOrdinarySignatureMaker signatureMaker = new PdfOrdinarySignatureMaker(doc, x509);

            // Create the signature on the PDF document with a specified signature name
            signatureMaker.MakeSignature("signature 1");

            // Save the signed PDF to a new file
            doc.SaveToFile("Signed.pdf");

            // Release resources
            doc.Dispose();
        }
    }
}

Key Components Explained:

  1. PdfDocument : The central class representing the PDF document. It provides methods for loading, manipulating, and saving PDF files.
  2. X509Certificate2 : The .NET class for handling digital certificates. The key storage flags are crucial:
    • MachineKeySet: Stores keys in the machine-level key store
    • EphemeralKeySet: Prevents key persistence in memory for better security
  3. PdfOrdinarySignatureMaker : The workhorse for digital signatures. It:
    • Manages the signing process
    • Handles cryptographic operations
    • Embeds the signature in the PDF
  4. MakeSignature() : The method that actually applies the signature. The string parameter names the signature, which must be unique within the document.

This basic implementation creates an invisible digital signature. The signature validates the document's integrity but doesn't provide a visual representation.

Output:

An invisible digital signature in PDF.

Customize PDF Signature Appearance

A digital signature can be customized to include additional information such as the signer's name, contact info, and even a visual signature image. This enhances the visual appeal and informational value of the signature.

Code Example:

using Spire.Pdf;
using Spire.Pdf.Graphics;
using Spire.Pdf.Interactive.DigitalSignatures;
using System.Security.Cryptography.X509Certificates;

namespace CustomSignatureAppearance
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a PdfDocument object to work with PDF files
            PdfDocument doc = new PdfDocument();

            // Load an existing PDF file from the specified path
            doc.LoadFromFile("C:/Users/Administrator/Desktop/Input.pdf");

            // Specify the path to the PFX certificate and its password
            string filePath = "C:/Users/Administrator/Desktop/certificate.pfx";
            string password = "e-iceblue";

            // Load the X.509 certificate from the PFX file
            X509Certificate2 x509 = new X509Certificate2(filePath, password,
                X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.EphemeralKeySet);

            // Create a PdfOrdinarySignatureMaker to handle the signature process using the loaded certificate
            PdfOrdinarySignatureMaker signatureMaker = new PdfOrdinarySignatureMaker(doc, x509);

            // Get the signature
            PdfSignature signature = signatureMaker.Signature;

            // Configure the signature properties like the signer's name, contact information, location, and sign reason
            signature.Name = "Gary";
            signature.ContactInfo = "726349";
            signature.Location = "U.S.";
            signature.Reason = "This is the final version.";

            // Create a signature appearance
            PdfSignatureAppearance appearance = new PdfSignatureAppearance(signature);

            // Set labels for the signature
            appearance.NameLabel = "Signer: ";
            appearance.ContactInfoLabel = "Phone: ";
            appearance.LocationLabel = "Location: ";
            appearance.ReasonLabel = "Reason: ";

            // Load an image
            PdfImage image = PdfImage.FromFile("C:/Users/Administrator/Desktop/signature.png");

            // Set the image as the signature image
            appearance.SignatureImage = image;

            // Set the graphic mode as SignImageAndSignDetail
            appearance.GraphicMode = GraphicMode.SignImageAndSignDetail;

            // Get the last page
            PdfPageBase page = doc.Pages[doc.Pages.Count - 1];

            // Add the signature to a specified location of the page
            signatureMaker.MakeSignature("signature 1", page, 54.0f,  330.0f, 280.0f, 90.0f, appearance);

            // Save the signed PDF to a new file
            doc.SaveToFile("Signed.pdf");

            // Release resources
            doc.Dispose();
        }
    }
}

Key Features Explained:

  1. PdfSignature Metadata :

    • Name: Identifies the signer
    • ContactInfo: Provides contact details
    • Location: Geographical signing location
    • Reason: Purpose of signing
  2. PdfSignatureAppearance : Controls visual elements:

    • Label customization for metadata fieldsŸ
    • Image integration via SignatureImage property
    • Layout controlthrough GraphicMode (options: SignImageOnly, SignDetailOnly, SignImageAndSignDetail)
  3. Precise Placement : The extended MakeSignature overload allows specifying:

    • Target page
    • X/Y coordinates
    • Width/Height dimensions

Output:

A visible digital signature with custom appearance in PDF.

To enhance the visibility and trustworthiness of your digitally signed PDF when opened in Adobe Reader, you can enable a validation indicator by applying the following method:

signatureMaker.SetAcro6Layers(false);

Digital signature with a validation indicator.

Add a Timestamp to PDF Digital Signature

Timestamping a digital signature adds an additional layer of security by proving when the document was signed. This is particularly important for long-term validity.

Code Example:

using Spire.Pdf;
using Spire.Pdf.Interactive.DigitalSignatures;
using Spire.Pdf.Security;
using System.Security.Cryptography.X509Certificates;

namespace SignPdfWithTimestamp
{
    class Program
    {
        static void Main(string[] args)
        {
            // Load PDF document
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile("C:/Users/Administrator/Desktop/Input.pdf");

            // Specify the path to the PFX certificate and its password
            string filePath = "C:/Users/Administrator/Desktop/certificate.pfx";
            string password = "e-iceblue";

            // Load the X.509 certificate from the PFX file
            X509Certificate2 x509 = new X509Certificate2(filePath, password,
                X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.EphemeralKeySet);

            // Initialize PDFPKCS#7Formatter
            PdfPKCS7Formatter formatter = new PdfPKCS7Formatter(x509, false);

            // Set the timestamp service to a public timestamp server
            formatter.TimestampService = new TSAHttpService("http://tsa.cesnet.cz:3161/tsa");

            // Initialize OCSP service for online certificate status checking
            formatter.OCSPService = new OCSPHttpService(null);

            // Apply signature
            PdfOrdinarySignatureMaker signatureMaker = new PdfOrdinarySignatureMaker(doc, formatter);
            signatureMaker.MakeSignature("signature 1");

            // Save and cleanup
            doc.SaveToFile("SignWithTimeStamp.pdf");
            doc.Dispose();
        }
    }
}

Timestamp Implementation Details:

  1. PdfPKCS7Formatter : Enhances basic signing with:
    • Timestamp support
    • OCSP revocation checking
    • Advanced cryptographic formatting
  2. TSAHttpService : Connects to a Time Stamp Authority (TSA) server. Public TSAs include:
    • http://timestamp.digicert.com
    • http://tsa.cesnet.cz:3161/tsa
    • http://timestamp.sectigo.com
  3. OCSPHttpService : Optional Online Certificate Status Protocol service for real-time certificate validity checking.

Output:

PDF digital signature with an embedded timestamp.

Create a Signable Signature Field in PDF

Digital signature fields allow users to sign PDF documents interactively. This is essential for forms that require user signatures.

Code Example:

using System.Drawing;
using Spire.Pdf;
using Spire.Pdf.Fields;
using Spire.Pdf.Graphics;

namespace AddDigitalSignatureFiled
{
    class Program
    {
        static void Main(string[] args)
        {
            // Initialize a new PdfDocument object
            PdfDocument doc = new PdfDocument();

            // Load the existing PDF from the specified path
            doc.LoadFromFile("C:/Users/Administrator/Desktop/Input.pdf");

            // Retrieve the last page of the document
            PdfPageBase page = doc.Pages[doc.Pages.Count - 1];

            // Create a signature field on the specified page
            PdfSignatureField signatureField = new PdfSignatureField(page, "signature");

            // Customize the appearance of the signature field
            signatureField.BorderWidth = 1.0f;
            signatureField.BorderStyle = PdfBorderStyle.Solid;
            signatureField.BorderColor = new PdfRGBColor(System.Drawing.Color.Black);
            signatureField.HighlightMode = PdfHighlightMode.Outline;
            signatureField.Bounds = new RectangleF(54.0f, 350.0f, 200.0f, 100.0f);

            // Enable form creation if none exists in the document
            doc.AllowCreateForm = (doc.Form == null);

            // Add the signature field to the document's form
            doc.Form.Fields.Add(signatureField);

            // Save the modified document to a new file
            doc.SaveToFile("SignatureField.pdf", FileFormat.PDF);
            doc.Dispose();
        }
    }
}

Signature Field Features:

  1. PdfSignatureField : Represents a signable field in a PDF form with properties for:
    • Visual styling (border, color)
    • Positioning and sizing
    • Interaction behavior
  2. Form Handling : The code automatically handles PDF form creation if none exists.
  3. Deferred Signing : Fields can be added now and signed later by end-users or additional processes.

Output:

Unsigned signature field.

Conclusion

Digitally signing PDFs with C# using Spire.PDF provides a robust solution for document authentication. Throughout this tutorial, we've explored:

  1. Basic certificate-based signing
  2. Custom signature appearances with images and metadata
  3. Timestamp integration for long-term validation
  4. Signature fields for form-based workflows

By implementing these techniques, you can enhance document security, compliance, and user trust in your applications. Whether for contracts, legal documents, or internal approvals, Spire.PDF simplifies end-to-end digital signing while maintaining industry standards.

FAQs

Q1: How do I verify a digitally signed PDF?

Spire.PDF provides verification capabilities through the PdfSignature class. You can check the VerifySignature method to validate signatures programmatically. For detailed guide, refer to: Verify Digital Signature in PDF with C#.

Q2: What certificate formats are supported?

Spire.PDF works with standard X.509 certificates, typically in PFX/P12 format for signing as they contain both public and private keys.

Q3: Can I add multiple signatures to a PDF?

Yes, you can add multiple signatures either by creating multiple signature fields or by incrementally signing the document.

Q4: How do I handle certificate expiration?

Using timestamps ensures signatures remain valid after certificate expiration. For long-term validation, consider using LTV (Long-Term Validation) enabled signatures.

Q5: Does Spire.PDF offer additional security options beyond digital signatures?

Yes, Spire.PDF allows you to password-protect your PDF documents and set specific document permissions. These features can be used alongside digital signatures to further enhance security.

Get a Free License

To fully experience the capabilities of Spire.PDF for .NET without any evaluation limitations, you can request a free 30-day trial license.

page 66