Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active October 30, 2025 20:23
Show Gist options
  • Select an option

  • Save aspose-com-gists/daa66e2fdcd72013a450ef298c73b033 to your computer and use it in GitHub Desktop.

Select an option

Save aspose-com-gists/daa66e2fdcd72013a450ef298c73b033 to your computer and use it in GitHub Desktop.
Insert Text in XPS Files using Java Easily
package com.example;
import java.awt.Color;
import com.aspose.page.License;
import com.aspose.xps.XpsDocument;
import com.aspose.xps.XpsFontStyle;
import com.aspose.xps.XpsGlyphs;
import com.aspose.xps.XpsSolidColorBrush;
public class main {
public static void main(String[] args) {
try {
// Define thepath for working directory and load Aspose.Page license
String dataDir = "file";
License lic = new License();
lic.setLicense(dataDir + "license.lic");
// Create an object of the XpsDocument class.
XpsDocument doc = new XpsDocument();
// Create a brush by calling the createSolidColorBrush method.
XpsSolidColorBrush textFill = doc.createSolidColorBrush(Color.BLACK);
// Add glyph to the document.
XpsGlyphs glyphs = doc.addGlyphs("Arial", 12, XpsFontStyle.Regular, 300f,
450f, "Hello World!");
glyphs.setFill(textFill);
// Save resultant XPS document by calling the save method.
doc.save(dataDir + "AddText_out.xps");
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment