XPS files contain fixed page layout information including the layout, appearance, and printing information for a document. You can insert some text or image into an XPS file programmatically in C#.
- Insert Text or Image in an XPS Document – C# API Installation
- Add Text in XPS File using C#
- Add Text in XPS File using Unicode String in C#
- Insert Image in XPS Document using C#
- Place Tiled Image in XPS File using C#
Insert Text or Image in an XPS Document – C# API Installation
You can insert text or image in an XPS file without needing to install any word processor or other user-interface application. Simply configure Aspose.Page for .NET by downloading the DLL files from the Downloads section or using the NuGet installation command below:
PM> Install-Package Aspose.Page
Add Text in XPS File using C#
You can add any text in an XPS file by following the steps below:
- Initialize an object of the XPSDocument class.
- Create a brush of any color and add the glyph.
- Save output XPS document.
The following code snippet explains how to add text in an XPS file programmatically in C#:
Add Text in XPS File using Unicode String in C#
You can also add a Unicode string to the XPS document by following the steps below:
- Create an instance of the XPSDocument class.
- Add the Unicode string.
- Save the output XPS document.
The following code is based on these steps, which shows how to add text in an XPS file using a Unicode string in C# language:
Insert Image in XPS Document using C#
You can insert an image in the XPS document with the following steps:
- Create a new XPS Document.
- Load input Image.
- Create a Matrix and ImageBrush.
- Finally, save the output XPS file.
The code example below shows how to insert an image in an XPS document with C#:
Insert Tiled Image in XPS File using C#
You can insert the tiled image in the XPS file using C# by following the steps below:
- Create a new XPS Document.
- Add an ImageBrush-filled rectangle and add a tiled image.
- Save output XPS document.
The code snippet below elaborates on how to add the tiled image in an XPS file using C#:
Conclusion
In this article, you have explored how to insert text or images in an XPS document using C#. You can add text as a simple string or a Unicode string as per your requirements. Likewise, an image can be inserted as usual or as a tiled image. Please feel free to visit the documentation section to learn other features of the API. In case of any concerns, please write to us at the forum.