Working with Text in XPS file | Java

Add Text to XPS Document

Aspose.Page for Java offers XpsGlyphs Class, with which you can add text on XPS document. You need to specify any brush offered by the API, below example uses XpsSolidColorBrush and saves the object of XpsDocument class. Following code snippet shows complete functionality to add text on an XPS document:

 1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Java
 2// The path to the documents directory.
 3String dataDir = Utils.getDataDir();
 4// Create new XPS Document
 5XpsDocument doc = new XpsDocument();
 6//Create a brush 
 7XpsSolidColorBrush textFill = doc.createSolidColorBrush(Color.BLACK);
 8//Add glyph to the document
 9XpsGlyphs glyphs = doc.addGlyphs("Arial", 12, XpsFontStyle.Regular, 300f, 450f, "Hello World!");
10glyphs.setFill(textFill);
11// Save resultant XPS document
12doc.save(dataDir + "AddText_out.xps");

See working with text in XPS documents in .NET and C++.


The result

Add Text

Add Text Using Encoding String

The solution for Java offers XpsGlyphs Class, with which you can add text using Encoding String on an XPS document. You need to specify a brush using setBidiLevel() property of XpsGlyphs class. Following code snippet shows complete functionality to add text using encoding string:

 1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Java
 2// The path to the documents directory.
 3String dataDir = Utils.getDataDir();
 4// Create new XPS Document
 5XpsDocument doc = new XpsDocument();
 6// Add Text
 7XpsSolidColorBrush textFill = doc.createSolidColorBrush(Color.BLACK);
 8XpsGlyphs glyphs = doc.addGlyphs("Arial", 20, XpsFontStyle.Regular, 400f, 200f, "AVAJ rof SPX.esopsA");
 9glyphs.setBidiLevel(1);
10glyphs.setFill(textFill);
11// Save resultant XPS document
12doc.save(dataDir + "AddEncodingText_out.xps");

See working with text in XPS documents in .NET and C++.


The result

Add Text Right-To-Left

You can download examples and data files from GitHub.

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.