ByteScout PDF Viewer SDK - VB.NET - Get Selection Points with PDF Viewer UI Application - ByteScout
Announcement
Our ByteScout SDK products are sunsetting as we focus on expanding new solutions.
Learn More Open modal
Close modal
Announcement Important Update
ByteScout SDK Sunsetting Notice
Our ByteScout SDK products are sunsetting as we focus on our new & improved solutions. Thank you for being part of our journey, and we look forward to supporting you in this next chapter!

ByteScout PDF Viewer SDK – VB.NET – Get Selection Points with PDF Viewer UI Application

  • Home
  • /
  • Articles
  • /
  • ByteScout PDF Viewer SDK – VB.NET – Get Selection Points with PDF Viewer UI Application

How to get selection points with PDF viewer UI application in VB.NET with ByteScout PDF Viewer SDK

Write code in VB.NET to get selection points with PDF viewer UI application with this step-by-step tutorial

The coding tutorials are designed to help you test the features without need to write your own code. ByteScout PDF Viewer SDK is the component that helps in adding pdf viewer into your desktop WinForms application. User may select multiple areas with mouse, can use keyboard shortcuts and zoom in or zoom out and change scaling. You may read coordinates, handle custom painting code and retrieve text inside selection area. It can get selection points with PDF viewer UI application in VB.NET.

This rich sample source code in VB.NET for ByteScout PDF Viewer SDK includes the number of functions and options you should do calling the API to get selection points with PDF viewer UI application. Follow the instructions from the scratch to work and copy the VB.NET code. Enjoy writing a code with ready-to-use sample codes in VB.NET.

You can download free trial version of ByteScout PDF Viewer SDK from our website to see and try many others source code samples for VB.NET.

On-demand (REST Web API) version:
 Web API (on-demand version)

On-premise offline SDK for Windows:
 60 Day Free Trial (on-premise)

Form1.Designer.vb
      
Partial Class Form1 ''' <summary> ''' Required designer variable. ''' </summary> Private components As System.ComponentModel.IContainer = Nothing ''' <summary> ''' Clean up any resources being used. ''' </summary> ''' <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> Protected Overrides Sub Dispose(disposing As Boolean) If disposing AndAlso (components IsNot Nothing) Then components.Dispose() End If MyBase.Dispose(disposing) End Sub #Region "Windows Form Designer generated code" ''' <summary> ''' Required method for Designer support - do not modify ''' the contents of this method with the code editor. ''' </summary> Private Sub InitializeComponent() Me.tsbOpen = New System.Windows.Forms.ToolStripButton() Me.toolStrip1 = New System.Windows.Forms.ToolStrip() Me.pdfViewerControl1 = New Bytescout.PDFViewer.PDFViewerControl() Me.txtSelectionPixel = New System.Windows.Forms.TextBox() Me.txtSelectionPDFUnit = New System.Windows.Forms.TextBox() Me.label2 = New System.Windows.Forms.Label() Me.label1 = New System.Windows.Forms.Label() Me.btnGetSelectionPoints = New System.Windows.Forms.Button() Me.toolStrip1.SuspendLayout() Me.SuspendLayout() ' 'tsbOpen ' Me.tsbOpen.Image = Global.Sample_UI_Application.My.Resources.Resources.folder_page Me.tsbOpen.ImageTransparentColor = System.Drawing.Color.Magenta Me.tsbOpen.Name = "tsbOpen" Me.tsbOpen.Size = New System.Drawing.Size(99, 24) Me.tsbOpen.Text = "&Open PDF" ' 'toolStrip1 ' Me.toolStrip1.ImageScalingSize = New System.Drawing.Size(20, 20) Me.toolStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.tsbOpen}) Me.toolStrip1.Location = New System.Drawing.Point(0, 0) Me.toolStrip1.Name = "toolStrip1" Me.toolStrip1.Size = New System.Drawing.Size(1240, 27) Me.toolStrip1.TabIndex = 1 Me.toolStrip1.Text = "toolStrip1" ' 'pdfViewerControl1 ' Me.pdfViewerControl1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _ Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.pdfViewerControl1.BackColor = System.Drawing.SystemColors.ButtonShadow Me.pdfViewerControl1.Location = New System.Drawing.Point(0, 129) Me.pdfViewerControl1.Margin = New System.Windows.Forms.Padding(4) Me.pdfViewerControl1.MouseMode = Bytescout.PDFViewer.MouseMode.Selection Me.pdfViewerControl1.Name = "pdfViewerControl1" Me.pdfViewerControl1.RegistrationKey = Nothing Me.pdfViewerControl1.RegistrationName = Nothing Me.pdfViewerControl1.ResetRotationOnPageChange = False Me.pdfViewerControl1.Scale = 100 Me.pdfViewerControl1.SelectionColor = System.Drawing.Color.Red Me.pdfViewerControl1.ShowImageObjects = True Me.pdfViewerControl1.ShowTextObjects = True Me.pdfViewerControl1.ShowVectorObjects = True Me.pdfViewerControl1.Size = New System.Drawing.Size(1240, 532) Me.pdfViewerControl1.TabIndex = 0 ' 'txtSelectionPixel ' Me.txtSelectionPixel.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.txtSelectionPixel.Location = New System.Drawing.Point(470, 84) Me.txtSelectionPixel.Multiline = True Me.txtSelectionPixel.Name = "txtSelectionPixel" Me.txtSelectionPixel.ReadOnly = True Me.txtSelectionPixel.Size = New System.Drawing.Size(761, 25) Me.txtSelectionPixel.TabIndex = 11 ' 'txtSelectionPDFUnit ' Me.txtSelectionPDFUnit.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.txtSelectionPDFUnit.Location = New System.Drawing.Point(470, 40) Me.txtSelectionPDFUnit.Multiline = True Me.txtSelectionPDFUnit.Name = "txtSelectionPDFUnit" Me.txtSelectionPDFUnit.ReadOnly = True Me.txtSelectionPDFUnit.Size = New System.Drawing.Size(761, 25) Me.txtSelectionPDFUnit.TabIndex = 10 ' 'label2 ' Me.label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, CType((System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Underline), System.Drawing.FontStyle), System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.label2.Location = New System.Drawing.Point(187, 84) Me.label2.Name = "label2" Me.label2.RightToLeft = System.Windows.Forms.RightToLeft.Yes Me.label2.Size = New System.Drawing.Size(277, 25) Me.label2.TabIndex = 9 Me.label2.Text = "Selection in Pixels" ' 'label1 ' Me.label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, CType((System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Underline), System.Drawing.FontStyle), System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.label1.Location = New System.Drawing.Point(187, 40) Me.label1.Name = "label1" Me.label1.RightToLeft = System.Windows.Forms.RightToLeft.Yes Me.label1.Size = New System.Drawing.Size(277, 25) Me.label1.TabIndex = 8 Me.label1.Text = "Selection in PDF Units" ' 'btnGetSelectionPoints ' Me.btnGetSelectionPoints.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.btnGetSelectionPoints.Location = New System.Drawing.Point(9, 40) Me.btnGetSelectionPoints.Name = "btnGetSelectionPoints" Me.btnGetSelectionPoints.Size = New System.Drawing.Size(172, 69) Me.btnGetSelectionPoints.TabIndex = 7 Me.btnGetSelectionPoints.Text = "Get Selection Points" Me.btnGetSelectionPoints.UseVisualStyleBackColor = True ' 'Form1 ' Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 16.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(1240, 663) Me.Controls.Add(Me.txtSelectionPixel) Me.Controls.Add(Me.txtSelectionPDFUnit) Me.Controls.Add(Me.label2) Me.Controls.Add(Me.label1) Me.Controls.Add(Me.btnGetSelectionPoints) Me.Controls.Add(Me.pdfViewerControl1) Me.Controls.Add(Me.toolStrip1) Me.Margin = New System.Windows.Forms.Padding(4) Me.Name = "Form1" Me.Text = "Form1" Me.toolStrip1.ResumeLayout(False) Me.toolStrip1.PerformLayout() Me.ResumeLayout(False) Me.PerformLayout() End Sub Private WithEvents tsbOpen As Windows.Forms.ToolStripButton Private WithEvents toolStrip1 As Windows.Forms.ToolStrip Private WithEvents pdfViewerControl1 As Bytescout.PDFViewer.PDFViewerControl Private WithEvents txtSelectionPixel As Windows.Forms.TextBox Private WithEvents txtSelectionPDFUnit As Windows.Forms.TextBox Private WithEvents label2 As Windows.Forms.Label Private WithEvents label1 As Windows.Forms.Label Private WithEvents btnGetSelectionPoints As Windows.Forms.Button #End Region End Class

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Viewer SDK Home Page

Explore ByteScout PDF Viewer SDK Documentation

Explore Samples

Sign Up for ByteScout PDF Viewer SDK Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Form1.vb
      
Imports System.Drawing Imports System.Windows.Forms Partial Public Class Form1 Inherits Form Public Sub New() InitializeComponent() ' Assign default document pdfViewerControl1.InputFile = "sample.pdf" ' Initially set selection pdfViewerControl1.Selection = New Rectangle() {New Rectangle(20, 20, 100, 100)} ' Get Selection Information GetSelectionInformation() End Sub Private Sub tsbOpen_Click(ByVal sender As Object, ByVal e As EventArgs) Handles tsbOpen.Click Using openFileDialog As New OpenFileDialog() openFileDialog.Title = "Open PDF Document" openFileDialog.Filter = "PDF Files (*.pdf)|*.pdf|All Files|*.*" If openFileDialog.ShowDialog() = DialogResult.OK Then Me.Text = openFileDialog.FileName Cursor = Cursors.WaitCursor Try pdfViewerControl1.InputFile = openFileDialog.FileName Catch exception As Exception MessageBox.Show(exception.Message) Finally Cursor = Cursors.[Default] End Try End If End Using End Sub Private Sub btnGetSelectionPoints_Click(sender As Object, e As EventArgs) Handles btnGetSelectionPoints.Click GetSelectionInformation() End Sub Private Sub GetSelectionInformation() If pdfViewerControl1.SelectionInPoints.Length > 0 Then ' If need to get selection in PDF format then use .SelectionInPoints that returns coordinates in PDF points. ' PDF points can be used with other SDK to extract text, draw on pdf, add text, images etc. ' These PDF points coordinates are staying the same with any rendering resolution for PDF because resolution affects only how pdf Is converted into displaying image. Dim selectionInPoints As RectangleF = pdfViewerControl1.SelectionInPoints(0) txtSelectionPDFUnit.Text = String.Format("Top={0}, Left={1}, Bottom={2}, Right={3}, Width={4}, Height={5}", selectionInPoints.Top, selectionInPoints.Left, selectionInPoints.Bottom, selectionInPoints.Right, selectionInPoints.Width, selectionInPoints.Height) ' If you need to draw on screen on the control then please use .Selection property to get coordinates. Dim selectionInPixels As RectangleF = pdfViewerControl1.Selection(0) txtSelectionPixel.Text = String.Format("Top={0}, Left={1}, Bottom={2}, Right={3}, Width={4}, Height={5}", selectionInPixels.Top.ToString(), selectionInPixels.Left.ToString(), selectionInPixels.Bottom.ToString(), selectionInPixels.Right.ToString(), selectionInPixels.Width, selectionInPixels.Height) Else MessageBox.Show("Selection not available.") End If End Sub End Class

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Viewer SDK Home Page

Explore ByteScout PDF Viewer SDK Documentation

Explore Samples

Sign Up for ByteScout PDF Viewer SDK Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Program.vb
      
Imports System.Collections.Generic Imports System.Windows.Forms NotInheritable Class Program Private Sub New() End Sub ''' <summary> ''' The main entry point for the application. ''' </summary> <STAThread> _ Friend Shared Sub Main() Application.EnableVisualStyles() Application.SetCompatibleTextRenderingDefault(False) Application.Run(New Form1()) End Sub End Class

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Viewer SDK Home Page

Explore ByteScout PDF Viewer SDK Documentation

Explore Samples

Sign Up for ByteScout PDF Viewer SDK Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

VIDEO

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Viewer SDK Home Page

Explore ByteScout PDF Viewer SDK Documentation

Explore Samples

Sign Up for ByteScout PDF Viewer SDK Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

prev
next