Draw PDF curve shapes in C++
Contents
[
Hide
]
Draw a stroked curve
- Create a Document and add a page.
- Create a 400-by-200 Graph with a green border.
- Construct a Curve from the eight supplied coordinate values.
- Set its stroke color through GraphInfo and add it 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/Curve.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 <system/array.h>
using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Drawing;
// Port of GraphsCurveExamples.addCurve.
void GraphExamples::AddCurve(String outputFile)
{
auto document = MakeObject<Document>();
auto page = document->get_Pages()->Add();
auto graph = MakeObject<Graph>(400.0, 200.0);
graph->set_Border(MakeObject<BorderInfo>(BorderSide::All, Color::get_Green()));
auto curve1 = MakeObject<Curve>(MakeArray<float>({10, 10, 50, 60, 70, 10, 100, 120}));
curve1->get_GraphInfo()->set_Color(Color::get_GreenYellow());
graph->get_Shapes()->Add(curve1);
page->get_Paragraphs()->Add(graph);
document->Save(outputFile);
}
Draw a filled curve
- Create a Document and add a page.
- Create a 400-by-200 Graph with a green border.
- Construct a Curve from the supplied coordinate array.
- Set FillColor to GreenYellow and add the curve 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/Curve.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 <system/array.h>
using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Drawing;
// Port of GraphsCurveExamples.addCurveFilled.
void GraphExamples::AddCurveFilled(String outputFile)
{
auto document = MakeObject<Document>();
auto page = document->get_Pages()->Add();
auto graph = MakeObject<Graph>(400.0, 200.0);
graph->set_Border(MakeObject<BorderInfo>(BorderSide::All, Color::get_Green()));
auto curve1 = MakeObject<Curve>(MakeArray<float>({10, 10, 50, 60, 70, 10, 100, 120}));
curve1->get_GraphInfo()->set_FillColor(Color::get_GreenYellow());
graph->get_Shapes()->Add(curve1);
page->get_Paragraphs()->Add(graph);
document->Save(outputFile);
}