PDFファイルに曲線オブジェクトを追加

次のコードスニペットは、Aspose.PDF.Drawingライブラリでも動作します。

曲線オブジェクトを追加

グラフCurveは、各線が他の三つの線と通常の二重点で交わる射影線の接続された集合です。

Aspose.PDF for .NETは、グラフ内でベジェ曲線を使用する方法を示しています。 ベジェ曲線は、スムーズな曲線をモデル化するためにコンピュータグラフィックスで広く使用されています。曲線は、その制御点の凸包に完全に含まれており、ポイントは視覚的に表示され、直感的に曲線を操作するために使用できます。 全体の曲線は、四つの指定されたポイント(その凸包)の角にある四角形に含まれています。

この記事では、PDFドキュメント内で作成できる単純なグラフ曲線と塗りつぶされた曲線を調査します。

以下の手順に従ってください:

  1. Documentインスタンスを作成します。
  2. 特定の寸法を持つDrawing objectを作成します。
  3. Drawing objectのBorderを設定します。
  4. ページの段落コレクションにGraphオブジェクトを追加します。
  5. PDFファイルを保存します。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ExampleCurve()
{
    // The path to the document directory
    var dataDir = RunExamples.GetDataDir_AsposePdf_Images();

    // Create PDF document
    using (var document = new Aspose.Pdf.Document())
    {
        // Add page
        var page = document.Pages.Add();

        // Create Drawing object with certain dimensions
        var graph = new Aspose.Pdf.Drawing.Graph(400, 200);

        // Set border for Drawing object
        var borderInfo = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, Aspose.Pdf.Color.Green);
        graph.Border = borderInfo;

        // Create a curve and set its properties
        var curve1 = new Aspose.Pdf.Drawing.Curve(new float[] { 10, 10, 50, 60, 70, 10, 100, 120 })
        {
            GraphInfo = 
            { 
                Color = Aspose.Pdf.Color.GreenYellow 
            }
        };

        // Add the curve to the graph shapes
        graph.Shapes.Add(curve1);

        // Add Graph object to paragraphs collection of page
        page.Paragraphs.Add(graph);

        // Save PDF document
        document.Save(dataDir + "DrawingCurve1_out.pdf");
    }
}

次の画像は、コードスニペットを実行した結果を示しています:

Drawing Curve

塗りつぶされた曲線オブジェクトを作成

この例では、色で塗りつぶされた曲線オブジェクトを追加する方法を示します。

// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void CurveFilled()
{
    // The path to the document directory
    var dataDir = RunExamples.GetDataDir_AsposePdf_Images();

    // Create PDF document
    using (var document = new Aspose.Pdf.Document())
    {
        // Add page
        var page = document.Pages.Add();

        // Create Drawing object with certain dimensions
        var graph = new Aspose.Pdf.Drawing.Graph(400, 200);

        // Set border for Drawing object
        var borderInfo = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, Aspose.Pdf.Color.Green);
        graph.Border = borderInfo;

        // Create a curve and set fill color
        var curve1 = new Aspose.Pdf.Drawing.Curve(new float[] { 10, 10, 50, 60, 70, 10, 100, 120 })
        {
            GraphInfo = 
            { 
                FillColor = Aspose.Pdf.Color.GreenYellow 
            }
        };

        // Add the curve to the graph shapes
        graph.Shapes.Add(curve1);

        // Add Graph object to paragraphs collection of page
        page.Paragraphs.Add(graph);

        // Save PDF document
        document.Save(dataDir + "DrawingCurve2_out.pdf");
    }
}

塗りつぶされた曲線を追加した結果を見てください:

Filled Curve