Manage the number of pages of XPS

.NET API Solution to add or remove pages to/from XPS file

 

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.

Add or delete pages to/from XPS documents we need:

  • Aspose.Page for .NET API which is a feature-rich, powerful and easy-to-use document manipulation and conversion API for C# platform.

  • Open the NuGet package manager, and search for Aspose.Page 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.

  1. Set the path to the documents directory.
  2. Create an XPS file using the XpsDocument Class .
  3. Create an empty page with the InsertPage() Method.
  4. Save the changed XPS document using the XPsDocument.Save

C# Code to add pages to an XPS file

    using Aspose.Page.Xps;
    using Aspose.Page.Xps.XpsModel;
    using System.Drawing;
    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_WorkingWithPages();

    // Create a new XPS Document
    XpsDocument doc = new XpsDocument(dataDir + "Sample1.xps");

    // Insert an empty page at beginning of pages list
    doc.InsertPage(1, true);
            
    // Save the resultant XPS document
    doc.Save(dataDir + "AddPages_out.xps");
The next code snippet shows how to delete useless pages from XPS files within the Aspose.Page for .NET Api Solution.

Take the next steps if some pages of your XPS file need to be deleted:

  1. Set the path to the documents directory.
  2. Create or open an XPS file using the XpsDocument Class.
  3. Remove the pages you do not need anymore with the RemovePage() Method
  4. Save the changed XPS document by means of the XPsDocument.Save() Method

C# Code to remove pages from the XPS file

    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_WorkingWithPages();

    // Create a new XPS Document
    XpsDocument doc = new XpsDocument(dataDir + "Sample2.xps");

    // Remove the first page (at index 1).
    doc.RemovePageAt(1);
            
    // Save the resultant XPS document
    doc.Save(dataDir + "Sample2_out.xps");



FAQ

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.