PDF 파일에 곡선 객체 추가

다음 코드 스니펫은 Aspose.PDF.Drawing 라이브러리와 함께 작동합니다.

곡선 객체 추가

그래프 Curve는 각각 세 개의 다른 선과 만나는 연결된 투영선의 집합입니다.

Aspose.PDF for .NET는 그래프에서 베지어 곡선을 사용하는 방법을 보여줍니다. 베지어 곡선은 부드러운 곡선을 모델링하기 위해 컴퓨터 그래픽에서 널리 사용됩니다. 곡선은 제어 점의 볼록 껍질에 완전히 포함되며, 이 점들은 그래픽적으로 표시되고 곡선을 직관적으로 조작하는 데 사용될 수 있습니다. 전체 곡선은 네 개의 주어진 점(그들의 볼록 껍질)의 모서리를 가진 사각형에 포함됩니다.

이 문서에서는 PDF 문서에서 생성할 수 있는 간단한 그래프 곡선과 채워진 곡선을 조사할 것입니다.

아래 단계를 따르십시오:

  1. Document 인스턴스를 생성합니다.
  2. 특정 치수를 가진 Drawing object를 생성합니다.
  3. 드로잉 객체에 대한 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