PDF 파일에 원 객체 추가

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

원 객체 추가

막대 그래프와 마찬가지로 원 그래프는 여러 개의 개별 카테고리에서 데이터를 표시하는 데 사용할 수 있습니다. 그러나 막대 그래프와 달리 원 그래프는 전체를 구성하는 모든 카테고리에 대한 데이터가 있을 때만 사용할 수 있습니다. 그러므로 Aspose.PDF for .NET을 사용하여 객체를 추가하는 방법을 살펴보겠습니다.

아래 단계를 따르세요:

  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 Circle()
{
    // 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 circle with the specified coordinates and radius
        var circle = new Aspose.Pdf.Drawing.Circle(100, 100, 40);

        // Set the circle's color
        circle.GraphInfo.Color = Aspose.Pdf.Color.GreenYellow;

        // Add the circle to the graph shapes
        graph.Shapes.Add(circle);

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

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

그림으로 그린 원은 다음과 같이 보일 것입니다:

Drawing Circle

채워진 원 객체 만들기

이 예제는 색으로 채워진 원 객체를 추가하는 방법을 보여줍니다.

// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void CircleFilled()
{
    // 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 filled circle
        var circle = new Aspose.Pdf.Drawing.Circle(100, 100, 40)
        {
            GraphInfo = 
            { 
                Color = Aspose.Pdf.Color.GreenYellow, 
                FillColor = Aspose.Pdf.Color.Green 
            },
            Text = new Aspose.Pdf.Text.TextFragment("Circle")
        };

        // Add the circle to the graph shapes
        graph.Shapes.Add(circle);

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

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

채워진 원을 추가한 결과를 살펴보겠습니다:

Filled Circle