Introduction

Aspose.PDF FOSS for C++ includes a small vector-graphics API for building free-form shapes directly on a PDF page. This is separate from the library’s raster-rendering path — BmpDevice, JpegDevice, and TiffDevice, which convert existing page content to image formats — and instead lets a program construct new geometry (circles, ellipses, and lines) on a page as the document is generated.

The API centers on a Graph, a container that holds a set of Shape objects and is placed on a page in the same way as other page content, through Page.Paragraphs(). Three concrete shapes derive from the abstract Shape base: Circle, Ellipse, and Line, each expressing its geometry through a small set of numeric properties rather than a shared point or rectangle type. Stroke width, color, fill, and dash pattern are set per shape through GraphInfo, and the Graph container itself carries a BorderInfo for framing the whole container.

This is a narrow area of the library — five classes covering shape geometry and styling — intended for programs that need to draw simple geometric content (borders, markers, connecting lines, highlight circles) on a page without building a full vector-drawing layer or falling back to image compositing.


What’s Included

The Graph Container and Adding Shapes to a Page

Graph holds the shapes drawn on a page. Its own properties — Left(), Top(), Width(), Height(), and IsChangePosition() — position and size the container on the page, and Shapes() returns the vector of Shape pointers it holds. Shapes are added by constructing them, setting their properties, and appending them to that vector; the Graph itself is added to the page through Page.Paragraphs().Add().

#include <aspose/pdf/document.hpp>
#include <aspose/pdf/graph.hpp>
#include <aspose/pdf/circle.hpp>

using namespace Aspose::Pdf;

int main() {
    Document doc;
    Page page = doc.Pages().Add();

    auto graph = std::make_shared<Graph>();
    graph->Left(50.0);
    graph->Top(50.0);
    graph->Width(400.0);
    graph->Height(400.0);

    auto circle = std::make_unique<Circle>();
    circle->PosX(200.0);
    circle->PosY(200.0);
    circle->Radius(75.0);
    graph->Shapes().push_back(std::move(circle));

    page.Paragraphs().Add(graph);
    doc.Save("graph.pdf");
}

Drawing Circles and Ellipses

Circle and Ellipse each describe their geometry with plain numeric properties instead of a shared point or rectangle type. Circle exposes PosX(), PosY(), and Radius(); Ellipse exposes Left(), Bottom(), Width(), and Height(), describing a bounding box in the same style Graph itself uses for positioning. Both override CheckBounds(containerWidth, containerHeight), inherited from Shape, which reports whether the shape’s current geometry fits inside a container of the given size.

#include <aspose/pdf/circle.hpp>
#include <aspose/pdf/ellipse.hpp>

using namespace Aspose::Pdf;

Circle circle;
circle.PosX(150.0);
circle.PosY(150.0);
circle.Radius(50.0);
bool circleFits = circle.CheckBounds(400.0, 400.0);

Ellipse ellipse;
ellipse.Left(20.0);
ellipse.Bottom(20.0);
ellipse.Width(120.0);
ellipse.Height(60.0);
bool ellipseFits = ellipse.CheckBounds(400.0, 400.0);

Drawing Lines

Line stores its geometry differently from Circle and Ellipse: PositionArray() returns a flat std::vector<float> of coordinates — an x, y pair for each point the line passes through — rather than a set of named properties. A two-point segment is set with four values: start x, start y, end x, end y. Like the other shapes, Line overrides CheckBounds(containerWidth, containerHeight) from Shape.

#include <aspose/pdf/line.hpp>

using namespace Aspose::Pdf;

Line line;
line.PositionArray({50.0f, 50.0f, 350.0f, 350.0f});
bool lineFits = line.CheckBounds(400.0, 400.0);

Styling Shapes with GraphInfo and BorderInfo

Each shape’s stroke and fill come from a GraphInfo, read and set through Shape.GraphInfo() / GraphInfo(value). GraphInfo exposes stroke width (LineWidth()), stroke and fill color (Color(), FillColor()), a dash pattern (DashArray(), DashPhase()), a doubled-line flag (IsDoubled()), and skew/scale/rotation properties (SkewAngleX()/SkewAngleY(), ScalingRateX()/ScalingRateY(), RotationAngle()). The Graph container also carries a BorderInfo, set through Border(), which holds one GraphInfo per edge — Left(), Right(), Top(), Bottom() — plus a RoundedBorderRadius() for rounding the container’s own border.

#include <aspose/pdf/graph_info.hpp>
#include <aspose/pdf/border_info.hpp>
#include <aspose/pdf/color.hpp>

using namespace Aspose::Pdf;

GraphInfo stroke;
stroke.LineWidth(2.0f);
stroke.Color(Color::FromRgb(1.0, 0.0, 0.0));
stroke.FillColor(Color::FromRgb(1.0, 0.9, 0.9));
stroke.DashArray({4, 2});

BorderInfo border{BorderSide::All, 1.5f, Color::Black()};
border.RoundedBorderRadius(6.0);

Quick Start

Add the library as a CMake subdirectory and link against the aspose_pdf_foss target:

add_subdirectory(aspose.pdf-foss-for-cpp)
target_link_libraries(your_app PRIVATE aspose_pdf_foss)

Create a document, add a page, draw a circle inside a Graph container, and save the result:

#include <aspose/pdf/document.hpp>
#include <aspose/pdf/graph.hpp>
#include <aspose/pdf/circle.hpp>

using namespace Aspose::Pdf;

int main() {
    Document doc;
    Page page = doc.Pages().Add();

    auto graph = std::make_shared<Graph>();
    graph->Left(50.0);
    graph->Top(50.0);
    graph->Width(300.0);
    graph->Height(300.0);

    auto circle = std::make_unique<Circle>();
    circle->PosX(150.0);
    circle->PosY(150.0);
    circle->Radius(100.0);
    graph->Shapes().push_back(std::move(circle));

    page.Paragraphs().Add(graph);
    doc.Save("circle.pdf");
}

Supported Formats

FormatExtensionReadWrite
BMP.bmp
JPEG.jpg
TIFF.tiff
Text.txt
SVG.svg

These formats apply to the library as a whole — page rasterization (BMP, JPEG, TIFF), text extraction (Text), and SVG import — rather than to the vector-graphics classes specifically. Graph, Shape, Circle, Ellipse, and Line draw directly into the PDF page content and are not tied to a file format of their own.


Open Source & Licensing

Aspose.PDF FOSS for C++ is distributed under the MIT license, with the full source available at github.com/aspose-pdf-foss/Aspose.PDF-FOSS-for-Cpp. The license permits commercial use, modification, and redistribution without a separate agreement.


Getting Started