XPS パッケージ内でのパッケージ間の操作
C# を介して XPS パッケージ内のページ、色、グリフを操作する
.NET 用の Aspose.Page API ソリューションには、XPS ファイルを操作するための個別のライブラリとして XPS パッケージが含まれています。その豊富な機能には、ファイルのマージ、変換、グラフィックスの操作など、多くの便利で人気のある機能が含まれています.
XPS では、1 つのドキュメントに複数のファイルを保持できます。そのため、どの XPS パッケージにも、ドキュメント内および異なる XPS ドキュメント間でこれらのファイルとそのページを操作する機能が必要です。このような操作は、パッケージ間操作と呼ばれます。それらは個別に説明する必要があります。
ここでは、ページ操作、グリフや色の追加など、パッケージ間の操作の例を示します。
XPS パッケージ C# 内でページを操作する手順。
- ドキュメント ディレクトリへのパスを設定します。
- XpsDocument クラス を使用して XPS ファイルを作成します。
- あるドキュメントから別のドキュメントの先頭にアクティブなページを挿入するには、 InsertPage() 方法。
- あるドキュメントから別のドキュメントの末尾にアクティブなページを挿入するには、 AddPage() メソッドを使用します。 .
- 空のページを削除するには、 RemovePage() メソッドを使用します。
- あるドキュメントから別のドキュメントにページを削除するには、InsertPage() と SelectActivePage() メソッド。
- XPsDocument.Save を使用して、変更された XPS ドキュメントを保存します。
ページを使用したパッケージ間操作の C# コード
using Aspose.Page.XPS;
using Aspose.Page.XPS.XpsModel;
using System.Drawing;
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithCrossPackageOperations();
// Create the first XPS Document
XpsDocument doc1 = new XpsDocument(dataDir + "input1.xps");
// Create the second XPS Document
XpsDocument doc2 = new XpsDocument(dataDir + "input2.xps");
// Create the third XPS Document
XpsDocument doc3 = new XpsDocument(dataDir + "input3.xps");
// Create the fourth XPS Document
XpsDocument doc4 = new XpsDocument();
// Insert the active page (1 in this case) from the second document to the beginning of the fourth document
doc4.InsertPage(1, doc2.Page, false);
// Insert the active page (1 in this case) from the third document to the end of the fourth document
doc4.AddPage(doc3.Page, false);
// Remove page 2 from the fourth document. This is an empty page that was created when the document had been created.
doc4.RemovePageAt(2);
// Insert page 3 from the first document to the second postion of the fourth document
doc4.InsertPage(2, doc1.SelectActivePage(3), false);
// Save the fourth XPS document
doc4.Save(dataDir + "out.xps");
XPS パッケージ C# 内にグリフ クローンを追加する手順。
- ドキュメント ディレクトリへのパスを設定します。
- XPS ファイルのストリームを開きます。
- XpsDocument Class を使用して XPS ファイルを作成します。
- AddGlyphs() メソッドを使用してドキュメントにグリフを追加します。
- XpsDocument Class を使用して 2 番目の XPS ファイルを作成します。
- 最初のファイルから 2 番目のファイルにグリフを複製するには、Add() および Clone() メソッド。
- XPsDocument.Save() メソッドを使用して、両方の XPS ドキュメントを保存します。
XPS パッケージ内で glyth をコピーする C# コード
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithCrossPackageOperations();
// Create the first XPS Document
XpsDocument doc1 = new XpsDocument();
// Add glyphs to the first document
XpsGlyphs glyphs = doc1.AddGlyphs("Times New Roman", 200, FontStyle.Bold, 50, 250, "Test");
// Fill glyphs in the first document with one color
glyphs.Fill = doc1.CreateSolidColorBrush(Color.Green);
// Create the second XPS Document
XpsDocument doc2 = new XpsDocument();
// Add glyphs cloned from the one's from the first document
glyphs = doc2.Add(glyphs.Clone());
// Fill glyphs in the second document with another color
((XpsSolidColorBrush)glyphs.Fill).Color = doc2.CreateColor(Color.Red);
// Save the first XPS document
doc1.Save(dataDir + "out1.xps");
// Save the second XPS document
doc2.Save(dataDir + "out2.xps");
画像で満たされた Glyph C# を追加する手順。
- ドキュメント ディレクトリへのパスを設定します。
- XPS ファイルのストリームを開きます。
- XpsDocument Class を使用して XPS ファイルを作成します。
- AddGlyphs() メソッドを使用してドキュメントにグリフを追加します。
- イメージ ブラシでグリフを塗りつぶすには、 CreateImageBrush() メソッドを使用します。
- XpsDocument Class を使用して 2 番目の XPS ファイルを作成します。
- AddGlyphs() メソッドを使用して、最初のドキュメントのフォントでグリフを 2 番目のドキュメントに追加します。
- CreateImageBrush() メソッドを使用して、最初のドキュメントの塗りつぶしからイメージ ブラシを作成し、2 番目のドキュメントのグリフを塗りつぶします。
- XPsDocument.Save() メソッドを使用して、両方の XPS ドキュメントを保存します。
XPS パッケージ内で画像が埋め込まれたグリフを作成する C# コード
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithCrossPackageOperations();
// Create the first XPS Document
XpsDocument doc1 = new XpsDocument();
// Add glyphs to the first document
XpsGlyphs glyphs1 = doc1.AddGlyphs("Times New Roman", 200, FontStyle.Bold, 50, 250, "Test");
// Fill the glyphs with an image brush
glyphs1.Fill = doc1.CreateImageBrush(dataDir + "R08SY_NN.tif", new RectangleF(0f, 0f, 128f, 192f),
new RectangleF(0f, 0f, 64f, 96f));
((XpsImageBrush)glyphs1.Fill).TileMode = XpsTileMode.Tile;
// Create the second XPS Document
XpsDocument doc2 = new XpsDocument();
// Add glyphs with the font from the first document to the second document
XpsGlyphs glyphs2 = doc2.AddGlyphs(glyphs1.Font, 200, 50, 250, "Test");
// Create an image brush from the fill of the the first document and fill glyphs in the second document
glyphs2.Fill = doc2.CreateImageBrush(((XpsImageBrush)glyphs1.Fill).Image, new RectangleF(0f, 0f, 128f, 192f),
new RectangleF(0f, 0f, 128f, 192f));
((XpsImageBrush)glyphs2.Fill).TileMode = XpsTileMode.Tile;
// Save the first XPS document
doc1.Save(dataDir + "out1.xps");
// Save the second XPS document
doc2.Save(dataDir + "out2.xps");
よくある質問
1. XPSパッケージとは何ですか?
XPS パッケージは、XPS ファイルを管理するための別個のライブラリです。これを使用して、XPS を編集するための独自のコンバーター、リーダー、またはその他のアプリを作成します。
2. XPS パッケージを入手するにはどうすればよいですか?
XPS パッケージは、 Aspose.Page ソリューションに含まれています。
3. どのようなパッケージ間操作が利用できますか?
Aspose XPS パッケージを使用すると、あるドキュメントから別のドキュメントにページを転送したり、グリフ、スタイル、設定などのオブジェクトのクローンを作成したりできます。
4. XPS ドキュメント間のページを操作するにはどうすればよいですか?
この XPS パッケージでファイルを転送するには、XpsDocument クラスの InsertPage()、AddPage()、RemovePage()、および SelectActivePage() メソッドを使用します。
XPS XPS ファイル形式とは
XPS 形式は PDF 形式に似ています。どちらもページ記述言語 (PDL) 形式です。 EPS は PostScript 言語ではなく、HTML に基づいています。 .eps ファイルには、ドキュメントの構造のマークアップと、ドキュメントがどのように見えるかに関する情報を含めることができます。また、ドキュメントを印刷およびレンダリングする方法についての説明も追加されています。この形式の特徴は、ドキュメントの説明を修正することです。つまり、誰が、どのオペレーティング システムからドキュメントを開いたとしても、同じように表示されます。