Work with canvases within XPS
Clip and transform canvases in XPS files using the C++ API
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, which provides 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 documents is one of the features offered by Aspose.Page for C++. This solution works with different page description languages, XPS in particular.
To transform canvases of an XPS file, follow the guide below:
- Create an XPS file using the XpsDocument class.
- Create the main canvas, common to all page elements, using 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 using 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, use the Translate() method.
- To scale canvas 4, call the Scale() method.
- To rotate canvas 5 around a point by 45 degrees; the RotateAround() method comes in handy.
- Save the changed XPS document using the XpsDocument.Save() method.
The canvas transformation
To clip canvases of an XPS file, follow the guide below:
- Create or open an XPS file using the XpsDocument class.
- Create the main canvas, common to all page elements, using 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 using 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 using the XpsDocument.Save() method.
The canvas clipping
XPS What is XPS File Format
XPS (XML Paper Specification) is Microsoft’s open‑source alternative to PDF. It uses XML/HTML markup to describe page layout, fonts, and images, ensuring consistent rendering across Windows platforms and other operating systems.