How to Start Convert PDF Work with PDF Modules PDF Document PDF Pages Text Image Graph & Path Annotation, Markup & Drawing Redaction Security Digital Signature Forms Watermark Bookmark Link File Attachment File Metadata Printing Work with Other SDKs Barcode read Barcode create OCR Twain

VB.NET PDF Viewer Component
How to open, display, add, delete PDF file stamp annotation using vb.net


VB.NET Tutorial for How to Add a Stamp Annotation to PDF Page with Visual basic .net Language in .NET Project. ASP.NET Annotate PDF function is based on .NET PDF Annotate SDK.









  • A best application for annotation PDF document in Visual Basic.NET application and ASP.NET WebForm project
  • Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint
  • Evaluation library and components enable users to annotate PDF without adobe PDF reader control installed
  • Able to add notes to PDF using vb.net source code in Visual Studio .NET framework
  • Allow users to add comments online in ASPX webpage
  • Able to change font size in PDF comment box
  • Able to save and print stamp notes in PDF file


Stamp Annotation is a necessary feature in PDF annotation, which bring users quick and efficient working with PDF Document. RasterEdge XDoc.PDF SDK is a multifunctional PDF document processing tool, which can perform various PDF annotation works in easy ways. Using this .NET PDF annotation control, C# developers can add a sticky note to any position on PDF page.



Since RasterEdge XDoc.PDF SDK is based on .NET framework 2.0, users are enabled to use it in any type of a 32-bit or 64-bit .NET application, including ASP.NET web service and Windows Forms for any .NET Framework version from 2.0 to 4.5.







VB.NET Stamp: Create Template for Stamp Annotation in Visual Basic .NET




With XDoc.PDF library, it is necessary to add PDFStampTemplate through PDFStampTemplateMgr before adding Stamp Annotation to pdf document. Every template has a unique template ID. When adding Stamp Annotation, it will create Stamp Annotation object with ID and responding User Info.


To create a stamp template, the following things are necessary:


      Background image, which will be provided as vector image


      Dynamic Fields, which is responding to User Info properties



What’s more, it has two ways to add background image for Stamp Template:


      Add by PDFContext


      Add from existing PDF file



The properties of Dynamic Field are as follows:


      The area of Stamp Template , RectangleF


      Field Type, which is responding to PDFAnnotStampUserInfo property


      Font, Size, Color





VB.NET prepare a stamp source file (PDF file)


Dim outputFilePath As String = "C:\StampTemplateBg1.pdf"

' initial a region (1 inch in both width And height) in the context for designing a template background
' Region Boundary: [0, 0, 96, 96] (in 96 dpi)
Dim ctx As PDFContext = New PDFContext()
ctx.SetWidth(New RELength(1, Units.IN))
ctx.SetHeight(New RELength(1, Units.IN))

' draw the outer circle
ctx.DrawEllipse(New REPen(Color.Red, 6.0F), 3, 3, 90, 90)
' draw the inner circle
ctx.DrawEllipse(New REPen(Color.Red, 1.0F), 8, 8, 80, 80)
' draw the seperater line
ctx.DrawLine(New REPen(Color.Red, 1.0F), 8, 48, 88, 48)

' output to a file
ctx.SaveToFile(outputFilePath)


Dim outputFilePath As String = "C:\StampTemplateBg2.pdf"

' initial a region in the context for designing a template background
' Region Boundary: [0, 0, 192, 96] (in 96 dpi)
Dim ctx As PDFContext = New PDFContext()
ctx.SetWidth(New RELength(2, Units.IN))
ctx.SetHeight(New RELength(1, Units.IN))

' draw an outer rectangle
ctx.DrawRectangle(New REPen(Color.Red, 6.0F), 3, 3, 186, 90)
' draw an inner rectangle
ctx.DrawRectangle(New REPen(Color.Red, 1.0F), 8, 8, 176, 80)

' output to a file
ctx.SaveToFile(outputFilePath)




VB.NET create a new stamp annotation template from an exist PDF file


Dim sourceFilePath As String = "C:\StampTemplateBg1.pdf"
Dim pageIndex As Integer = 0

' create template by the specified page
Dim template As PDFStampTemplate = PDFStampTemplate.Create(sourceFilePath, pageIndex)

' to add optional dynamic fields for the template ...




VB.NET create a new stamp annotation template by using PDF Context


Dim ctx As PDFContext = New PDFContext()
ctx.SetWidth(New RELength(1.0F, Units.IN))
ctx.SetHeight(New RELength(1.0F, Units.IN))

' draw shapes to context
ctx.DrawEllipse(New REPen(Color.Red, 6.0F), 3, 3, 90, 90)
ctx.DrawEllipse(New REPen(Color.Red, 1.0F), 8, 8, 80, 80)
ctx.DrawLine(New REPen(Color.Red, 1.0F), 8, 48, 88, 48)

' create template by context
Dim template As PDFStampTemplate = PDFStampTemplate.Create(ctx)

' to add optional dynamic fields for the template ...




VB.NET create a stamp annotation template with dynamic fields


Dim ctx As PDFContext = New PDFContext()
ctx.SetWidth(New RELength(1.0F, Units.IN))
ctx.SetHeight(New RELength(1.0F, Units.IN))

' draw shapes to context
ctx.DrawEllipse(New REPen(Color.Red, 6.0F), 3, 3, 90, 90)
ctx.DrawEllipse(New REPen(Color.Red, 1.0F), 8, 8, 80, 80)
ctx.DrawLine(New REPen(Color.Red, 1.0F), 8, 48, 88, 48)

' create template by context
Dim template As PDFStampTemplate = PDFStampTemplate.Create(ctx)

' define a dynamic text field for User Info - Name
Dim field0 As PDFStampTemplateField = New PDFStampTemplateField()
' dynamic text field region in the context
field0.Boundary = New RectangleF(0, 18, 100, 20)
field0.FieldType = PDFStampTemplateFieldType.Name
field0.TextColor = Color.FromArgb(255, 0, 0)
field0.TextFont = New Font("Times New Roman", 10, FontStyle.Regular)
' add the filed
template.AddField(field0)

' define a dynamic text field for User Info - Company
Dim field1 As PDFStampTemplateField = New PDFStampTemplateField()
field1.Boundary = New RectangleF(0, 62, 100, 20)
field1.FieldType = PDFStampTemplateFieldType.Company
field1.TextColor = Color.FromArgb(255, 0, 0)
field1.TextFont = New Font("Times New Roman", 8, FontStyle.Regular)
template.AddField(field1)

' define a dynamic text field for User Info - Current Date Time
Dim field2 As PDFStampTemplateField = New PDFStampTemplateField()
field2.Boundary = New RectangleF(0, 40, 100, 20)
field2.FieldType = PDFStampTemplateFieldType.CurrertDateTime
field2.TextColor = Color.FromArgb(255, 0, 0)
field2.TextFont = New Font("Times New Roman", 6, FontStyle.Regular)
template.AddField(field2)




VB.NET add a new stamp annotation template


//  …create a stamp annotation template …
PDFStampTemplate template = PDFStampTemplate.Create("", 0);

//  template ID must be unique in the SDK
String templateID = "Template 1";
//  add new template to the SDK
PDFStampTemplateMgr.AddTemplate(templateID, template, false);

if (PDFStampTemplateMgr.IsTemplateExist(templateID))
{
    Console.WriteLine("Template Exist");
    //  get preview of a template with a given size
    Bitmap preview = PDFStampTemplateMgr.GetTemplatePreview(templateID, new Size(300, 300));
}
else
{
    Console.WriteLine("Template Dost Not Exist");
}




VB.NET add a stamp annotation to page


Dim inputFilePath As String = "C:\1.pdf"
Dim outputFilePath As String = "C:\1_Annots.pdf"

' Create a stamp annotation
Dim annot As PDFAnnotStamp = New PDFAnnotStamp()
' select stamp template by the template ID
Dim templateID As String = "Template 1"
annot.StampTemplateID = templateID
' set annotation position And size
annot.Boundary = New RectangleF(300, 300, 50, 50)

' set user info
annot.UserInfo.Company = "XYZ Ltd."
annot.UserInfo.FamilyName = "Kitty"
annot.UserInfo.GivenName = "Hello"

' other annotation properties
annot.Opacity = 1.0
annot.PageIndex = 0

' add annotation
PDFAnnotHandler.AddAnnotation(inputFilePath, annot, outputFilePath)




VB.NET retrieve annotation popup note window's properties


Dim inputFilePath As String = "C:\Annot_1.pdf"

Dim doc As PDFDocument = New PDFDocument(inputFilePath)
Dim annots As List(Of IPDFAnnot) = PDFAnnotHandler.GetAllAnnotations(doc)
For Each annot As IPDFAnnot In annots
    If TypeOf annot Is IPDFPopupAnnot Then
        Console.WriteLine("Annotation has popup window")

        Dim obj As IPDFPopupAnnot = annot
        Console.WriteLine("Is open in the begin:  {0}", obj.Popup.IsOpen)
        Console.WriteLine("Popup window boundary: {0}", obj.Popup.Boundary.ToString())
    Else
        Console.WriteLine("Annotation has no popup window")
    End If
Next




VB.NET retrieve annotation flags


Dim inputFilePath As String = "C:\Annot_1.pdf"

Dim doc As PDFDocument = New PDFDocument(inputFilePath)
Dim annots As List(Of IPDFAnnot) = PDFAnnotHandler.GetAllAnnotations(doc)
For Each annot As IPDFAnnot In annots
    Console.WriteLine("Annotation Flags")
    Console.WriteLine("  Invisible:       {0}", annot.IsInvisible)
    Console.WriteLine("  Hidden:          {0}", annot.IsHidden)
    Console.WriteLine("  Print:           {0}", annot.IsPrint)
    Console.WriteLine("  No Zoom:         {0}", annot.NoZoom)
    Console.WriteLine("  No Rotate:       {0}", annot.NoRotate)
    Console.WriteLine("  No View:         {0}", annot.NoView)
    Console.WriteLine("  Read Only:       {0}", annot.IsReadOnly)
    Console.WriteLine("  Locked:          {0}", annot.IsLocked)
    Console.WriteLine("  Toggle No View:  {0}", annot.IsToggleNoView)
    Console.WriteLine("  Locked Contents: {0}", annot.IsLockedContents)
Next




VB.NET set annotation flags


Dim inputFilePath As String = "C:\2.pdf"
Dim outputFilePath As String = "C:\Annot_1.pdf"

' create the annotation
Dim annot As PDFAnnotDeleteLine = New PDFAnnotDeleteLine()
annot.StartPoint = New PointF(100.0F, 200.0F)
annot.EndPoint = New PointF(300.0F, 400.0F)

' set annotation flags
annot.IsInvisible = False
annot.IsPrint = True
annot.NoRotate = True
annot.NoZoom = True

' add annotation
PDFAnnotHandler.AddAnnotation(inputFilePath, 1, annot, outputFilePath)