Work with canvases within XPS

Clip and transform canvases of XPS files using API for C++

 

In XPS files, a canvas is a rectangular area on a page where visual content, such as text, images, and shapes, can be drawn. It serves as a container for these elements and provides a framework for organizing and layering them.   Canvases can be reused in different parts of the document or even in multiple documents and they provide a flexible way to structure and organize content within an XPS document. Key characteristics of canvases in XPS files:

  • Canvases can be nested within other canvases, creating a hierarchical structure that allows for complex layouts and grouping of elements.
  • Canvases can be transformed using various operations, such as translation, rotation, and scaling. This enables flexible positioning and resizing of content.
  • Canvases can be clipped to specific regions, limiting the visible area of their contents. This is useful for creating intricate shapes and effects.
  • Canvases can contain different visual elements, including text runs, paragraphs, and text boxes. They can also contain images, geometrical shapes, and other canvases.

Managing Canvases in the documents is one of the features offered by Aspose.Page for C++. This is a solution for working with different Page Description Languages, XPS XPS in specific.

To transform canvases of XPS file follow the next guide:

  1. Create an XPS file using the XpsDocument Class .
  2. Create the main canvas, common for all page elements with the AddCanvas() Method.
  3. Make left and top offsets in the main canvas using the CreateMatrix() Method.
  4. Create rectangle path geometry with the CreatePathGeometry() Method.
  5. Create a fill for rectangles by means of the XpsBrush Class.
  6. To create a rectangle in canvas 2 and fill it use the XpsPath Class.
  7. To translate canvas 3 to position a new rectangle below the previous rectangle use the CreateMatrix() Method.
  8. To translate this canvas to the right side of the page the Translate() Method.
  9. To scale canvas 4 call the Scale() Method.
  10. To rotate canvas 5 around a point of 45 degrees the RotateAround() Method goes in handy.
  11. Save the changed XPS document using the XPsDocument.Save() Method.
The canvas transformation
The next code snippet shows how to clip canvases of XPS files within the Aspose.Page for C++ Api Solution.

To Clip canvases of XPS file follow the next guide:

  1. Create or open an XPS file using XpsDocument Class.
  2. Create the main canvas, common for all page elements with the AddCanvas() Method.
  3. Make left and top offsets in the main canvas using the CreateMatrix() Method.
  4. Create rectangle path geometry with the CreatePathGeometry() Method.
  5. Create a fill for rectangles by means of the XpsBrush Class.
  6. To add another canvas with a clip to the main canvas call the AddCanvas() Method again.
  7. Create circle geometry for the clip using the XpsPathGeometry Class.
  8. To create a rectangle in this canvas and fill it use the XpsPath Class.
  9. Add another canvas with the AddCanvas() Method then create a rectangle in this canvas and stroke it with the XpsPathGeometry Class.
  10. Save the changed XPS document by means of the XPsDocument.Save() Method.
The canvas clipping

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.