.NET (1317)
Children categories
Spire.PDF allows getting and verifying a specific signature in a PDF file, now starts from version 3.8.82, Spire.PDF supports to get all certificates in a PDF signature. In this article, we will show you the steps of how to achieve this task by using Spire.PDF.
For demonstration, we used a template PDF file which contains two certificates:

Code snippets:
Step 1: Instantiate a PdfDocument object and load the PDF file.
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("UPS.pdf");
Step 2: Create a List object.
List<PdfSignature> signatures = new List<PdfSignature>();
Step 3: Get all signatures from the PDF file and add them into the list object.
var form = (PdfFormWidget)doc.Form;
for (int i = 0; i < form.FieldsWidget.Count; ++i)
{
var field = form.FieldsWidget[i] as PdfSignatureFieldWidget;
if (field != null && field.Signature != null)
{
PdfSignature signature = field.Signature;
signatures.Add(signature);
}
}
Step 4: Get the first signature from the list, and then get all the certificates from the signature.
PdfSignature signatureOne = signatures[0]; X509Certificate2Collection collection = signatureOne.Certificates;
Effective screenshot:

Full code:
using System;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using Spire.Pdf;
using Spire.Pdf.Security;
using Spire.Pdf.Widget;
namespace Get_all_certificates_in_PDF_signature
{
class Program
{
static void Main(string[] args)
{
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("UPS.pdf");
List<PdfSignature> signatures = new List<PdfSignature>();
var form = (PdfFormWidget)doc.Form;
for (int i = 0; i < form.FieldsWidget.Count; ++i)
{
var field = form.FieldsWidget[i] as PdfSignatureFieldWidget;
if (field != null && field.Signature != null)
{
PdfSignature signature = field.Signature;
signatures.Add(signature);
}
}
PdfSignature signatureOne = signatures[0];
X509Certificate2Collection collection = signatureOne.Certificates;
foreach (var certificate in collection)
{
Console.WriteLine(certificate.Subject);
}
Console.ReadKey();
}
}
}
How to set horizontal alignment for the text in table on presentation slides
2016-11-30 01:21:13 Written by KoohjiWith the help of Spire.Presentation, developers can set the horizontal alignment for the text on presentation slides easily. This article will focus on show you how to set the horizontal alignment for the text on the table of the presentation slides in C#. There are five options for the text alignment on the Spire.Presentation: Left, Right, Center, Justify and None.
At first, please check a document with default alignment (Left) prepared. Then, different alignment styles will be applied for the different rows on the table.

Step 1: Create a presentation document and load the sample document from file.
Presentation presentation = new Presentation();
presentation.LoadFromFile("Sample.pptx",FileFormat.Pptx2010);
Step 2: Get the table from the sample document.
ITable table = null;
foreach (IShape shape in presentation.Slides[0].Shapes)
{
if (shape is ITable)
{
table = (ITable)shape;
Step 3: Align text horizontally.
for (int i = 0; i < table.ColumnsList.Count; i++)
{
table[i, 0].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Right;
table[i, 1].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Center;
table[i, 2].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Left;
table[i, 3].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.None;
table[i, 4].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Justify;
}
Step 4: Save the document to file.
presentation.SaveToFile("tableresult.pptx", FileFormat.Pptx2010);
Effective screenshot after apply the horizontal alignment for the text on table:

Full codes of how to set horizontal alignment for the text on the presentation slide's table:
using Spire.Presentation;
namespace set_horizontal_alignment
{
class Program
{
static void Main(string[] args)
{
Presentation presentation = new Presentation();
presentation.LoadFromFile("Sample.pptx", FileFormat.Pptx2010);
ITable table = null;
foreach (IShape shape in presentation.Slides[0].Shapes)
{
if (shape is ITable)
{
table = (ITable)shape;
for (int i = 0; i < table.ColumnsList.Count; i++)
{
table[i, 0].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Right;
table[i, 1].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Center;
table[i, 2].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Left;
table[i, 3].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.None;
table[i, 4].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Justify;
}
}
}
presentation.SaveToFile("tableresult.pptx", FileFormat.Pptx2010);
}
}
}
How to keep high quality image when convert XPS to PDF in C#
2016-11-24 08:27:52 Written by AdministratorWe have already had an article of showing how to convert the XPS files into PDF file. Starts from Spire.PDF V3.8.68, it newly supports to keep the high quality image on the resulted PDF file from the XPS document. Spire.PDF offers a property of pdf.UseHighQualityImage to set the image quality before loading the original XPS file. This article will focus on demonstrate how to save image with high quality for the conversion from XPS to PDF.
Here comes to the code snippets:
Step 1: Create a PDF instance.
PdfDocument pdf = new PdfDocument();
Step 2: Set the value of UseHighQualityImage as true to use the high quality image when convert XPS to PDF.
pdf.ConvertOptions.SetXpsToPdfOptions(true);
Step 3: Load the XPS document by use either the method of pdf.LoadFromFile() or pdf.LoadFromXPS().
pdf.LoadFromFile("Sample.xps",FileFormat.XPS);
Step 4: Save the document to file.
pdf.SaveToFile("result.pdf");
Effective screenshot of the high quality image after saving XPS as PDF file format:

Full codes:
using Spire.Pdf;
namespace ConvertXPStoPDF
{
class Program
{
static void Main(string[] args)
{
PdfDocument pdf = new PdfDocument();
pdf.ConvertOptions.SetXpsToPdfOptions(true);
pdf.LoadFromFile("Sample.xps", FileFormat.XPS);
//pdf.LoadFromXPS("Sample.xps");
pdf.SaveToFile("result.pdf", FileFormat.PDF);
}
}
}
Spire.XLS enables developers to change the color of data series in an Excel chart with just a few lines of code. Once changed, the legend color will also turn into the same as the color you set to the series.
The following part demonstrates the steps of how to accomplish this task. Below picture shows the original colors of the data series in an Excel chart:

Code snippets:
Step 1: Instantiate a Workbook object and load the Excel workbook.
Workbook book = new Workbook();
book.LoadFromFile("Sample.xlsx");
Step 2: Get the first worksheet.
Worksheet sheet = book.Worksheets[0];
Step 3: Get the second series of the chart.
ChartSerie cs = sheet.Charts[0].Series[1];
Step 4: Change the color of the second series to Purple.
cs.Format.Fill.FillType = ShapeFillType.SolidColor; cs.Format.Fill.ForeColor = Color.FromKnownColor(KnownColor.Purple);
Step 5: Save the Excel workbook to file.
book.SaveToFile("ChangeSeriesColor.xlsx", ExcelVersion.Version2010);
After running the code, the color of the second series has been changed into Purple, screenshot as shown below.

Full code:
using System.Drawing;
using Spire.Xls;
using Spire.Xls.Charts;
namespace Change_Series_Color
{
class Program
{
static void Main(string[] args)
{
Workbook book = new Workbook();
book.LoadFromFile("Sample.xlsx");
Worksheet sheet = book.Worksheets[0];
ChartSerie cs = sheet.Charts[0].Series[1];
cs.Format.Fill.FillType = ShapeFillType.SolidColor;
cs.Format.Fill.ForeColor = Color.FromKnownColor(KnownColor.Purple);
book.SaveToFile("ChangeSeriesColor.xlsx", ExcelVersion.Version2010);
}
}
}
Imports System.Drawing
Imports Spire.Xls
Imports Spire.Xls.Charts
Namespace Change_Series_Color
Class Program
Private Shared Sub Main(args As String())
Dim book As New Workbook()
book.LoadFromFile("Sample.xlsx")
Dim sheet As Worksheet = book.Worksheets(0)
Dim cs As ChartSerie = sheet.Charts(0).Series(1)
cs.Format.Fill.FillType = ShapeFillType.SolidColor
cs.Format.Fill.ForeColor = Color.FromKnownColor(KnownColor.Purple)
book.SaveToFile("ChangeSeriesColor.xlsx", ExcelVersion.Version2010)
End Sub
End Class
End Namespace
How to set the presentation show type as kiosk (full screen) in C#, VB.NET
2016-11-18 08:30:18 Written by KoohjiBrowsed at a kiosk (full screen) is one kind of the slide show types in PowerPoint, if users choose this option, the Slide Show is full screen but they cannot navigate from slide to slide, for example, move to the next or previous slides.
The following part will demonstrate how to set the presentation show type as kiosk in C# and VB.NET using Spire.Presentation.
Detail steps:
Step 1: Instantiate a Presentation object and load the PPT file.
Presentation presentation = new Presentation();
presentation.LoadFromFile("Sample.pptx");
Step 2: Specify the presentation show type as kiosk.
presentation.ShowType = SlideShowType.Kiosk;
Step 3: Save the file.
presentation.SaveToFile("Result.pptx", FileFormat.Pptx2013);
Output:

Full code:
using Spire.Presentation;
namespace Set_Presentation_show_type_as_ kiosk
{
class Program
{
static void Main(string[] args)
{
Presentation presentation = new Presentation();
presentation.LoadFromFile("Sample.pptx");
presentation.ShowType = SlideShowType.Kiosk;
presentation.SaveToFile("Result.pptx", FileFormat.Pptx2013);
}
}
}
Imports Spire.Presentation
Namespace Set_Presentation_show_type_as_ kiosk
Class Program
Private Shared Sub Main(args As String())
Dim presentation As New Presentation()
presentation.LoadFromFile("Sample.pptx")
presentation.ShowType = SlideShowType.Kiosk
presentation.SaveToFile("Result.pptx", FileFormat.Pptx2013)
End Sub
End Class
End Namespace
Working with Tick-mark Labels on the Category Axis in C#, VB.NET
2016-11-16 08:24:51 Written by KoohjiIn charts, each category on the category axis is identified by a tick-mark label and separated from other categories by tick marks. The tick-mark label text comes from the name of the associated category and is usually placed next to the axis.
In this article, we will introduce how we can custom the tick-mark labels by changing the labels' position, rotating labels and specifying interval between labels in C#, VB.ENT.

Figure 1 – Chart in Example File
To facilitate the introduction, we prepared a PowerPoint document that contains a column chart looks like the screenshot in Figure 1 and used below code to get the chart from the PowerPoint slide. Then we're able to custom the labels through the following ways.
Presentation ppt = new Presentation(@"C:\Users\Administrator\Desktop\ColumnChart.pptx",FileFormat.Pptx2013); IChart chart = ppt.Slides[0].Shapes[0] as IChart;
Rotate tick labels
chart.PrimaryCategoryAxis.TextRotationAngle = 45;

Specify interval between labels
To change the number of unlabeled tick marks, we must set IsAutomaticTickLabelSpacing property as false and change the TickLabelSpacing property to any number between 1 - 255.
chart.PrimaryCategoryAxis.IsAutomaticTickLabelSpacing = false; chart.PrimaryCategoryAxis.TickLabelSpacing = 2;

Change tick labels' position
chart.PrimaryCategoryAxis.TickLabelPosition = TickLabelPositionType.TickLabelPositionHigh;

Full Code:
using Spire.Presentation;
using Spire.Presentation.Charts;
namespace TickMarkLabel
{
class Program
{
static void Main(string[] args)
{
Presentation ppt = new Presentation(@"C:\Users\Administrator\Desktop\ColumnChart.pptx", FileFormat.Pptx2013);
IChart chart = ppt.Slides[0].Shapes[0] as IChart;
//rotate tick labels
chart.PrimaryCategoryAxis.TextRotationAngle = 45;
//specify interval between labels
chart.PrimaryCategoryAxis.IsAutomaticTickLabelSpacing = false;
chart.PrimaryCategoryAxis.TickLabelSpacing = 2;
////change position
//chart.PrimaryCategoryAxis.TickLabelPosition = TickLabelPositionType.TickLabelPositionHigh;
ppt.SaveToFile("result.pptx", FileFormat.Pptx2013);
}
}
}
Imports Spire.Presentation
Imports Spire.Presentation.Charts
Namespace TickMarkLabel
Class Program
Private Shared Sub Main(args As String())
Dim ppt As New Presentation("C:\Users\Administrator\Desktop\ColumnChart.pptx", FileFormat.Pptx2013)
Dim chart As IChart = TryCast(ppt.Slides(0).Shapes(0), IChart)
'rotate tick labels
chart.PrimaryCategoryAxis.TextRotationAngle = 45
'specify interval between labels
chart.PrimaryCategoryAxis.IsAutomaticTickLabelSpacing = False
chart.PrimaryCategoryAxis.TickLabelSpacing = 2
'''/change position
'chart.PrimaryCategoryAxis.TickLabelPosition = TickLabelPositionType.TickLabelPositionHigh;
ppt.SaveToFile("result.pptx", FileFormat.Pptx2013)
End Sub
End Class
End Namespace
We have already had an article of showing how to replace the image on the existing PDF file. Starts from Spire.PDF V3.8.45, it newly supports to update the image on button field via the method of field.SetButtonImage(PdfImage.FromFile(@"")). This article will focus on demonstrate how to replace the image on the button field in C#.
Firstly, check the original PDF file with the button field.

Step 1: Create a PDF document and load from file.
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("Sample.PDF", FileFormat.PDF);
Step 2: Get the form from the loaded PDF document.
PdfFormWidget form = pdf.Form as PdfFormWidget;
Step 3: Find the button field named "Image" and then set a new image for this button field.
for (int i = 0; i < form.FieldsWidget.Count; i++)
{
if (form.FieldsWidget[i] is PdfButtonWidgetFieldWidget)
{
PdfButtonWidgetFieldWidget field = form.FieldsWidget[i] as PdfButtonWidgetFieldWidget;
if (field.Name == "Image")
{ field.SetButtonImage(PdfImage.FromFile("logo.png")); }
}
}
Step 4: Save the document to file.
pdf.SaveToFile("result.pdf");
Effective screenshot after replace the image on the button field.

Full codes:
using Spire.Pdf;
using Spire.Pdf.Graphics;
using Spire.Pdf.Widget;
namespace ImageButton
{
class Program
{
static void Main(string[] args)
{
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("Sample.PDF", FileFormat.PDF);
PdfFormWidget form = pdf.Form as PdfFormWidget;
for (int i = 0; i < form.FieldsWidget.Count; i++)
{
if (form.FieldsWidget[i] is PdfButtonWidgetFieldWidget)
{
PdfButtonWidgetFieldWidget field = form.FieldsWidget[i] as PdfButtonWidgetFieldWidget;
if (field.Name == "Image")
{ field.SetButtonImage(PdfImage.FromFile("logo.png")); }
}
}
pdf.SaveToFile("result.pdf");
}
}
}
Embed private font into Word document when save as .docx file format
2016-11-09 08:49:02 Written by KoohjiNow Spire.Doc supports to embed private fonts from font files into Word document when save as .docx file format. This article will show you the detail steps of how to accomplish this task by using Spire.Doc.
For demonstration, we used a font file DeeDeeFlowers.ttf.

In the following part, we will embed font from above file into a Word document and use it to create text.
Step 1: Create a blank Word document.
Document document = new Document();
Step 2: Add a section and a paragraph to the document.
Section section = document.AddSection(); Paragraph p = section.AddParagraph();
Step 3: Append text to the paragraph, then set the font name and font size for the text.
TextRange range = p.AppendText("Let life be beautiful like summer flowers\n"
+"Life, thin and light-off time and time again\n"
+ "Frivolous tireless");
range.CharacterFormat.FontName = "DeeDeeFlowers";
range.CharacterFormat.FontSize = 20;
Step 4: Allow embedding font in document by setting the Boolean value of EmbedFontsInFile property to true.
document.EmbedFontsInFile = true;
Step 5: Embed private font from font file into the document.
document.PrivateFontList.Add(new PrivateFontPath("DeeDeeFlowers", @"E:\Program Files\DeeDeeFlowers.ttf"));
Step 6: Save as .docx file format.
document.SaveToFile("result.docx", FileFormat.Docx);
After running the code, we'll get the following output:

Full code:
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace Embed_private_font_into_Word
{
class Program
{
static void Main(string[] args)
{
Document document = new Document();
Section section = document.AddSection();
Paragraph p = section.AddParagraph();
TextRange range = p.AppendText("Let life be beautiful like summer flowers\n"
+"Life, thin and light-off time and time again\n"
+ "Frivolous tireless");
range.CharacterFormat.FontName = "DeeDeeFlowers";
range.CharacterFormat.FontSize = 20;
document.EmbedFontsInFile = true;
document.PrivateFontList.Add(new PrivateFontPath("DeeDeeFlowers", @"E:\Program Files\DeeDeeFlowers.ttf"));
document.SaveToFile("result.docx", FileFormat.Docx);
}
}
}
Sometimes we only need to get the text from the word document for other use when we deal with the word documents with large amount of information. With the help of Spire.Doc, we have already demonstrated how to extract the text from the word document by traverse every paragraph on the word document and then append the text accordingly. This article will show you how to use the method of doc.GetText() to extract the text directly from the word documents with texts, images and tables. It is more convenient for developers to extract the text from the word document from code.
Firstly, view the sample word document which will be extracted the text firstly:

Step 1: Create a word instance and load the source word document from file.
Document doc = new Document();
doc.LoadFromFile("Sample.docx");
Step 2: Invoke the doc.GetText() method to get all the texts from the word document.
string s = doc.GetText();
Step 3: Create a New TEXT File to Save Extracted Text.
File.WriteAllText("Extract.txt", s.ToString());
Effective screenshot after get all the text from the word document:

Full codes:
using Spire.Doc;
using System.IO;
namespace GetText
{
class WordText
{
public void GetText()
{
Document doc = new Document();
doc.LoadFromFile("Sample.docx");
string s = doc.GetText();
File.WriteAllText("Extract.txt", s.ToString());
}
}
}
Getting the coordinates of text or an image in a PDF is a useful task that allows precise referencing and manipulation of specific elements within the document. By extracting the coordinates, one can accurately identify the position of text or images on each page. This information proves valuable for tasks like data extraction, text recognition, or highlighting specific areas. This article introduces how to get the coordinate information of text or an image in a PDF document in C# using Spire.PDF for .NET.
Install Spire.PDF for .NET
To begin with, you need to add the DLL files included in the Spire.PDF for .NET package as references in your .NET project. You can download Spire.PDF for .NET from our website or install it directly through NuGet.
PM> Install-Package Spire.PDF
Get Coordinates of Text in PDF in C#
The PdfTextFinder.Find() method provided by Spire.PDF can help us find all instances of the string to be searched in a searchable PDF document. The coordinate information of a specific instance can be obtained through the PdfTextFragment.Positions property. The following are the step to get the (X, Y) coordinates of the specified text in a PDF using Spire.PDF for .NET.
- Create a PdfDocument object.
- Load a PDF file using PdfDocument.LoadFromFile() method.
- Loop through the pages in the document.
- Create a PdfTextFinder object, and get all instances of the specified text from a page using PdfTextFinder.Find() method.
- Loop through the find results and get the coordinate information of a specific result through PdfTextFragment.Positions property.
- C#
using Spire.Pdf;
using Spire.Pdf.Texts;
using System.Collections.Generic;
using System;
using System.Drawing;
namespace GetCoordinatesOfText
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Load a PDF file
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\input.pdf");
//Loop through all pages
foreach (PdfPageBase page in doc.Pages)
{
//Create a PdfTextFinder object
PdfTextFinder finder = new PdfTextFinder(page);
//Set the find options
PdfTextFindOptions options = new PdfTextFindOptions();
options.Parameter = TextFindParameter.IgnoreCase;
finder.Options = options;
//Find all instances of a specific text
ListPdfTextFragment> fragments = finder.Find("target audience");
//Loop through the instances
foreach (PdfTextFragment fragment in fragments)
{
//Get the position of a specific instance
PointF found = fragment.Positions[0];
Console.WriteLine(found);
}
}
}
}
}

Get Coordinates of an Image in PDF in C#
Spire.PDF provides the PdfImageHelper.GetImagesInfo() method to help us get all image information on a specific page. The coordinate information of a specific image can be obtained through the PdfImageInfo.Bounds property. The following are the steps to get the coordinates of an image in a PDF document using Spire.PDF for .NET.
- Create a PdfDocument object.
- Load a PDF file using PdfDocument.LoadFromFile() method.
- Get a specific page through PdfDocument.Pages[index] property.
- Create a PdfImageHelper object, and get all image information from the page using PdfImageHelper.GetImageInfo() method.
- Get the coordinate information of a specific image through PdfImageInfo.Bounds property.
- C#
using Spire.Pdf;
using Spire.Pdf.Utilities;
namespace GetCoordinatesOfImage
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Load a PDF file
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\input.pdf");
//Get a specific page
PdfPageBase page = doc.Pages[0];
//Create a PdfImageHelper object
PdfImageHelper helper = new PdfImageHelper();
//Get image information from the page
PdfImageInfo[] images = helper.GetImagesInfo(page);
//Get X,Y coordinates of a specific image
float xPos = images[0].Bounds.X;
float yPos = images[0].Bounds.Y;
Console.WriteLine("The image is located at({0},{1})", xPos, yPos);
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.