Knowledgebase (2311)
Children categories
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.
Word Find function can enable users to search for specific text or phrase quickly. Generally speaking, the found text will be highlighted automatically in order to distinguish from other contents. Also, users can format found text, such as set it as italic, bold etc.
Spire.Doc for WPF, a professional WPF component on manipulating Word, enables users to find and highlight text in Word with WPF. With this Word WPF component, developers can invoke doc.FindAllString(text string, bool caseSensitive, bool wholeWord) method directly to find text in Word. And for highlighting found text, developers need Firstly, use TextSelection, the class Spire.Doc for WPF provides, to save found string. Then, use foreach sentence to get each selection in this TextSelection. Finally, set HighlightColor, one properties of TextRange.CharacterFormat, for text in selection.
Below, the screenshot shows a Word document whose specified text has be found and highlighted.

Download and install Spire.Doc for WPF and then use the codes below to Find and Highlight Text in Word
Code Sample:
using Spire.Doc;
using Spire.Doc.Documents;
using System.Drawing;
using System.Windows;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
//Load Document
Document doc = new Document();
doc.LoadFromFile(@"E:\work\Documents\A GOOD MAN IS HARD TO FIND.docx");
//Find Text
TextSelection[] textSelections = doc.FindAllString("Bailey", true, true);
//Highlight Text
foreach (TextSelection selection in textSelections)
{
selection.GetAsOneRange().CharacterFormat.HighlightColor = Color.Green;
}
//Save Document
doc.SaveToFile("FindText.docx", FileFormat.Docx2010);
System.Diagnostics.Process.Start("FindText.docx");
}
}
}
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports System.Drawing
Imports System.Windows
Namespace WpfApplication1
Public Partial Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub button1_Click(sender As Object, e As RoutedEventArgs)
'Load Document
Dim doc As New Document()
doc.LoadFromFile("E:\work\Documents\A GOOD MAN IS HARD TO FIND.docx")
'Find Text
Dim textSelections As TextSelection() = doc.FindAllString("Bailey", True, True)
'Highlight Text
For Each selection As TextSelection In textSelections
selection.GetAsOneRange().CharacterFormat.HighlightColor = Color.Green
Next
'Save Document
doc.SaveToFile("FindText.docx", FileFormat.Docx2010)
System.Diagnostics.Process.Start("FindText.docx")
End Sub
End Class
End Namespace
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.