Draw PDF arc shapes in C++
Contents
[
Hide
]
Draw colored arcs
- Create a Document and add a page.
- Create a 400-by-400 Graph and give it a green BorderInfo.
- Create three Arc objects with the supplied centers, radii, and angles.
- Set a different stroke color through each arc GraphInfo.
- Add the arcs to the graph Shapes collection.
- 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/Arc.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::AddArc(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 arc1 = MakeObject<Arc>(100, 100, 95, 0, 90);
arc1->get_GraphInfo()->set_Color(Color::get_GreenYellow());
graph->get_Shapes()->Add(arc1);
auto arc2 = MakeObject<Arc>(100, 100, 90, 70, 180);
arc2->get_GraphInfo()->set_Color(Color::get_DarkBlue());
graph->get_Shapes()->Add(arc2);
auto arc3 = MakeObject<Arc>(100, 100, 85, 120, 210);
arc3->get_GraphInfo()->set_Color(Color::get_Red());
graph->get_Shapes()->Add(arc3);
page->get_Paragraphs()->Add(graph);
document->Save(outputFile);
}
Create the filled arc drawing
The source combines an arc and line segments; the line is part of the supplied filled drawing.
- Create a Document and add a page.
- Create a 400-by-400 Graph with a green border.
- Add an Arc centered at (100, 100) with radius 95 and angles 0 and 90.
- Set its FillColor to GreenYellow.
- Add a Line through the supplied three points and set its FillColor.
- 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/Arc.h>
#include <Aspose.PDF.Cpp/Generator/Drawing/Graph.h>
#include <Aspose.PDF.Cpp/Generator/Drawing/Line.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 <system/array.h>
using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Drawing;
// Port of GraphsArcExamples.addArcFilled.
void GraphExamples::AddArcFilled(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 arc = MakeObject<Arc>(100, 100, 95, 0, 90);
arc->get_GraphInfo()->set_FillColor(Color::get_GreenYellow());
graph->get_Shapes()->Add(arc);
auto line = MakeObject<Line>(MakeArray<float>({195, 100, 100, 100, 100, 195}));
line->get_GraphInfo()->set_FillColor(Color::get_GreenYellow());
graph->get_Shapes()->Add(line);
page->get_Paragraphs()->Add(graph);
document->Save(outputFile);
}