Aspose.Pdf

Graph Formats

Mostly, developers not only just add graphs or shapes to the PDF documents but they also like to modify the format, shape or visual appearance of these graphs. In the previous topic, we have discussed about how to add graphs or shapes into PDF documents using rich yet simplest API of Aspose.Pdf . Now, we are going to explain about modifying these Shapes .

 

Aspose.Pdf provides an object, GraphInfo , which is used to set Graph format. Using GraphInfo object, we can apply different settings (to achieve different graph formats) like:

 

 

Using the above features provided by GraphInfo , it is possible to change any Graph to any customized format. Developers can use GraphInfo object to produce any unique format of the graphs according to their requirement.

 

The following figure shows the effect of different Graph formats:

 

 

Note: GraphInfo object is encapsulated in all Shapes like Arc , Curve , Circle , Line and Rectangle .

 

A simple example is given below to demonstrate the use of GraphInfo object of a Circle .

 

Code Snippet

 

[C#]

 

//Instantiate Pdf document by calling its empty constructor

Pdf pdf1 = new Pdf();

 

//Create a section in the Pdf document

Section sec1 = pdf1.Sections.Add();

 

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

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

 

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

sec1.Paragraphs.Add(graph1);

 

//Create a circle shape in the graph with X=200, Y=50 and Radius=30

Circle circle1 = new Circle(graph1,200,50,30);

 

//Add the circle in the shapes collection of the graph

graph1.Shapes.Add(circle1);

 

//Set fill color of the circle using GraphInfo property of circle object

circle1.GraphInfo.FillColor = new Aspose.Pdf.Color("Green");

 

//Enable the circle to be filled with the color specified above line

circle1.GraphInfo.IsFilled = true;

 

//Save the Pdf

pdf1.Save(...);

 

[VB.NET]

 

'Instantiate Pdf object by calling its empty constructor

Dim pdf1 As Pdf = New Pdf()

 

'Create a section in the Pdf document

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

 

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

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

 

'Add the graph object to paragraphs collection of the section

sec1.Paragraphs.Add(graph1)

 

'Create a circle shape in the graph with X=200, Y=50 and Radius=30

Dim circle1 As Circle = New Circle(graph1, 200, 50, 30)

 

'Add the circle in the shapes collection of the graph

graph1.Shapes.Add(circle1)

 

'Set fill color of the circle using GraphInfo property of circle object

circle1.GraphInfo.FillColor = New Aspose.Pdf.Color("Green")

 

'Enable the circle to be filled with the color specified above line

circle1.GraphInfo.IsFilled = True

 

'Save the Pdf

pdf1.Save(...)

 

[JAVA]

 

//Instantiate Pdf document by calling its empty constructor

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 a circle shape in the graph with X=200, Y=50 and Radius=30

Circle circle1 = new Circle(200,50,30);

 

//Add the circle in the shapes collection of the graph

graph1.getShapes().add(circle1);                           

 

//Set fill color of the circle using GraphInfo property of circle object

circle1.getGraphInfo().setFillColor(Color.Green);

 

//Enable the circle to be filled with the color specified above line

circle1.getGraphInfo().setIsFilled(true);

 

//Save the Pdf

pdf1.save(...);

 

[XML]

 

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

  <Pdf xmlns="Aspose.Pdf">

   <Section>

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

     <Circle CenterPosition="200 50" Radius="30" FillColor="Green" IsFilled="true" />

    </Graph>

   </Section>

  </Pdf>

Sample XML for the Winding Filled Rule

[XML]

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

  <Pdf xmlns='Aspose.Pdf'>

   <Section PageMarginTop='0' PageMarginLeft='0' PageMarginRight='0' PageMarginBottom='0' PageHeight='578' PageWidth='793'>

    <Graph Height='578' Width='793'>

      <Line LineJoinMode='0' FillRule='winding' IsFilled='true' FillColor='blue' Color='blue' Position='431 315 433 438 360 343 505 339 367 424 431 315'/>

    </Graph>

   </Section>

  </Pdf>