Developers can rotate and adjust the size of the graphs on the fly using Aspose.Pdf . It's very easy yet powerful feature provided by Aspose.Pdf . We have discussed in previous topic that GraphInfo object (that is encapsulated in Graph class) has several properties that help developers to manage the size and shape of the graphs.
RotationAngle property of Graph class is used to set the rotation angle of the graphs. You just need to assign the desired angle to RotationAngle property as a float constant.
Moreover, if you need to adjust the size of the graph, you can use GraphInfo.ScalingRateX or GraphInfo.ScalingRateY or both to resize the Graph according to your requirement.
The following figure demonstrates the effects of RotationAngle and ScalingRateX properties on the graph:
|
Figure: Original Graph and different effects on it |
To achieve the effects as shown in the above figure, sample code is given below for better understanding.
Example:
[C#]
//Instantiate Pdf instance by calling its empty constructor
Pdf pdf1 = new Pdf();
//Create a section in the Pdf document
Section sec1 = pdf1.Sections.Add();
//Create 1st graph in the section with width=100 and height=400
Graph graph1 = new Graph(sec1,100,400);
//Add 1st graph into the paragraphs collection of the section
sec1.Paragraphs.Add(graph1);
//Create a rectangle shape with specified coordinates
Rectangle rect1=new Rectangle(graph1,85,100,100,50);
//Add the rectangle into the shapes collection of the 1st graph
graph1.Shapes.Add(rect1);
//Create 2nd graph in the section with width=100 and height=400
Graph graph2 = new Graph(sec1,100,400);
//Add 2nd graph into the paragraphs collection of the section
sec1.Paragraphs.Add(graph2);
//Create a rectangle shape with specified coordinates
Rectangle rect2=new Rectangle(graph2,85,100,100,50);
//Add the rectangle into the shapes collection of the 2nd graph
graph2.Shapes.Add(rect2);
//Rotate the 2nd graph to 30 degree using RotationAngle property
graph2.GraphInfo.RotationAngle=30;
//Create 3rd graph in the section with width=100 and height=400
Graph graph3 = new Graph(sec1,100,400);
//Add 3rd graph into the paragraphs collection of the section
sec1.Paragraphs.Add(graph3);
//Create a rectangle shape with specified coordinates
Rectangle rect3=new Rectangle(graph3,85,100,100,50);
//Add the rectangle into the shapes collection of the 3rd graph
graph3.Shapes.Add(rect3);
//Adjust the horizontal size of the 3rd graph using ScalingRateX property
graph3.GraphInfo.ScalingRateX=1.5f;
//Save the Pdf
pdf1.Save(...);
[VB.NET]
Dim pdf1 As Pdf = New Pdf()
Dim sec1 As Section = pdf1.Sections.Add()
'Create 1st graph in the section with width=100 and height=400
Dim graph1 As Graph = New Graph(sec1,100,400)
'Add 1st graph into the paragraphs collection of the section
sec1.Paragraphs.Add(graph1)
'Create a rectangle shape with specified coordinates
Dim rect1 As Rectangle = New Rectangle(graph1,85,100,100,50)
'Add the rectangle into the shapes collection of the 1st graph
graph1.Shapes.Add(rect1)
'Create 2nd graph in the section with width=100 and height=400
Dim graph2 As Graph = New Graph(sec1,100,400)
'Add 2nd graph into the paragraphs collection of the section
sec1.Paragraphs.Add(graph2)
'Create a rectangle shape with specified coordinates
Dim rect2 As Rectangle = New Rectangle(graph2,85,100,100,50)
'Add the rectangle into the shapes collection of the 2nd graph
graph2.Shapes.Add(rect2)
'Rotate the 2nd graph to 30 degree using RotationAngle property
graph2.GraphInfo.RotationAngle=30
'Create 3rd graph in the section with width=100 and height=400
Dim graph3 As Graph = New Graph(sec1,100,400)
'Add 3rd graph into the paragraphs collection of the section
sec1.Paragraphs.Add(graph3)
'Create a rectangle shape with specified coordinates
Dim rect3 As Rectangle = New Rectangle(graph3,85,100,100,50)
'Add the rectangle into the shapes collection of the 3rd graph
graph3.Shapes.Add(rect3)
'Adjust the horizontal size of the 3rd graph using ScalingRateX property
graph3.GraphInfo.ScalingRateX=1.5f
'Save the Pdf
pdf1.Save(...)
[XML]
<?xml version="1.0" encoding="utf-8" ?>
<Pdf xmlns="Aspose.Pdf">
<Section>
<Graph Height="100" Width="400">
<Rectangle Position="85 100 100 50" />
</Graph>
<Graph Height="100" Width="400" RotationAngle="30">
<Rectangle Position="85 100 100 50" />
</Graph>
<Graph Height="100" Width="400" ScaleRate="1.5 1">
<Rectangle Position="85 100 100 50" />
</Graph>
</Section>
</Pdf>
Note: Rotation and scaling features are applicable on graphs not on individual shapes in a graph.