Add Gradient Grid Transparency XPS

XPS files can be used to display a lot of visual information. They support text, images, object transparency, grids, gradients, and many other features. You can insert gradient, grid, and transparent objects in XPS files as per your requirements. In this article, we will be exploring these features in detail, along with different examples and use cases. Let us walk through the following topics:

Installing XPS API for C++

You can quickly and easily configure Aspose.Page for C++ API in your programming applications for manipulating XPS, PS, EPS, and other supported file formats. Simply download the DLL file from official Downloads, or install it from NuGet gallery with the command below:

PM> Install-Package Aspose.Page.Cpp 

Adding Gradient in XPS file using C++

Sometimes you need to add gradient in XPS files. You can manipulate the XPS file as the API lets you add linear, horizontal as well as vertical gradient. Let us add the following gradients in a XPS file:

Add Vertical Gradient in XPS file with C++

You can easily add vertical gradient in XPS files with a few simple API calls. Below are the steps for adding the vertical gradient:

  1. Create a new XPS Document
  2. Initialize List of XpsGradientStop
  3. Create a new path by defining the geometry
  4. Save resultant XPS document

The code below is based on these steps, which demonstrates how to add a vertical gradient in an XPS file using C++:

Add Horizontal Gradient in XPS using C++

Another possible variation of gradient in XPS files is the horizontal gradient. The approach of adding horizontal gradient is bit related to the use case we have discussed above. The following are the steps that you need to follow for adding horizontal gradient:

  1. Create new XPS Document
  2. Specify gradient stops using XpsGradientStop
  3. Create path with geometry
  4. Save output XPS document

The following code snippet elaborates how to add horizontal gradient in XPS files using C++:

Insert Grid in XPS file with C++

Aspose.Page for C++ API lets you render grids in the XPS files with a lot of properties to control the rendering. Let us consider the example of inserting grid in XPS file in your C++ based applications. You can work with this feature by considering the steps below:

  1. Initialize XpsDocument class object
  2. Specify Geometry for the grid VisualBrush
  3. Create Canvas for magenta grid VisualBrush
  4. Create Visual brush and add grid
  5. Save output XPS file

The code below is based on these steps which explains how to insert grid in XPS files using C++:

Insert Transparent Object in XPS file using C++

Another exciting feature for working with XPS files is the support for transparency and opacity. You might need to add transparent objects on the XPS file under different scenarios. This can be achieved with the help of the following steps:

  1. Create new XPS Document
  2. Create path with closed rectangle geometry
  3. Add geometry for different paths
  4. Save output XPS document

These steps are followed by the following code, that demonstrates how to add transparent object in XPS file with C++ programming language:

Conclusion

In a nutshell, we have explored a number of features to work with XPS files. You can add a gradient, linear, horizontal, or vertical, as well as grids or transparent objects in XPS files. Moreover, you can take a look at several other features by downloading the Examples project. In case of any ambiguity, please feel free to write to us at the Free Support Forums. We will be honored to guide you!

See Also