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:
- Create an XPS file using the XpsDocument Class .
- Create the main canvas, common for all page elements with the AddCanvas() Method.
- Make left and top offsets in the main canvas using the CreateMatrix() Method.
- Create rectangle path geometry with the CreatePathGeometry() Method.
- Create a fill for rectangles by means of the XpsBrush Class.
- To create a rectangle in canvas 2 and fill it use the XpsPath Class.
- To translate canvas 3 to position a new rectangle below the previous rectangle use the CreateMatrix() Method.
- To translate this canvas to the right side of the page the Translate() Method.
- To scale canvas 4 call the Scale() Method.
- To rotate canvas 5 around a point of 45 degrees the RotateAround() Method goes in handy.
- Save the changed XPS document using the XPsDocument.Save() Method.
The canvas transformation
To Clip canvases of XPS file follow the next guide:
- Create or open an XPS file using XpsDocument Class.
- Create the main canvas, common for all page elements with the AddCanvas() Method.
- Make left and top offsets in the main canvas using the CreateMatrix() Method.
- Create rectangle path geometry with the CreatePathGeometry() Method.
- Create a fill for rectangles by means of the XpsBrush Class.
- To add another canvas with a clip to the main canvas call the AddCanvas() Method again.
- Create circle geometry for the clip using the XpsPathGeometry Class.
- To create a rectangle in this canvas and fill it use the XpsPath Class.
- Add another canvas with the AddCanvas() Method then create a rectangle in this canvas and stroke it with the XpsPathGeometry Class.
- 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.