Add images to XPS

Dynamic API solution for C++ that enhances your XPS files by adding stunning images in an easy way. Supercharge your C++ applications and elevate the content of XPS files!

 

Aspose.Page for C++ API solution lets you manipulate XPS files along with other Page Description Language format files. Among other features the Solution allows you to easily create and read XPS documents and add an image to them. You can accomplish this by creating a Matrix and an ImageBrush to add the image to the XPS file. Here’s an example of how to do this. For complete examples and data files, please go to our Github project . Elevate your XPS documents with this API solution! Seamlessly integrate image insertion capabilities, allowing you to effortlessly enhance your XPS files with visuals. No matter if you’re crafting engaging reports, designing presentations, or creating captivating documents, our API simplifies the process, ensuring precision and efficiency. Bring your content creation capabilities to a new level. Discover the magic of easy image integration with our C++ API solution by getting a free trial or just buy it right away!

In order to add a picture to an XPS file you need to have:

  • 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 images to an XPS file.

  1. Create a new XPS document using the XpsDocument Class.
  2. Create an XpsPath object with the necessary Path Geometry defined. Calling the AddPath() Method for this
  3. If need create a matrix, which is used to position the image. The matrix is set as the RenderTransform Property of the path.
  4. Create an ImageBrush to fill the path with the image. The CreateImageBrush() Method is used to create the brush, and it takes in the path of the image file, the source rectangle and the destination rectangle.
  5. Save the modified XPS document by calling the Save() Method of the XpsDocument Class and passing in the path to save the file.

C++ Code to insert a picture into an XPS file

    using Aspose::Page::XPS;
    using Aspose::Page::XPS::XpsModel;
    // Create new XPS Document
    System::SharedPtr<XpsDocument> doc = System::MakeObject<XpsDocument>();

    // Add Image
    System::SharedPtr<XpsPath> path = doc->AddPath(doc->CreatePathGeometry(u"M 30,20 l 258.24,0 0,56.64 -258.24,0 Z"));
    //Creating a matrix is optional, it can be used for proper positioning
    path->set_RenderTransform(doc->CreateMatrix(0.7f, 0.f, 0.f, 0.7f, 0.f, 20.f));

    //Create Image Brush
    path->set_Fill(doc->CreateImageBrush(dataDir() + u"QL_logo_color.tif", System::Drawing::RectangleF(0.f, 0.f, 258.24f, 56.64f), System::Drawing::RectangleF(50.f, 20.f, 193.68f, 42.48f)));

    // Save resultant XPS document
    doc->Save(outDir() + u"AddImage_out.xps");



FAQ

1. Can I add images to XPS files?

XPS is a fixed-layout document format developed by Microsoft, similar to PDF, and it supports the inclusion of images alongside text and other graphical elements. You can embed images directly into XPS files to enhance visual content and create more engaging documents.

2. How do I add images to an XPS file?

To add images to an XPS file, you can use various methods depending on the software or tools you’re using. In Aspose.Page it is XpsDocument.AddPath() Method of the XpsDocument Class.

3. What image formats are compatible with XPS files?

XPS files support a range of image formats for inclusion, including but not limited to JPEG, PNG, TIFF, GIF, and BMP. You can insert images in any of these formats into your XPS files, and they will be rendered and displayed correctly within the document when viewed using compatible XPS readers or software.

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.