Insert Text Image XPS C#

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

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:

  1. Initialize an object of the XPSDocument class.
  2. Create a brush of any color and add the glyph.
  3. 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:

  1. Create an instance of the XPSDocument class.
  2. Add the Unicode string.
  3. 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:

  1. Create a new XPS Document.
  2. Load input Image.
  3. Create a Matrix and ImageBrush.
  4. 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:

  1. Create a new XPS Document.
  2. Add an ImageBrush-filled rectangle and add a tiled image.
  3. 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.

See Also

Convert XPS or OXPS to Word DOCX/DOC in C#