|
VB.NET PDF Reader Library
How to show, display, add, delete, update PDF file drawings & shapes in vb.net, winform, wpf, asp.net
Sample Codes for VB.NET Users to draw shapes annotations on PDF in VB.NET Class.
ASP.NET Annotate PDF function is based on .net PDF Annotate SDK.
RasterEdge VB.NET PDF Drawing SDK enables users with the capabilities to draw and write text and graphics on single or multiple PDF document page(s) within Windows or
Web imaging application in Visual VB.NET class. With our offered API solutions,
VB developers and end users are able to write text and graphics contents on all the selected PDF pages at the same time, and the relevant properties, like font size, algorithm,
horizontal and vertical positions can be predetermined by using online VB.ENT sample code.
VB.NET add path & shape annotation to pdf document
Dim inputFilePath As String = Program.RootPath + "\\" + "2.pdf"
Dim outputFilePath As String = Program.RootPath + "\\" + "Annot_6.pdf"
' open a PDF file
Dim doc As PDFDocument = New PDFDocument(inputFilePath)
' get the 1st page
Dim page As PDFPage = doc.GetPage(0)
' create the annotation
Dim annot0 As PDFAnnotLine = New PDFAnnotLine()
annot0.Start = New PointF(100.0F, 100.0F)
annot0.End = New PointF(200.0F, 200.0F)
' add annotation to the page
PDFAnnotHandler.AddAnnotation(page, annot0)
' create the annotation
Dim annot1 As PDFAnnotArrow = New PDFAnnotArrow()
annot1.Start = New PointF(300.0F, 100.0F)
annot1.End = New PointF(400.0F, 150.0F)
' add annotation to the page
PDFAnnotHandler.AddAnnotation(page, annot1)
' create the annotation
Dim annot2 As PDFAnnotEllipse = New PDFAnnotEllipse()
With annot2
.Location = New PointF(300, 300)
.Width = 50.0F
.Height = 50.0F
End With
' add annotation to the page
PDFAnnotHandler.AddAnnotation(page, annot2)
' create the annotation
Dim annot3 As PDFAnnotRectangle = New PDFAnnotRectangle()
With annot3
.Location = New PointF(400, 400)
.Width = 50.0F
.Height = 50.0F
End With
' add annotation to the page
PDFAnnotHandler.AddAnnotation(page, annot3)
' create the annotation
Dim annot4 As PDFAnnotPolygon = New PDFAnnotPolygon()
Dim elem0(4) As PointF
annot4.Points = elem0
With annot4
.Points(0) = New PointF(50.0F, 450.0F)
.Points(1) = New PointF(100.0F, 450.0F)
.Points(2) = New PointF(120.0F, 480.0F)
.Points(3) = New PointF(100.0F, 500.0F)
.Points(4) = New PointF(50.0F, 500.0F)
End With
' add annotation to the page
PDFAnnotHandler.AddAnnotation(page, annot4)
' create the annotation
Dim annot5 As PDFAnnotPolyline = New PDFAnnotPolyline()
Dim elem1(4) As PointF
annot5.Points = elem1
With annot5
.Points(0) = New PointF(250.0F, 450.0F)
.Points(1) = New PointF(300.0F, 450.0F)
.Points(2) = New PointF(320.0F, 480.0F)
.Points(3) = New PointF(300.0F, 500.0F)
.Points(4) = New PointF(250.0F, 500.0F)
End With
' add annotation to the page
PDFAnnotHandler.AddAnnotation(page, annot5)
' save to a new file
doc.Save(outputFilePath)
VB.NET read path & shape annotation from pdf document
Dim inputFilePath As String = Program.RootPath + "\\" + "Annot_6.pdf"
Dim doc As PDFDocument = New PDFDocument(inputFilePath)
Dim annots = PDFAnnotHandler.GetAllAnnotations(doc)
For Each annot As IPDFAnnot In annots
If TypeOf annot Is PDFAnnotLine Then
Dim obj As PDFAnnotLine = annot
Console.WriteLine("Line Annotation: ")
Console.WriteLine("Start Point: " + obj.Start.ToString())
Console.WriteLine("End Point: " + obj.End.ToString())
Console.WriteLine("Line Color: " + obj.LineColor.ToString())
Console.WriteLine("Line Width: {0}", obj.LineWidth)
ElseIf TypeOf annot Is PDFAnnotArrow Then
Dim obj As PDFAnnotArrow = annot
Console.WriteLine("Arrow Annotation: ")
Console.WriteLine("Start Point: " + obj.Start.ToString())
Console.WriteLine("End Point: " + obj.End.ToString())
Console.WriteLine("Line Color: " + obj.LineColor.ToString())
Console.WriteLine("Line Width: {0}", obj.LineWidth)
ElseIf TypeOf annot Is PDFAnnotEllipse Then
Dim obj As PDFAnnotEllipse = annot
Console.WriteLine("Ellipse Annotation: ")
Console.WriteLine("Location: " + obj.Location.ToString())
Console.WriteLine("Width: {0}", obj.Width)
Console.WriteLine("Height: {0}", obj.Height)
Console.WriteLine("Line Color: " + obj.LineColor.ToString())
Console.WriteLine("Line Width: {0}", obj.LineWidth)
Console.WriteLine("Fill Color: " + obj.FillColor.ToString())
ElseIf TypeOf annot Is PDFAnnotRectangle Then
Dim obj As PDFAnnotRectangle = annot
Console.WriteLine("Rectangle Annotation: ")
Console.WriteLine("Location: " + obj.Location.ToString())
Console.WriteLine("Width: {0}", obj.Width)
Console.WriteLine("Height: {0}", obj.Height)
Console.WriteLine("Line Color: " + obj.LineColor.ToString())
Console.WriteLine("Line Width: {0}", obj.LineWidth)
Console.WriteLine("Fill Color: " + obj.FillColor.ToString())
ElseIf TypeOf annot Is PDFAnnotPolygon Then
Dim obj As PDFAnnotPolygon = annot
Console.WriteLine("Polygon Annotation: ")
Console.WriteLine("End Points: ")
For Each pt As PointF In obj.Points
Console.WriteLine(" " + pt.ToString())
Next
Console.WriteLine("Line Color: " + obj.LineColor.ToString())
Console.WriteLine("Line Width: {0}", obj.LineWidth)
Console.WriteLine("Fill Color: " + obj.FillColor.ToString())
ElseIf TypeOf annot Is PDFAnnotPolyline Then
Dim obj As PDFAnnotPolyline = annot
Console.WriteLine("Polyline Annotation: ")
Console.WriteLine("End Points: ")
For Each pt As PointF In obj.Points
Console.WriteLine(" " + pt.ToString())
Next
Console.WriteLine("Line Color: " + obj.LineColor.ToString())
Console.WriteLine("Line Width: {0}", obj.LineWidth)
Console.WriteLine("Fill Color: " + obj.FillColor.ToString())
ElseIf TypeOf annot Is PDFAnnotPen Then
Dim obj As PDFAnnotPen = annot
Console.WriteLine("Pen Annotation: ")
Console.WriteLine("Points: ")
For Each pt As PointF In obj.Points
Console.WriteLine(" " + pt.ToString())
Next
Console.WriteLine("Line Color: " + obj.LineColor.ToString())
Console.WriteLine("Line Width: {0}", obj.LineWidth)
Console.WriteLine("Path: " + obj.Path.ToString())
End If
Next
VB.NET delete all annotations from pdf document
Dim inputFilePath As String = "C:\1_Annots.pdf"
Dim doc As PDFDocument = New PDFDocument(inputFilePath)
' get all annotations in the 1st page
Dim page As PDFPage = doc.GetPage(0)
Dim annots = PDFAnnotHandler.GetAllAnnotations(page)
' remove all annotations in the 1st page
PDFAnnotHandler.DeleteAnnotation(doc, annots)
|