XPSファイル内のテキスト操作 | Java
XPSドキュメントにテキストを追加
Aspose.Page for JavaはXpsGlyphsクラスを提供しており、これを使用してXPSドキュメントにテキストを追加できます。APIで提供されているブラシを指定する必要があります。以下の例ではXpsSolidColorBrushを使用し、XpsDocumentクラスのオブジェクトを保存します。以下のコードスニペットは、XPSドキュメントにテキストを追加するための完全な機能を示しています。
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");
結果
エンコーディング文字列を使用してテキストを追加する
Java 向けのソリューションでは、XpsGlyphs クラスが提供されており、これを使用すると、XPS ドキュメントにエンコーディング文字列を使用してテキストを追加できます。XpsGlyphs クラスの setBidiLevel() プロパティを使用してブラシを指定する必要があります。次のコードスニペットは、エンコーディング文字列を使用してテキストを追加する完全な機能を示しています。
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");
結果
サンプルとデータ ファイルは GitHub からダウンロードできます。