How to Add Rectangle or Line Object to An Existing PDF File using .NET
This technical tip shows how .NET developers can add line object to an Existing PDF File inside their .NET applications. Aspose.Pdf for .NET supports the feature to add graph objects (for example graph, line, rectangle etc.) to PDF documents. You also get the leverage to add Line object where you can also specify the dash pattern, color and other formatting for Line element. The legacy Aspose.Pdf.Generator provides the feature to set DashLengthInBlack and DashLengthInWhite properties where dash pattern for line object can be defined. Similar features can be accomplished while using DOM approach.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//your code here...
//The following code snippet shows how to add a Rectangle object that is filled with color.
[C#]
// Create Document instance
Document doc = new Document();
// Add page to pages collection of PDF file
Page page = doc.Pages.Add();
// Create Graph instance
Aspose.Pdf.Drawing.Graph graph = new Aspose.Pdf.Drawing.Graph(100, 400);
// Add graph object to paragraphs collection of page instance
page.Paragraphs.Add(graph);
// Create Rectangle instance
Aspose.Pdf.Drawing.Line line = new Aspose.Pdf.Drawing.Line(new float[]{100, 100, 200, 100});
// Specify fill color for Graph object
line.GraphInfo.DashArray = new int[] { 0, 1, 0 };
line.GraphInfo.DashPhase = 1;
// Add rectangle object to shapes collection of Graph object
graph.Shapes.Add(line);
// Save PDF file
doc.Save("c:/pdftest/LineAdded.pdf");
[VB.NET]
' Create Document instance
Dim doc As Document = New Document()
' Add page to pages collection of PDF file
Dim page As Page = doc.Pages.Add()
' Create Graph instance
Dim graph As Aspose.Pdf.Drawing.Graph = New Aspose.Pdf.Drawing.Graph(100, 400)
' Add graph object to paragraphs collection of page instance
page.Paragraphs.Add(graph)
' Create Rectangle instance
Dim line As Aspose.Pdf.Drawing.Line = New Aspose.Pdf.Drawing.Line(New Single() {100, 100, 200, 100})
' Specify fill color for Graph object
line.GraphInfo.DashArray = New Integer() {0, 1, 0}
line.GraphInfo.DashPhase = 1
' Add rectangle object to shapes collection of Graph object
graph.Shapes.Add(line)
' Save PDF file
doc.Save("c:/pdftest/LineAdded.pdf")
//DashLengthInBlack and DashLengthInWhite properties for Line object
[C#]
X
Url: http://www.aspose.com/.net/pdf-component.aspx
Language: C# | User: Sheraz Khan | Created: Jul 20, 2016 | Tags: add line object to PDF File how to add a Rectangle object add graph objects to PDF File add dash Line pattern .NET PDF API .NET PDF Library fill Rectangle object with color