キャンバスを操作する

XPS ファイルのキャンバスをクリップして変換する

 

ドキュメント内のキャンバスの管理は、Aspose.Page for .NET が提供する機能の 1 つです。これは、さまざまなページ記述言語、特に XPS XPS を操作するためのソリューションです。以下の例では、次の方法を確認できます。

  • XPS ファイルでキャンバスを作成します。

  • メイン キャンバスで左と上にオフセットを作成します。

  • 変換された変換を含む新しいキャンバスをメイン キャンバスに追加します。

  • ポイント変換を中心に回転する新しいキャンバスをメイン キャンバスに追加します。

  • キャンバスをクリップします。 XPS ファイルのキャンバスを使用したさらに多くの操作。

XPS ファイルのキャンバスを変換するには、次のガイドに従います。

  1. XpsDocument クラス を使用して XPS ファイルを作成します。
  2. AddCanvas() メソッドを使用して、すべてのページ要素に共通のメイン キャンバスを作成します。
  3. CreateMatrix() メソッドを使用して、メイン キャンバスの左と上のオフセットを作成します。
  4. CreatePathGeometry() メソッドで四角形のパス ジオメトリを作成します。
  5. XpsBrush クラスを使用して、四角形の塗りつぶしを作成します。
  6. キャンバス 2 に四角形を作成して塗りつぶすには、 XpsPath クラスを使用します。
  7. キャンバス 3 を変換して前の四角形の下に新しい四角形を配置するには、 CreateMatrix() メソッドを使用します。
  8. このキャンバスをページの右側に変換するには、 Translate() メソッドを使用します。
  9. キャンバス 4 をスケーリングするには、 Scale() メソッドを呼び出します。
  10. キャンバス 5 を 45 度の点を中心に回転するには、 RotateAround() メソッドを使用します。便利で。
  11. XPsDocument.Save() メソッドを使用して、変更された XPS ドキュメントを保存します。

XPS ファイル Canvas Transformation C# コード

    using Aspose.Page.Xps;
    using Aspose.Page.Xps.XpsModel;
    using System.Drawing;
    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_WorkingWithCanvas();
            
    // Create a new XPS Document
    XpsDocument doc = new XpsDocument();

    // Create main canvas, common for all page elemnts
    XpsCanvas canvas1 = doc.AddCanvas();

    // Make left and top offsets in the main canvas
    canvas1.RenderTransform = doc.CreateMatrix(1, 0, 0, 1, 20, 10);

    // Create the rectangle path geometry
    XpsPathGeometry rectGeom = doc.CreatePathGeometry("M 0,0 L 200,0 200,100 0,100 Z");

    // Create a fill for rectangles
    XpsBrush fill = doc.CreateSolidColorBrush(doc.CreateColor(12, 15, 159));
            
    // Add new canvas without any transformations to the main canvas
    XpsCanvas canvas2 = canvas1.AddCanvas();
    // Create rectangle in this canvas and fill it
    XpsPath rect = canvas2.AddPath(rectGeom);
    rect.Fill = fill;

    // Add new canvas with translate transformation to the main canvas
    XpsCanvas canvas3 = canvas1.AddCanvas();
    // Translate this canvas to position new rectangle below the previous rectnagle
    canvas3.RenderTransform = doc.CreateMatrix(1, 0, 0, 1, 0, 200);
    // Translate this canvas to the right side of the page
    canvas3.RenderTransform.Translate(500, 0);
    // Create the rectangle in this canvas and fill it
    rect = canvas3.AddPath(rectGeom);
    rect.Fill = fill;

    // Add new canvas with the double scale transformation to the main canvas
    XpsCanvas canvas4 = canvas1.AddCanvas();
    // Translate this canvas to position new rectangle below the previous rectnagle
    canvas4.RenderTransform = doc.CreateMatrix(1, 0, 0, 1, 0, 400);
    // Scale this canvas
    canvas4.RenderTransform.Scale(2, 2);
    // Create a rectangle in this canvas and fill it
    rect = canvas4.AddPath(rectGeom);
    rect.Fill = fill;

    // Add new canvas with rotation around a point transformation to the main canvas
    XpsCanvas canvas5 = canvas1.AddCanvas();
    // Translate this canvas to position new rectangle below the previous rectnagle
    canvas5.RenderTransform = doc.CreateMatrix(1, 0, 0, 1, 0, 800);
    // Rotate this canvas aroud a point on 45 degrees
    canvas5.RenderTransform.RotateAround(45, new PointF(100, 50));
    rect = canvas5.AddPath(rectGeom);
    rect.Fill = fill;
            
    // Save the resultant XPS document
    doc.Save(dataDir + "output1.xps");
次のコード スニペットは、Aspose.Page for .NET Api ソリューション内で XPS ファイルのキャンバスをクリップする方法を示しています。

XPS ファイルのキャンバスをクリップするには、次のガイドに従います。

  1. XpsDocument Class を使用して XPS ファイルを作成または開きます。
  2. AddCanvas() メソッドを使用して、すべてのページ要素に共通のメイン キャンバスを作成します。
  3. CreateMatrix() メソッドを使用して、メイン キャンバスの左と上のオフセットを作成します。
  4. CreatePathGeometry() メソッドで四角形のパス ジオメトリを作成します。
  5. XpsBrush クラスを使用して、四角形の塗りつぶしを作成します。
  6. クリップを含む別のキャンバスをメイン キャンバスに追加するには、AddCanvas() メソッドを再度呼び出します。
  7. XpsPathGeometry クラスを使用して、クリップの円ジオメトリを作成します。
  8. このキャンバスに四角形を作成して塗りつぶすには、 XpsPath クラスを使用します。
  9. AddCanvas() メソッドで別のキャンバスを追加してから、このキャンバスに長方形を作成し、XpsPathGeometry クラスでそれをストロークします。
  10. XPsDocument.Save() メソッドを使用して、変更された XPS ドキュメントを保存します。

XPS ファイル キャンバス クリッピング C# コード

    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_WorkingWithCanvas();
            
    // Create a new XPS Document
    XpsDocument doc = new XpsDocument();

    // Create main canvas, common for all page elemnts
    XpsCanvas canvas1 = doc.AddCanvas();

    // Make left and top offsets in the main canvas
    canvas1.RenderTransform = doc.CreateMatrix(1, 0, 0, 1, 20, 10);

    // Create the rectangle path geometry
    XpsPathGeometry rectGeom = doc.CreatePathGeometry("M 0,0 L 500,0 500,300 0,300 Z");

    // Create a fill for rectangles
    XpsBrush fill = doc.CreateSolidColorBrush(doc.CreateColor(12, 15, 159));
            
    // Add another canvas with the clip to the main canvas
    XpsCanvas canvas2 = canvas1.AddCanvas();

    // Create circle geometry for the clip
    XpsPathGeometry clipGeom = doc.CreatePathGeometry("M250,250 A100,100 0 1 1 250,50 100,100 0 1 1 250,250");
    canvas2.Clip = clipGeom;

    // Create rectangle in this canvas and fill it
    XpsPath rect = canvas2.AddPath(rectGeom);
    rect.Fill = fill;

    // Add the second canvas with stroked rectangle to the main canvas
    XpsCanvas canvas3 = canvas1.AddCanvas();

    // Create rectangle in this canvas and stroke it
    rect = canvas3.AddPath(rectGeom);
    rect.Stroke = fill;
    rect.StrokeThickness = 2;

    // Save resultant XPS document
    doc.Save(dataDir + "output2.xps");



よくある質問

1. XPS ファイルにキャンバスを追加するにはどうすればよいですか?

ドキュメントディレクトリへのパスを設定します。キャンバスを追加するには、AddCanvas() メソッドを使用します。

2. XPS ファイル内のキャンバス オフセットを操作するにはどうすればよいですか?

ドキュメント ディレクトリへのパスを設定し、キャンバスを追加します。オフセットを作成するには、CreateMatrix() メソッドを使用します。

3. XPS ファイル内のキャンバスを使用したどのような操作がサポートされていますか?

キャンバスを作成、クリップ、追加できるだけでなく、そのオフセットを操作することもできます。

XPS XPS ファイル形式とは

XPS 形式は PDF 形式に似ています。どちらもページ記述言語 (PDL) 形式です。 EPS は PostScript 言語ではなく、HTML に基づいています。 .eps ファイルには、ドキュメントの構造のマークアップと、ドキュメントがどのように見えるかに関する情報を含めることができます。また、ドキュメントを印刷およびレンダリングする方法についての説明も追加されています。この形式の特徴は、ドキュメントの説明を修正することです。つまり、誰が、どのオペレーティング システムからドキュメントを開いたとしても、同じように表示されます。