Insert Text or Image in XPS File Programmatically using C++

Insert Text Image XPS C++

You can create, edit, or manipulate XPS files easily. Moreover, you can control the contents and their position as per your requirements. You can insert an image or text in XPS files programmatically using C++ language. Let us explore this feature in detail under the following topics:

Work with Text or Image Contents in XPS Files – API Installation

You can add text or image contents into XPS files in C++ applications. You do not need to consider minor details about the file format of the document as few API calls can do the job as per your requirements. Aspose.Page for C++ API can be configured easily either by downloading it from New Releases or with the below NuGet installation command:

PM> Install-Package Aspose.Page.Cpp

Add Text in XPS File using C++

Text can be used in XPS file to label some drawing, image or other contents. Likewise, you can also use the text as watermark for the file. You need to follow the steps below to add or insert text in XPS files:

  1. Create a new XPS Document
  2. Create a brush to add text
  3. Add glyph to the document
  4. Save output XPS document

The code below shows how to add text in XPS file using C++:

Add Text in XPS File using Unicode String in C++

We have learned adding simple text string to an XPS file. Let us proceed and consider a scenario where you need to add Unicode string in the XPS files. You need to follow the below steps for adding text in XPS file, based on Unicode string:

  1. Create new XPS Document
  2. Add Unicode Text
  3. Save output XPS document

The following code is based on these steps, which shows how to add text in XPS file using Unicode string in C++ language:

Insert Image in XPS Document using C++

Images can contain a lot of visual information so the API supports inserting an image in XPS file in your C++ applications. Aspose.Page for C++ API lets you insert pictures or images in XPS files with below steps:

  1. Create a new XPS Document
  2. Load input Image
  3. Create a Matrix and ImageBrush
  4. Save output XPS file

The code example below shows how to insert image in XPS document with C++:

Insert Tiled Image in XPS File using C++

We have learned the first step of adding or inserting image in an XPS file, let us proceed with related example of inserting tiled image in XPS document. Below are the steps for adding tiled image in XPS file:

  1. Create new XPS Document
  2. Add ImageBrush filled rectangle
  3. Add tiled image
  4. Save resultant XPS document

The following code snippet demonstrates how to add tiled image in XPS file using C++:

Conclusion

In this article, you have learned how to insert or add some text, or image in XPS files using C++ language. This feature can be helpful in scenarios like when you need to add a watermark in XPS documents, or adding some stamp as per your requirements. Likewise, a lot of other exciting features are supported for the XPS file format. You can learn more by visiting the API Documentation, or you can also discuss with us at Free Support Forum. We look forward to getting in touch with you!

See Also

Convert XPS, OXPS to JPG or PNG Image using C# VB.NET