ByteScout PDF Extractor SDK – C# – SearchablePDFMaker Progress Indication

  • Home
  • /
  • Articles
  • /
  • ByteScout PDF Extractor SDK – C# – SearchablePDFMaker Progress Indication

ByteScout PDF Extractor SDK – C# – SearchablePDFMaker Progress Indication

Program.cs

using System;
using System.Diagnostics;
using Bytescout.PDFExtractor;

namespace SearchablePDFMakerProgressChangedEvent
{
class Program
{
static void Main(string[] args)
{
try
{
using (var searchablePDFMaker = new SearchablePDFMaker(“demo”, “demo”))
{
// Load sample PDF document
searchablePDFMaker.LoadDocumentFromFile(“sample_ocr.pdf”);

// Extractor Progress event
Console.WriteLine(“Searchable PDF making in progress: \n”);
searchablePDFMaker.ProgressChanged += SearchablePDF_ProgressChanged;

// Set the location of “tessdata” folder containing language data files
searchablePDFMaker.OCRLanguageDataFolder = @”c:\Program Files\Bytescout PDF Extractor SDK\Redistributable\net2.00\tessdata\”;

// Set OCR language
searchablePDFMaker.OCRLanguage = “eng”; // “eng” for english, “deu” for German, “fra” for French, “spa” for Spanish etc – according to files in /tessdata

// Set PDF document rendering resolution
searchablePDFMaker.OCRResolution = 300;

// Save extracted text to file
searchablePDFMaker.MakePDFSearchable(“output.pdf”);

// Open result document in default associated application (for demo purpose)
ProcessStartInfo processStartInfo = new ProcessStartInfo(“output.pdf”);
processStartInfo.UseShellExecute = true;
Process.Start(processStartInfo);
}

}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

Console.WriteLine(“\n\n Press enter key to exit…”);
Console.ReadLine();
}

///

/// Handle progress change event
///

private static void SearchablePDF_ProgressChanged(object sender, OngoingOperation ongoingOperation, double progress, ref bool cancel)
{
drawTextProgressBar(Convert.ToInt32(progress), 100);
}

///

/// Display progress bar
///

private static void drawTextProgressBar(int progress, int total)
{
//draw empty progress bar
Console.CursorLeft = 0;
Console.Write(“[“); //start
Console.CursorLeft = 32;
Console.Write(“]”); //end
Console.CursorLeft = 1;
float onechunk = 30.0f / total;

//draw filled part
int position = 1;
for (int i = 0; i < onechunk * progress; i++) { Console.BackgroundColor = ConsoleColor.Green; Console.CursorLeft = position++; Console.Write(" "); } //draw unfilled part for (int i = position; i <= 31; i++) { Console.BackgroundColor = ConsoleColor.Gray; Console.CursorLeft = position++; Console.Write(" "); } //draw totals Console.CursorLeft = 35; Console.BackgroundColor = ConsoleColor.Black; Console.Write(progress.ToString() + " of " + total.ToString() + " "); //blanks at the end remove any excess } } } [/csharp]


  Click here to get your Free Trial version of the SDK

prev
next