Draw PDF ellipses in C++
Contents
[
Hide
]
Draw ellipses and label one shape
- Create a Document and add a page.
- Create a 400-by-400 Graph with a green border.
- Create two Ellipse objects using the supplied positions and dimensions.
- Configure their stroke colors.
- Assign a TextFragment containing Ellipse to the first shape.
- Add both shapes to the graph.
- Add the Graph to the page paragraphs.
- 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
- Create a Document and add a page.
- Create a 400-by-400 Graph with a green border.
- Create two Ellipse objects.
- Set their FillColor values to GreenYellow and DarkRed.
- Add the ellipses to Shapes.
- Add the Graph to the page paragraphs.
- 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);
}