Add Curve Shapes to PDF in Java

Curves in Aspose.PDF for Java are defined by a float coordinate array passed to Curve.

Add a curve outline

  1. Create a new PDF Document.
  2. Add a Page to the document.
  3. Create a Graph container and add it to the page.
  4. Create the Curve shape and configure its control points.
  5. Add the Curve to the Graph container.
  6. Set the shape properties required by the example, including Color.
  7. Save the output PDF Document.
public static void addCurve(Path outputFile) {
    try (Document document = new Document()) {
        Page page = document.getPages().add();
        Graph graph = new Graph(400.0, 200.0);
        graph.setBorder(new BorderInfo(BorderSide.All, Color.getGreen()));

        Curve curve1 = new Curve(new float[]{10, 10, 50, 60, 70, 10, 100, 120});
        curve1.getGraphInfo().setColor(Color.getGreenYellow());
        graph.getShapes().addItem(curve1);

        page.getParagraphs().add(graph);
        document.save(outputFile.toString());
    }
}