Code vector graphics shapes of XPS files

C++ API solution to work with vector graphics of XPS files

 

XPS, like other Page Description Languages, allows working with vector graphics. This C++ API solution includes the manipulation of vector graphics of XPS files. It offers a wide range of functionality, part of which is depicted in the code snippet here. There are just a few examples of how to add oval and rectangle shapes to files. Additionally, you will learn to manage the colors of these shapes. By following this method, you will be able to create any geometric shape you require.

To work with vector graphics shapes of XPS, we need:

  • Aspose.Page for C++ API which is a feature-rich, powerful and easy to use document manipulation and conversion API for C++ platform.

  • You can download its latest version directly, just open NuGet package manager, and search for Aspose.Page.Cpp and install. You may also use the following command from the Package Manager Console.

Package Manager Console Command


    PM> Install-Package Aspose.Page

Steps to add a rectangle with C++.

  1. First, set the path to the directory where the document will be saved.
  2. Create an XPS file by instantiating the XpsDocument Class .
  3. Use the methods of the XpsPath Class to create a rectangle.
  4. Finally, save the modified XPS document by calling the XPsDocument.Save Method.

C++ Code to insert a rectangle to an XPS file

    class AddRectangle : public System::Object
    {
        typedef AddRectangle ThisType;
        typedef System::Object BaseType;

        typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
        RTTI_INFO_DECL();

    public:

        static void Run();

    };

Add an ellipse with C++.

To add an ellipse or other figure to an XPS file you will need to take similar steps and use the same entities as for adding a rectangle.

C++ Code to insert an ellipse to an XPS file

    class AddEllipse : public System::Object
    {
        typedef AddEllipse ThisType;
        typedef System::Object BaseType;

        typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
        RTTI_INFO_DECL();

    public:

        static void Run();

    };



FAQ

1. How to draw graphics in an XPS?

To manipulate vector graphic objects within XPS use the corresponding Classes of the Aspose.Page.XPS.XpsModel namespace.

2. Can I change the color of the graphics within XPS?

Yes, you can manage colors, gradients, brushes, canvases, etc.

3. How can I add geometric figures to an XPS file?

Open a stream of the XPS file. To add the needed figure use methods of the XpsPath Class.

XPS What is XPS File Format

XPS format is similar to PDF format. Both are page description language (PDL) formats. EPS is based on HTML and not on PostScript language. The .eps file is capable to contain a markup of the document's structure along with the information on how the document would look like. There are also added instructions on how to print and render the document. The feature of the format is that it fixes the document's description which means that it will look the same no matter who and from what operational system opens it.