ByteScout PDF Suite - C# - Get Selection Points with PDF Viewer UI Application with PDF Viewer SDK - 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 Suite – C# – Get Selection Points with PDF Viewer UI Application with PDF Viewer SDK

  • Home
  • /
  • Articles
  • /
  • ByteScout PDF Suite – C# – Get Selection Points with PDF Viewer UI Application with PDF Viewer SDK

How to get selection points with PDF viewer UI application with PDF viewer SDK in C# using ByteScout PDF Suite

Continuous learning is a crucial part of computer science and this tutorial shows how to get selection points with PDF viewer UI application with PDF viewer SDK in C#

The sample source code below will teach you how to get selection points with PDF viewer UI application with PDF viewer SDK in C#. Want to get selection points with PDF viewer UI application with PDF viewer SDK in your C# app? ByteScout PDF Suite is designed for it. ByteScout PDF Suite is the bundle that provides six different SDK libraries to work with PDF from generating rich PDF reports to extracting data from PDF documents and converting them to HTML. This bundle includes PDF (Generator) SDK, PDF Renderer SDK, PDF Extractor SDK, PDF to HTML SDK, PDF Viewer SDK and PDF Generator SDK for Javascript.

Want to quickly learn? This fast application programming interfaces of ByteScout PDF Suite for C# plus the guidelines and the code below will help you quickly learn how to get selection points with PDF viewer UI application with PDF viewer SDK. Just copy and paste the code into your C# application’s code and follow the instructions. Enjoy writing a code with ready-to-use sample codes in C#.

Our website gives trial version of ByteScout PDF Suite for free. It also includes documentation and source code samples.

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.cs
      
namespace Sample_UI_Application { partial class Form1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #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 void InitializeComponent() { this.pdfViewerControl1 = new Bytescout.PDFViewer.PDFViewerControl(); this.toolStrip1 = new System.Windows.Forms.ToolStrip(); this.tsbOpen = new System.Windows.Forms.ToolStripButton(); this.btnGetSelectionPoints = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.txtSelectionPDFUnit = new System.Windows.Forms.TextBox(); this.txtSelectionPixel = new System.Windows.Forms.TextBox(); this.toolStrip1.SuspendLayout(); this.SuspendLayout(); // // pdfViewerControl1 // this.pdfViewerControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.pdfViewerControl1.BackColor = System.Drawing.SystemColors.ButtonShadow; this.pdfViewerControl1.Location = new System.Drawing.Point(-13, 127); this.pdfViewerControl1.Margin = new System.Windows.Forms.Padding(4); this.pdfViewerControl1.MouseMode = Bytescout.PDFViewer.MouseMode.Selection; this.pdfViewerControl1.Name = "pdfViewerControl1"; this.pdfViewerControl1.RegistrationKey = null; this.pdfViewerControl1.RegistrationName = null; this.pdfViewerControl1.ResetRotationOnPageChange = false; this.pdfViewerControl1.Scale = 100; this.pdfViewerControl1.SelectionColor = System.Drawing.Color.Red; this.pdfViewerControl1.ShowImageObjects = true; this.pdfViewerControl1.ShowTextObjects = true; this.pdfViewerControl1.ShowVectorObjects = true; this.pdfViewerControl1.Size = new System.Drawing.Size(1240, 605); this.pdfViewerControl1.TabIndex = 0; // // toolStrip1 // this.toolStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.tsbOpen}); this.toolStrip1.Location = new System.Drawing.Point(0, 0); this.toolStrip1.Name = "toolStrip1"; this.toolStrip1.Size = new System.Drawing.Size(1240, 27); this.toolStrip1.TabIndex = 1; this.toolStrip1.Text = "toolStrip1"; // // tsbOpen // this.tsbOpen.Image = global::Sample_UI_Application.Properties.Resources.folder_page; this.tsbOpen.ImageTransparentColor = System.Drawing.Color.Magenta; this.tsbOpen.Name = "tsbOpen"; this.tsbOpen.Size = new System.Drawing.Size(99, 24); this.tsbOpen.Text = "&Open PDF"; this.tsbOpen.Click += new System.EventHandler(this.tsbOpen_Click); // // btnGetSelectionPoints // this.btnGetSelectionPoints.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnGetSelectionPoints.Location = new System.Drawing.Point(5, 41); this.btnGetSelectionPoints.Name = "btnGetSelectionPoints"; this.btnGetSelectionPoints.Size = new System.Drawing.Size(172, 69); this.btnGetSelectionPoints.TabIndex = 2; this.btnGetSelectionPoints.Text = "Get Selection Points"; this.btnGetSelectionPoints.UseVisualStyleBackColor = true; this.btnGetSelectionPoints.Click += new System.EventHandler(this.btnGetSelectionPoints_Click); // // label1 // this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Underline))), System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label1.Location = new System.Drawing.Point(183, 41); this.label1.Name = "label1"; this.label1.RightToLeft = System.Windows.Forms.RightToLeft.Yes; this.label1.Size = new System.Drawing.Size(277, 25); this.label1.TabIndex = 3; this.label1.Text = "Selection in PDF Units"; // // label2 // this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Underline))), System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label2.Location = new System.Drawing.Point(183, 85); this.label2.Name = "label2"; this.label2.RightToLeft = System.Windows.Forms.RightToLeft.Yes; this.label2.Size = new System.Drawing.Size(277, 25); this.label2.TabIndex = 4; this.label2.Text = "Selection in Pixels"; // // txtSelectionPDFUnit // this.txtSelectionPDFUnit.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.txtSelectionPDFUnit.Location = new System.Drawing.Point(466, 41); this.txtSelectionPDFUnit.Multiline = true; this.txtSelectionPDFUnit.Name = "txtSelectionPDFUnit"; this.txtSelectionPDFUnit.ReadOnly = true; this.txtSelectionPDFUnit.Size = new System.Drawing.Size(761, 25); this.txtSelectionPDFUnit.TabIndex = 5; // // txtSelectionPixel // this.txtSelectionPixel.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.txtSelectionPixel.Location = new System.Drawing.Point(466, 85); this.txtSelectionPixel.Multiline = true; this.txtSelectionPixel.Name = "txtSelectionPixel"; this.txtSelectionPixel.ReadOnly = true; this.txtSelectionPixel.Size = new System.Drawing.Size(761, 25); this.txtSelectionPixel.TabIndex = 6; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1240, 663); this.Controls.Add(this.txtSelectionPixel); this.Controls.Add(this.txtSelectionPDFUnit); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Controls.Add(this.btnGetSelectionPoints); this.Controls.Add(this.pdfViewerControl1); this.Controls.Add(this.toolStrip1); this.Margin = new System.Windows.Forms.Padding(4); this.Name = "Form1"; this.Text = "Form1"; this.toolStrip1.ResumeLayout(false); this.toolStrip1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } #endregion private Bytescout.PDFViewer.PDFViewerControl pdfViewerControl1; private System.Windows.Forms.ToolStrip toolStrip1; private System.Windows.Forms.ToolStripButton tsbOpen; private System.Windows.Forms.Button btnGetSelectionPoints; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox txtSelectionPDFUnit; private System.Windows.Forms.TextBox txtSelectionPixel; } }

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Form1.cs
      
using System; using System.Drawing; using System.Windows.Forms; namespace Sample_UI_Application { public partial class Form1 : Form { public Form1() { 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(); } private void tsbOpen_Click(object sender, EventArgs e) { using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.Title = @"Open PDF Document"; openFileDialog.Filter = @"PDF Files (*.pdf)|*.pdf|All Files|*.*"; if (openFileDialog.ShowDialog() == DialogResult.OK) { this.Text = openFileDialog.FileName; Cursor = Cursors.WaitCursor; try { pdfViewerControl1.InputFile = openFileDialog.FileName; } catch (Exception exception) { MessageBox.Show(exception.Message); } finally { Cursor = Cursors.Default; } } } } private void btnGetSelectionPoints_Click(object sender, EventArgs e) { GetSelectionInformation(); } private void GetSelectionInformation() { if (pdfViewerControl1.SelectionInPoints.Length > 0) { // 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. RectangleF selectionInPoints = 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. RectangleF selectionInPixels = 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."); } } } }

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Program.cs
      
using System; using System.Collections.Generic; using System.Windows.Forms; namespace Sample_UI_Application { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } }

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF Suite 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 Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next