.NET (1317)
Children categories
Creating barcodes in a Word document is a useful technique for enhancing productivity and organization. Barcodes facilitate quick scanning and tracking, making them essential for businesses, events, and personal projects.
This article explains two methods for creating barcodes in a Word document using C#: one with barcode fonts via Spire.Doc for .NET API, and the other using a Barcode API alongside the Word API.
- Create Barcodes in a Word Document Using Barcode Fonts
- Create Barcodes in a Word Document Using Barcode API
Install Spire.Doc for .NET
To begin with, you need to add the DLL files included in the Spire.Doc for .NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.Doc
Create Barcodes in a Word Document Using Barcode Fonts
A barcode font is a typeface that converts alphanumeric data into a scannable format of bars and spaces. To use it, you typically need to install the font on your system and then format text in a Word document.
The steps to create barcodes in a Word document using barcode fonts are as follows:
- Download and install the desired barcode font on your computer.
- Create a Document object.
- Load a Word file using Document.LoadFromFile() method.
- Get a specific section and add a paragraph using Section.AddParagraph() method.
- Add text to the paragraph using Paragraph.AppendText() method.
- Apply the barcode font to the text using TextRange.CharacterFormat.FontName property.
- Set the font size and color for the text.
- Save the document to a different Word file.
- C#
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace Name
{
class Program
{
static void Main(string[] args)
{
// Create a Document object
Document document = new Document();
// Load a Word file
document.LoadFromFile("C:\\Users\\Administrator\\Desktop\\input.docx");
// Get a specific section
Section section = document.Sections[0];
// Add a paragraph
Paragraph paragraph = section.AddParagraph();
// Append text to the paragraph
TextRange txtRang = paragraph.AppendText("Hello,World");
// Apply barcode font to the text
txtRang.CharacterFormat.FontName = "Code 128";
// Set the font size and text color
txtRang.CharacterFormat.FontSize = 80;
txtRang.CharacterFormat.TextColor = Color.Black;
// Save the document to a different Word file
document.SaveToFile("Barcode.docx", FileFormat.Docx);
// Dispose resources
document.Dispose();
}
}
}

Create Barcodes in a Word Document Using Barcode API
Spire.Barcode for .NET is a Barcode API that allows you to easily create a barcode with customized settings, such as barcode type, data, size, and color. You can install the library from NuGet using the following command.
PM> Install-Package Spire.Barcode
After the barcode image is created, you can then insert it to a Word document with the help of the Spire.Doc for .NET library.
The steps to create barcode in a Word document using a Barcode API are as follows:
- Install Spire.Barcode for .NET in your .NET program.
- Create a BarcodeSettings object.
- Specify the barcode type, data, width and other attributes using the properties under the BarcodeSettings object.
- Generate a barcode image based on the settings using BarCodeGenerator.GenerateImage() method.
- Create a Document object.
- Load a Word file using Document.LoadFromFile() method.
- Get a specific section and add a paragraph using Section.AddParagraph() method.
- Add the barcode image to the paragraph using Paragraph.AppendPicture() method.
- Save the document to a different Word file.
- C#
using Spire.Barcode;
using Spire.Doc;
using Spire.Doc.Documents;
using System.Drawing;
namespace Name
{
class Program
{
static void Main(string[] args)
{
// Create a BarcodeSettings object
BarcodeSettings settings = new BarcodeSettings();
// Set barcode type
settings.Type = BarCodeType.QRCode;
// Set barcode data
settings.Data2D = "Hello, World";
// Set the other attributes of the barcode
settings.X = 1.5f;
settings.QRCodeECL = QRCodeECL.H;
settings.ShowTopText = false;
settings.ShowText = false;
// Create a BarCodeGenerator object
BarCodeGenerator generator = new BarCodeGenerator(settings);
// Generate a barcode image
Image image = generator.GenerateImage();
// Create a Document object
Document document = new Document();
// Load a Word file
document.LoadFromFile("C:\\Users\\Administrator\\Desktop\\target.docx");
// Get a specific section
Section section = document.Sections[0];
// Add a paragraph
Paragraph paragraph = section.AddParagraph();
// Add the barcode image to the paragraph
paragraph.AppendPicture(image);
// Save the document to a different Word file
document.SaveToFile("Barcode.docx", FileFormat.Docx);
// Dispose resources
document.Dispose();
}
}
}

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.
Excel Background Image, one kind of page layout setting, is used to beautify files. Actually, with a beautiful background image, the Excel file will be more attractive to readers. Also, different from inserting image in Excel directly, background image will not cover data information. It means that all the data in Excel can be displayed even though background image is inserted.
Spire.XLS for WPF, a professional component to operate Excel files in WPF applications, enables users to insert background image in Excel. This guide will focus on how to realize this function by using C#, VB.NET.
Assign value for BackgroundImage property of PageSetup in Worksheet class to insert background image. Because the type of BackgroundImage is Bitmap, so the assigned value must be bitmap image. The following screenshot shows result after inserting background image.

Download and install Spire.XLS for WPF. Then add a button in MainWindow. Double click the button to use the following code to insert background image in Excel.
Bitmap bm = new Bitmap(Image.FromFile(@"E:\Work\Documents\SampleImage\Flower.jpg"));
sheet.PageSetup.BackgoundImage = bm;
Dim bm As New Bitmap(Image.FromFile("E:\Work\Documents\SampleImage\Flower.jpg"))
sheet.PageSetup.BackgoundImage = bm
Spire.XLS allows user to operate Excel document directly such as save to stream, save as web response, copy, lock/unlock worksheet, set up workbook properties, etc. As a professional WPF/.NET/Silverlight Excel component, it owns the ability of inserting content into Excel document, formatting cells and converting Excel documents to popular office file formats. Spire.XLS for WPF supports Excel 97-2003, Excel 2007 and Excel 2010.
This section will show you a detail solution to easily convert RTF to HTML in your WPF application via a .NET Word component. Only two lines of core code in total will be used to realize your RTF to HTML task in this solution.
Spire.Doc for WPF, as a professional MS Word component on WPF, enables you to accomplish RTF to HTML task through following two methods: Document.LoadFromFile(string fileName, FileFormat fileFormat) called to load your RTF file from system and Document. SaveToFile(string ilename, FileFormat fileFormat) is used to save the RTF file as HTML.
Now, you can download Spire.Doc for WPF and then, view the effect of RTF to HTML task as below picture:

Sample Code:
using Spire.Doc;
using Spire.Doc.Documents;
namespace wpfrtftohtml
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
//Load RTF file
Document document = new Document();
document.LoadFromFile(@"..\wpfrtftohtml.rtf", FileFormat.Rtf);
//Convert rtf to html
document.SaveToFile("rtftohtml.html", FileFormat.Html);
}
}
}
Imports Spire.Doc
Imports Spire.Doc.Documents
Namespace wpfrtftohtml
Public Class MainWindow
Inherits Window
Public Sub New()
MyBase.New
InitializeComponent
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
'Load RTF file
Dim document As Document = New Document
document.LoadFromFile("..\wpfrtftohtml.rtf", FileFormat.Rtf)
'Convert rtf to html
document.SaveToFile("rtftohtml.html", FileFormat.Html)
End Sub
End Class
End Namespace
A CSV (Comma Separated Values) file is a plain text file that contains data separated by commas. It is widely used to import or export data from one application to another. In some cases, you might need to do conversions between CSV and Excel. In this article, you will learn how to implement this function programmatically in C# and VB.NET using Spire.XLS for .NET library.
Install Spire.XLS for .NET
To begin with, you need to add the DLL files included in the Spire.XLS for .NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.XLS
Convert Excel to CSV in C# and VB.NET
The following are the steps to convert Excel to CSV:
- Create an instance of Workbook class.
- Load an Excel file using Workbook.LoadFromFile() method.
- Get the desired worksheet by its index using Workbook.Worksheets[index] property.
- Save the worksheet as CSV using XlsWorksheet.SaveToFile() method. You can choose one of the following overloaded SaveToFile() methods:
- SaveToFile(string fileName, string separator)
- SaveToFile(string fileName, string separator, Encoding encoding)
- SaveToFile(string fileName, string separator, bool retainHiddenData)
- C#
- VB.NET
using Spire.Xls;
using System.Text;
namespace ConvertAWorksheetToCsv
{
class Program
{
static void Main(string[] args)
{
//Create an instance of Workbook class
Workbook workbook = new Workbook();
//Load an Excel file
workbook.LoadFromFile("Sample.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
//Save the worksheet as CSV
sheet.SaveToFile("ExcelToCSV.csv", ",", Encoding.UTF8);
}
}
}

Convert CSV to Excel in C# and VB.NET
The following are the steps to convert CSV to Excel:
- Create an instance of Workbook class.
- Load a CSV file using Workbook.LoadFromFile(string fileName, string separator, int startRow, int startColumn) method.
- Get the desired worksheet by its index using Workbook.Worksheets[index] property.
- Access the used range of the worksheet using Worksheet.AllocatedRange property. Then set CellRange.IgnoreErrorOptions property as IgnoreErrorType.NumberAsText to ignore possible errors while saving the numbers in the range as text.
- Autofit columns and rows using CellRange.AutoFitColumns() and CellRange.AutoFitRows() methods.
- Save the CSV to Excel using Workbook.SaveToFile(string fileName, ExcelVersion version) method.
- C#
- VB.NET
using Spire.Xls;
namespace ConvertCsvToExcel
{
class Program
{
static void Main(string[] args)
{
//Create an instance of Workbook class
Workbook workbook = new Workbook();
//Load a CSV file
workbook.LoadFromFile(@"ExcelToCSV.csv", ",", 1, 1);
//Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
//Access the used range in the worksheet
CellRange usedRange = sheet.AllocatedRange;
//Ignore errors when saving numbers in the range as text
usedRange.IgnoreErrorOptions = IgnoreErrorType.NumberAsText;
//Autofit columns and rows
usedRange.AutoFitColumns();
usedRange.AutoFitRows();
//Save the result file
workbook.SaveToFile("CSVToExcel.xlsx", ExcelVersion.Version2013);
}
}
}

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.
Excel Panes can be frozen in order to keep certain rows or columns visible when scrolling through the worksheet. This is particularly helpful when you have a huge amount of data that you need to deal with. In this article, you will learn how to freeze rows or/and columns in C# and VB.NET using Sprie.XLS for .NET.
Spire.XLS provides the Worksheet.FreezePanes(int rowIndex, int columnIndex) method to freeze all rows and columns above and left of the selected cell which is determined by the rowIndex and the columnIndex.

The following sections will demonstrate how to:
Install Spire.XLS for .NET
To begin with, you need to add the DLL files included in the Spire.XLS for .NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.XLS
Freeze the Top Row
To freeze the top row, the selected cell should be the cell (2, 1) – “A2”. The following are the steps to freeze the top row using Spire.XLS for .NET.
- Create a Workbook object.
- Load an Excel file using Workbook.LoadFromFile() method.
- Get a specific worksheet through Workbook.Worksheets[sheetIndex] property.
- Freeze the top row by passing (2, 1) to the Worksheet.FreezePanes(int rowIndex, int columnIndex) method as the parameter.
- Save the workbook to another Excel file using Workbook.SaveToFile() method.
- C#
- VB.NET
using Spire.Xls;
namespace FreezeTopRow
{
class Program
{
static void Main(string[] args)
{
//Create a Workbook instance
Workbook workbook = new Workbook();
//Load an Excel document
workbook.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
//Freeze the top row
sheet.FreezePanes(2, 1);
//Save to another file
workbook.SaveToFile("FreezeTopRow.xlsx", ExcelVersion.Version2016);
}
}
}

Freeze the First Column
To freeze the first column, the selected cell should be the cell (1, 2) – “B1”. The following are the steps to freeze the first column using Spire.XLS for .NET.
- Create a Workbook object.
- Load an Excel file using Workbook.LoadFromFile() method.
- Get a specific worksheet through Workbook.Worksheets[sheetIndex] property.
- Freeze the top row by passing (1, 2) to the Worksheet.FreezePanes(int rowIndex, int columnIndex) method as the parameter.
- Save the workbook to another Excel file using Workbook.SaveToFile() method.
- C#
- VB.NET
using Spire.Xls;
namespace FreezeFirstColumn
{
class Program
{
static void Main(string[] args)
{
//Create a Workbook instance
Workbook workbook = new Workbook();
//Load an Excel document
workbook.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
//Freeze the first column
sheet.FreezePanes(1, 2);
//Save to another file
workbook.SaveToFile("FreezeFirstColumn.xlsx", ExcelVersion.Version2016);
}
}
}

Freeze the First Row and the First Column
To freeze the first row and the first column, the selected cell should be the cell (2, 2) – “B2”. The following are the detailed steps.
- Create a Workbook object.
- Load an Excel file using Workbook.LoadFromFile() method.
- Get a specific worksheet through Workbook.Worksheets[sheetIndex] property.
- Freeze the first row and the first column by passing (2, 2) to the Worksheet.FreezePanes(int rowIndex, int columnIndex) method as the parameter.
- Save the workbook to another Excel file using Workbook.SaveToFile() method.
- C#
- VB.NET
using Spire.Xls;
namespace FreezeFirstRowAndFirstColumn
{
class Program
{
static void Main(string[] args)
{
//Create a Workbook instance
Workbook workbook = new Workbook();
//Load an Excel document
workbook.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
//Freeze the first row and the first column
sheet.FreezePanes(2, 2);
//Save to another file
workbook.SaveToFile("FreezeFirstRowAndFirstColumn.xlsx", ExcelVersion.Version2016);
}
}
}

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.
The Find function in Excel is one of the most commonly used functions for quickly locating specified data, and users can also highlight the data to make it more obvious. In this article, you will learn how to programmatically find and highlight cells with a specific value using Spire.XLS for .NET.
Install Spire.XLS for .NET
To begin with, you need to add the DLL files included in the Spire.XLS for .NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.XLS
Find and Highlight Data in Excel
The detailed steps are as follows.
- Create a Workbook instance.
- Load a sample Excel file using Workbook.LoadFromFile() method.
- Get a specified worksheet using Workbook.Worksheets[sheetIndex] property.
- Find all cells with matching text using Worksheet.FindAllString(string stringValue, bool formula, bool formulaValue) method.
- Set color to highlight the cells using CellRange.Style.Color property.
- Save the result file using Workbook.SaveToFile() method.
- C#
- VB.NET
using Spire.Xls;
using System.Drawing;
namespace FindHighlight
{
class Program
{
static void Main(string[] args)
{
//Create a Workbook instance
Workbook workbook = new Workbook();
//Load a sample Excel file
workbook.LoadFromFile("Test.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
//Find all cells with the text "Regulator System"
foreach (CellRange range in sheet.FindAllString("Regulator System", true, true))
{
//Set color to highlight the cells
range.Style.Color = Color.Yellow;
}
//Save the result file
workbook.SaveToFile("FindHighlight.xlsx", ExcelVersion.Version2016);
}
}
}

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.
Excel comments are additional notes or commentary that can be added to specified cells to provide more in-depth explanations or to offer tips to other users. Once a comment’s been added, Excel provides users with the flexibility to format, edit, delete and show/hide the comment in the worksheet. In this article, you will learn how to programmatically edit or delete existing comments in Excel using Spire.XLS for .NET.
Install Spire.XLS for .NET
To begin with, you need to add the DLL files included in the Spire.XLS for.NET package as references in your .NET project. The DLLs files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.XLS
Edit Comments in Excel
After adding comments to your Excel workbook, you may sometimes need to make changes to the added comments. The below table lists some of the core classes and properties used to get the existing comments and then set new text as well as formatting for the comments.
| Name | Description |
| CellRange.Comment Property | Returns a Comment object that represents the comment associated with the cell in the upper-left corner of the range. |
| ExcelCommentObject Class | Represents a comment. |
| ExcelCommentObject.Text Property | Gets or sets the comment text. |
| ExcelCommentObject.Height Property | Gets or sets height of a comment. |
| ExcelCommentObject.Width Property | Gets or sets width of a comment. |
| ExcelCommentObject.AutoSize Property | Indicates whether the size of the specified object is changed automatically to fit text within its boundaries. |
The following are steps to edit comments in Excel:
- Create a Workbook instance.
- Load an Excel file using Workbook.LoadFromFile() method.
- Get the first worksheet of the Excel file using Workbook.Worksheets[] property.
- Get a comment in a specific cell range using Worksheet.Range.Comment property.
- Set new text and height/width or auto size for the existing comment using the properties of ExcelCommentObject class.
- Save the document to another file using Workbook.SaveToFile() method.
- C#
- VB.NET
using Spire.Xls;
namespace EditExcelComment
{
class Program
{
static void Main(string[] args)
{
// Create a Workbook instance
Workbook workbook = new Workbook();
// Load an Excel file
workbook.LoadFromFile("Comments.xlsx");
// Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
//Get comments in specific cells and set new comments
sheet.Range["A8"].Comment.Text = "Frank has left the company.";
sheet.Range["F6"].Comment.Text = "Best sales.";
// Set the height and width of the new comments
sheet.Range["A8"].Comment.Height = 50;
sheet.Range["A8"].Comment.Width = 100;
sheet.Range["F6"].Comment.AutoSize = true;
// Save to file.
workbook.SaveToFile("ModifyComment.xlsx", ExcelVersion.Version2013);
}
}
}

Delete Comments in Excel
The ExcelCommentObject.Remove() method offered by Spire.XLS for .NET allows you to remove a specified comment easily. The detailed steps are as follows:
- Create a Workbook instance.
- Load an Excel file using Workbook.LoadFromFile() method.
- Get the first worksheet of the Excel file using Workbook.Worksheets[] property.
- Get a comment in a specific cell range using Worksheet.Range.Comment property and then delete the comment using ExcelCommentObject.Remove() method.
- Save the document to another file using Workbook.SaveToFile() method.
- C#
- VB.NET
using Spire.Xls;
namespace EditExcelComment
{
class Program
{
static void Main(string[] args)
{
// Create a Workbook instance
Workbook workbook = new Workbook();
// Load an Excel file
workbook.LoadFromFile("Comments.xlsx");
// Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
//Get the comment in a specific cell and remove it
sheet.Range["F6"].Comment.Remove();
// Save to file.
workbook.SaveToFile("DeleteComment.xlsx", ExcelVersion.Version2013);
}
}
}

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.
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.
Word Image can make one document more interesting and impressive. Sometimes, image can be used explain contents. For example, if one document focuses on describing appearance one kind of birds, readers can learn more clearly with a bird picture.
Spire.Doc for WPF, a professional component to manipulate Word documents with WPF, enables users to insert image in Word with WPF. And this guide will show a method about how to insert image Word in WPF quickly.
Users can invoke paragraph.AppendPicture(image) method to insert image in Word directly. If you want to set image height/width to make picture display appropriately in document, you can use Height and Width property provided by DocPicture class which Spire.Doc for .NET offers. Below, there is the result after inserting image in Word.

Download and install Spire.Doc for WPF. Then, add a button in MainWindow. Double click this button and use the following code to insert image in Word.
Code Sample:
//Create Document
Document document = new Document();
Section section = document.AddSection();
Paragraph Imageparagraph = section.AddParagraph();
//Insert Image
Image image = Image.FromFile(@"E:\work\Documents\Image\street.jpg");
DocPicture picture =Imageparagraph.AppendPicture(image);
//Set Image
picture.Height = 360;
picture.Width = 525;
'Create Document
Dim document As New Document()
Dim section As Section = document.AddSection()
Dim Imageparagraph As Paragraph = section.AddParagraph()
'Insert Image
Dim image As Image = image.FromFile("E:\work\Documents\Image\street.jpg")
Dim picture As DocPicture = Imageparagraph.AppendPicture(image)
'Set Image
picture.Height = 360
picture.Width = 525
Spire.Doc is a Microsoft Word component, which enables users to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document in WPF, .NET and Silverlight.
Whatever solution you use to convert RTF to PDF before, the solution that will be introduced is the easiest method to clearly realize your RTF to PDF conversion task. The whole process can be accomplished through three lines of key code in your WPF application via a Word component Spire.Doc for WPF.

Now, please download Spire.Doc for WPF and convert your RTF to PDF by the code below:
using Spire.Doc;
namespace WPFRTFtoPDF
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Document doc = new Document();
doc.LoadFromFile(@"..\WPFRTFtoPDF.rtf", FileFormat.Rtf);
doc.SaveToFile("test.pdf", FileFormat.PDF);
}
}
}
Imports Spire.Doc
Namespace WPFRTFtoPDF
Public Partial Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub button1_Click(sender As Object, e As RoutedEventArgs)
Dim doc As New Document()
doc.LoadFromFile("..\WPFRTFtoPDF.rtf", FileFormat.Rtf)
doc.SaveToFile("test.pdf", FileFormat.PDF)
End Sub
End Class
End Namespace
For comparison, I put the original RTF file below:

Spire.Doc is a standalone word component, which enables users to perform a wide range of word document processing tasks in WPF, .NET and Silverlight without installing MS Word on system.