Aspose.Pdf

Using Graph Coordinates

The Graph object defines an area where you can draw Shapes . The following figure shows the coordinates in the Graph area. The lower-left point of the Graph area is the origin of the coordinates system. All Shapes in the Graph are oriented using coordinates in this system.

 

 

A Graph Paragraph has a collection of Shapes encapsulated in itself. We can add any kind of Shape supported by Aspose.Pdf to that Shapes collection. In the example below, we have demonstrated the addition of a Curve in the Shapes collection of a Graph object.

 

Curve is a special kind of Shape that requires 4 control points (as its coordinates) to be drawn. Each control point has its own X-axis and Y-axis values. So, we have to pass 8 float constants as 4 control points. Then a Curve Shape is added to the PDF document. Similarly, other Shapes can also be added to PDF documents.

 

Code Snippet

 

[C#]

 

//Instantiate a Pdf document object

Pdf pdf1 = new Pdf();

 

//Add a section to the Pdf document

Section sec1 = pdf1.Sections.Add();

 

//Create a graph object in the section with Width=100 and Height=400

Graph graph1 = new Graph(sec1,100,400);

 

//Add the graph object to the paragraphs collection of the section

sec1.Paragraphs.Add(graph1);

 

//Create an array containing the (X,Y) values of 4 control points

//required to position a curve

float[] posArr = new float[]{0,0,200,80,300,40,350,90};

 

//Create a curve in the graph with the coordinates given as an array to

//the constructor of curve class

Curve curve1 = new Curve(graph1,posArr);

 

//Add the curve shape into the shapes collection of the graph

graph1.Shapes.Add(curve1);

 

//Save the Pdf

pdf1.Save(...);

 

[VB.NET]

 

'Instantiate a Pdf document object

Dim pdf1 As Pdf = New Pdf()

 

'Add a section to the Pdf document

Dim sec1 As Section = pdf1.Sections.Add()

 

'Create a graph object in the section with Width=100 and Height=400

Dim graph1 As Graph = New Graph(sec1, 100, 400)

 

'Add the graph object to the paragraphs collection of the section

sec1.Paragraphs.Add(graph1)

 

'Create an array containing the (X,Y) values of 4 control points

'required to position a curve

Dim posArr() As Single = New Single() {0, 0, 200, 80, 300, 40, 350, 90}

 

'Create a curve in the graph with the coordinates given as an array to

'the constructor of curve class

Dim curve1 As Curve = New Curve(graph1, posArr)

 

'Add the curve shape into the shapes collection of the graph

graph1.Shapes.Add(curve1)

 

'Save the Pdf

pdf1.Save(...)

 

[JAVA]

 

//Instantiate a Pdf document object

Pdf pdf1= new Pdf();                           

 

//Add a section to the Pdf document

Section sec1 = pdf1.getSections().add();

 

//Create a graph object in the section with Width=100 and Height=400

Graph graph1 = new Graph(sec1,400,400);

 

//Add the graph object to the paragraphs collection of the section

sec1.getParagraphs().add(graph1);

 

//Create an array containing the (X,Y) values of 4 control points

//required to position a curve

float[] posArr = new float[]{0,0,200,80,300,40,350,90};

 

//Create a curve in the graph with the coordinates given as an array to

//the constructor of curve class

Curve curve1 = new Curve(posArr);

 

//Add the curve shape into the shapes collection of the graph

graph1.getShapes().add(curve1);

 

//Save the Pdf

pdf1.save(...);

 

[XML]

 

<?xml version="1.0" encoding="utf-8" ?>

  <Pdf xmlns="Aspose.Pdf">

   <Section>

        <Graph Height="100" Width="400">

                <Curve Position="0 0 200 80 300 40 350 90" />

        </Graph>

   </Section>

  </Pdf>