Modify XPS Document with Aspose.Page for .NET
Introduction
Welcome to our step-by-step guide on how to modify XPS documents using Aspose.Page for .NET. Aspose.Page is a powerful library that enables developers to work with XPS files effortlessly. In this tutorial, we will walk you through the process of adding a signature text, “Confirmed,” to specified pages in an XPS document.
Prerequisites
Before you begin, make sure you have the following prerequisites in place:
Aspose.Page for .NET: Ensure that you have the Aspose.Page library installed. You can find the documentation here.
Download the Required Files: Download the necessary files, including the input XPS document, from the Aspose releases page.
Document Directory: Set up a directory for your documents and update the
dir
variable in the code with the appropriate path.
Now that you have everything set up, let’s dive into the step-by-step guide.
Import Namespaces
In your .NET project, start by importing the required namespaces for Aspose.Page:
using Aspose.Page.XPS;
using Aspose.Page.XPS.XpsModel;
using System.Drawing;
using System.IO;
Step 1: Open XPS Document Stream
// ExStart:3
// The path to the documents directory.
string dir = "Your Document Directory";
// Open a stream of XPS file
using (FileStream xpsStream = File.Open(dir + "input1.xps", FileMode.Open, FileAccess.Read))
{
// Create PS document from stream
XpsDocument document = new XpsDocument(xpsStream, new XpsLoadOptions());
// Continue to the next step...
}
// ExEnd:3
Step 2: Create Signature Text
// ExStart:4
// Create fill of the signature text
XpsSolidColorBrush textFill = document.CreateSolidColorBrush(Color.BlueViolet);
// Continue to the next step...
// ExEnd:4
Step 3: Define Pages and Add Signature
// ExStart:5
// Define pages where signature will be set
int[] pageNumbers = new int[] {1, 2, 3};
// For every defined page set signature "Confirmed" at coordinates x=650 and y=950
for (int i = 0; i < pageNumbers.Length; i++)
{
// Define active page
document.SelectActivePage(pageNumbers[i]);
// Create glyphs object
XpsGlyphs glyphs = document.AddGlyphs("Arial", 24, FontStyle.Bold, 650, 900, "Confirmed");
// Define fill for glyphs
glyphs.Fill = textFill;
}
// Continue to the next step...
// ExEnd:5
Step 4: Save Changes to XPS Document
// ExStart:6
// Save changed XPS document
document.Save(dir + "input1_out.xps");
// ExEnd:6
Congratulations! You’ve successfully modified an XPS document using Aspose.Page for .NET. Feel free to explore additional features and functionalities offered by Aspose.Page to enhance your document processing.
Conclusion
In this tutorial, we covered the essential steps to modify XPS documents using Aspose.Page for .NET. By following these steps, you can seamlessly integrate signature texts into specific pages, adding a personalized touch to your documents.
FAQ’s
Q1: Is Aspose.Page compatible with the latest .NET frameworks?
A1: Yes, Aspose.Page is regularly updated to support the latest .NET frameworks.
Q2: Can I customize the font and style of the added text?
A2: Absolutely! You can modify the font, style, and other attributes as per your requirements.
Q3: Are there any limitations on the document size that Aspose.Page can handle?
A3: Aspose.Page is designed to handle documents of varying sizes, but it’s always recommended to check the documentation for specific details.
Q4: How can I obtain a temporary license for Aspose.Page?
A4: You can acquire a temporary license here.
Q5: Where can I seek help or connect with the Aspose community?
A5: Visit the Aspose.Page forum to ask questions and engage with the community.