Add or delete pages to/from XPS documents

C++ API Solution to add or remove pages to/from XPS file


This C++ API can easily manipulate PostScript PS and Encapsulated PostScript EPS files, as well as XPS documents, in a programmatic way. The Solution offers rich functionality: from conversion to working with different graphics, text and other objects. It can handle multiple files at once and supports Levels 1-3 PostScript operators for PS and EPS files. It also handles most of the EPS header comments and ensures maximum conformity when converting PostScript documents, with the exception of a few font cases such as Time New Roman.

Additionally, the API can add or remove pages (and the code example of such a job is presented here), manipulate canvases, paths, and glyph elements, create vector graphics shapes and text strings, and convert XPS outline items in the transformation of XPS files.

XPS can hold multiple documents in one file as well as XPS documents may have multiple pages included. Another functionality offered by Aspose.Page API solution is managing the number of the XPS file. With it, for XPS file transformation, using the API you can add or remove pages. This can be done to existing or to new, just-created files.

In order to manipulate XPS files you need to get:

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

This code snippet explains the creation of a new XPS document and inserting an empty page at the beginning of the pages list.

  1. Set the path to the document directory with the variable dataDir which is assigned the path to the documents directory. It uses the RunExamples::GetDataDir_WorkingWithPages() Method.
  2. Create a new XPS document using the System::MakeObject() Method and a path to a file called Sample1.xps dataDir directory.
  3. The InsertPage() method is called on the document object. Its first parameter is 1 (indicating the position of the new page) and the second parameter is true (indicating that the new page should be inserted at the beginning of the pages list).
  4. Finally, call the Save() Method to save the document object to a new file called AddPages_out.xps in the RunExamples::GetOutDir() directory.

C++ Code to insert pages into an XPS file

    using Aspose::Page::XPS;
    using Aspose::Page::XPS::XpsModel;
    // The path to the documents directory.
    System::String dataDir = RunExamples::GetDataDir_WorkingWithPages();
    // Create new XPS Document
    System::SharedPtr<XpsDocument> doc = System::MakeObject<XpsDocument>(dataDir + u"Sample1.xps");

    // Insert an empty page at beginning of pages list
    doc->InsertPage(1, true);

    // Save resultant XPS document
    doc->Save(RunExamples::GetOutDir() + u"AddPages_out.xps");


1. How do I delete a page in XPS?

To remove a page from an XPS file RemovePage() Method and save the edited document.

2. Can you edit pages of XPS files?

To edit XPS files with this API Solution use the Properties, Methods, and Constructors of the XpsDocument Class.

3. How to add pages to XPS files?

To add another page to an XPS file InsertPage() Method and save the edited document.

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.