Draw PDF ellipses in C++

Draw ellipses and label one shape

  1. Create a Document and add a page.
  2. Create a 400-by-400 Graph with a green border.
  3. Create two Ellipse objects using the supplied positions and dimensions.
  4. Configure their stroke colors.
  5. Assign a TextFragment containing Ellipse to the first shape.
  6. Add both shapes to the graph.
  7. Add the Graph to the page paragraphs.
  8. Save the PDF with Save().
#include <Aspose.PDF.Cpp/Color.h>
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/Generator/BorderInfo.h>
#include <Aspose.PDF.Cpp/Generator/BorderSide.h>
#include <Aspose.PDF.Cpp/Generator/BoundsCheckableList/BoundsCheckableList.h>
#include <Aspose.PDF.Cpp/Generator/Drawing/Ellipse.h>
#include <Aspose.PDF.Cpp/Generator/Drawing/Graph.h>
#include <Aspose.PDF.Cpp/Generator/GraphInfo.h>
#include <Aspose.PDF.Cpp/Generator/Paragraphs.h>
#include <Aspose.PDF.Cpp/Page.h>
#include <Aspose.PDF.Cpp/PageCollection.h>
#include <Aspose.PDF.Cpp/Text/TextFragment.h>

using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Drawing;
using namespace Aspose::Pdf::Text;

// Port of GraphsEllipseExamples.addEllipse.
void GraphExamples::AddEllipse(String outputFile)
{
    auto document = MakeObject<Document>();
    auto page = document->get_Pages()->Add();
    auto graph = MakeObject<Graph>(400.0, 400.0);
    graph->set_Border(MakeObject<BorderInfo>(BorderSide::All, Color::get_Green()));

    auto ellipse1 = MakeObject<Ellipse>(150, 100, 120, 60);
    ellipse1->get_GraphInfo()->set_Color(Color::get_GreenYellow());
    ellipse1->set_Text(MakeObject<TextFragment>(u"Ellipse"));
    graph->get_Shapes()->Add(ellipse1);

    auto ellipse2 = MakeObject<Ellipse>(50, 50, 18, 300);
    ellipse2->get_GraphInfo()->set_Color(Color::get_DarkRed());
    graph->get_Shapes()->Add(ellipse2);

    page->get_Paragraphs()->Add(graph);
    document->Save(outputFile);
}

Draw filled ellipses

  1. Create a Document and add a page.
  2. Create a 400-by-400 Graph with a green border.
  3. Create two Ellipse objects.
  4. Set their FillColor values to GreenYellow and DarkRed.
  5. Add the ellipses to Shapes.
  6. Add the Graph to the page paragraphs.
  7. Save the PDF with Save().
#include <Aspose.PDF.Cpp/Color.h>
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/Generator/BorderInfo.h>
#include <Aspose.PDF.Cpp/Generator/BorderSide.h>
#include <Aspose.PDF.Cpp/Generator/BoundsCheckableList/BoundsCheckableList.h>
#include <Aspose.PDF.Cpp/Generator/Drawing/Ellipse.h>
#include <Aspose.PDF.Cpp/Generator/Drawing/Graph.h>
#include <Aspose.PDF.Cpp/Generator/GraphInfo.h>
#include <Aspose.PDF.Cpp/Generator/Paragraphs.h>
#include <Aspose.PDF.Cpp/Page.h>
#include <Aspose.PDF.Cpp/PageCollection.h>

using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Drawing;

void GraphExamples::CreateEllipseFilled(String outputFile)
{
    auto document = MakeObject<Document>();
    auto page = document->get_Pages()->Add();
    auto graph = MakeObject<Graph>(400.0, 400.0);
    graph->set_Border(MakeObject<BorderInfo>(BorderSide::All, Color::get_Green()));

    auto ellipse1 = MakeObject<Ellipse>(100, 100, 120, 180);
    ellipse1->get_GraphInfo()->set_FillColor(Color::get_GreenYellow());
    graph->get_Shapes()->Add(ellipse1);

    auto ellipse2 = MakeObject<Ellipse>(200, 150, 180, 120);
    ellipse2->get_GraphInfo()->set_FillColor(Color::get_DarkRed());
    graph->get_Shapes()->Add(ellipse2);

    page->get_Paragraphs()->Add(graph);
    document->Save(outputFile);
}