Sample source code below will display you how to manage a complex task like remove text from selected regions in C#. Want to remove text from selected regions in your C# app? ByteScout Premium Suite is designed for it. ByteScout Premium Suite is the set that includes 12 SDK products from ByteScout including tools and components for PDF, barcodes, spreadsheets, screen video recording.
This prolific sample source code in C# for ByteScout Premium Suite contains various functions and other necessary options you should do calling the API to remove text from selected regions. IF you want to implement the functionality, just copy and paste this code for C# below into your code editor with your app, compile and run your application. Check C# sample code samples to see if they respond to your needs and requirements for the project.
ByteScout provides the free trial version of ByteScout Premium Suite along with the 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)
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.btnRemoveTextInSelectedRegions = new System.Windows.Forms.Button(); 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, 70); 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, 662); this.pdfViewerControl1.TabIndex = 0; this.pdfViewerControl1.CurrentPageIndexChanged += new System.EventHandler(this.PdfViewerControl1_CurrentPageIndexChanged); this.pdfViewerControl1.SelectionChanged += new Bytescout.PDFViewer.SelectionChangedEventHandler(this.PdfViewerControl1_SelectionChanged); // // 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.ImageTransparentColor = System.Drawing.Color.Magenta; this.tsbOpen.Name = "tsbOpen"; this.tsbOpen.Size = new System.Drawing.Size(79, 24); this.tsbOpen.Text = "&Open PDF"; this.tsbOpen.Click += new System.EventHandler(this.tsbOpen_Click); // // btnRemoveTextInSelectedRegions // this.btnRemoveTextInSelectedRegions.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnRemoveTextInSelectedRegions.Location = new System.Drawing.Point(0, 30); this.btnRemoveTextInSelectedRegions.Name = "btnRemoveTextInSelectedRegions"; this.btnRemoveTextInSelectedRegions.Size = new System.Drawing.Size(407, 33); this.btnRemoveTextInSelectedRegions.TabIndex = 2; this.btnRemoveTextInSelectedRegions.Text = "Remove Text in Selected Regions"; this.btnRemoveTextInSelectedRegions.UseVisualStyleBackColor = true; this.btnRemoveTextInSelectedRegions.Click += new System.EventHandler(this.BtnRemoveTextInSelectedRegions_Click); // // 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.btnRemoveTextInSelectedRegions); 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 btnRemoveTextInSelectedRegions; } }
60 Day Free Trial or Visit ByteScout Premium Suite Home Page
Explore ByteScout Premium Suite Documentation
Explore Samples
Sign Up for ByteScout Premium Suite Online Training
Get Your API Key
Explore Web API Docs
Explore Web API Samples
using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Windows.Forms; using Bytescout.PDFExtractor; using Bytescout.PDFViewer; namespace Sample_UI_Application { public partial class Form1 : Form { // Dictionary to keep selected rectangles for all document pages private readonly Dictionary<int, RectangleF[]> _dictPageWiseRectangles = new Dictionary<int, RectangleF[]>(); public Form1() { InitializeComponent(); // Load sample document into PDF Viewer control pdfViewerControl1.InputFile = "sample.pdf"; // Tune PDF Viewer control pdfViewerControl1.MouseMode = MouseMode.Selection; pdfViewerControl1.MultiSelectMode = true; pdfViewerControl1.AllowResizeSelectionRectangles = true; pdfViewerControl1.ShowResizeHandlesForActiveSelectionOnly = true; } 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 BtnRemoveTextInSelectedRegions_Click(object sender, EventArgs e) { using (Remover2 remover = new Remover2("demo", "demo")) { remover.LoadDocumentFromFile(pdfViewerControl1.InputFile); foreach (KeyValuePair<int, RectangleF[]> keyValuePair in _dictPageWiseRectangles) remover.AddTextToRemove(keyValuePair.Key, keyValuePair.Value); // Remove text from all selected rectangles remover.PerformRemoval("output.pdf"); } pdfViewerControl1.CurrentPageIndex = 0; MessageBox.Show("Output file created successfully!", "Success"); // Open output file Process.Start("output.pdf"); } private void PdfViewerControl1_SelectionChanged(object sender, SelectionChange selectionChange, int selectionIndex) { // Store selection changes if (selectionChange != SelectionChange.Cleared) { _dictPageWiseRectangles[pdfViewerControl1.CurrentPageIndex] = pdfViewerControl1.SelectionInPoints; } } private void PdfViewerControl1_CurrentPageIndexChanged(object sender, EventArgs e) { // Show stored selection on page switching if (_dictPageWiseRectangles.ContainsKey(pdfViewerControl1.CurrentPageIndex)) { pdfViewerControl1.SelectionInPoints = _dictPageWiseRectangles[pdfViewerControl1.CurrentPageIndex]; } } } }
60 Day Free Trial or Visit ByteScout Premium Suite Home Page
Explore ByteScout Premium Suite Documentation
Explore Samples
Sign Up for ByteScout Premium Suite Online Training
Get Your API Key
Explore Web API Docs
Explore Web API Samples
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()); } } }
60 Day Free Trial or Visit ByteScout Premium Suite Home Page
Explore ByteScout Premium Suite Documentation
Explore Samples
Sign Up for ByteScout Premium Suite Online Training
Get Your API Key
Explore Web API Docs
Explore Web API Samples
60 Day Free Trial or Visit ByteScout Premium Suite Home Page
Explore ByteScout Premium Suite Documentation
Explore Samples
Sign Up for ByteScout Premium Suite Online Training
Get Your API Key
Explore Web API Docs
Explore Web API Samples
also available as: