Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Friday, August 18, 2017 3:54:33 PM(UTC)
Nick Villalobos

Groups: Registered
Posts: 119

Was thanked: 4 time(s) in 4 post(s)

When wanting to convert an image to a PDF with the text on the page being searchable, you will need to use the ImageOverText Property to make sure that your output maintains the same layout as your original image.

This property uses a raster image overlay on top of the resulting PDF document when this value is set to true. When using the resulting document in a PDF viewer, you can still search the text underneath the overlay image and still maintain the look of the original document.

Below you will find a simple code snippet written in C# that demonstrates how you can convert you image file to a searchable PDF:

Code:

// Create DocWriter
DocumentWriter docWriter = new DocumentWriter();

// Initialize Ocr engine
IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantag

// Start up the engine
ocrEngine.Startup(null, docWriter, null, null);

using (RasterCodecs codecs = new RasterCodecs())
{

   codecs.Load(originalFile);

   // Change the PDF options
   PdfDocumentOptions pdfOptions = docWriter.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions;

   // Set ImageOverText to true to keep layout of original image
   pdfOptions.ImageOverText = true;

   docWriter.SetOptions(DocumentFormat.Pdf, pdfOptions);

   // Create a new PDF document 
   Console.WriteLine("Creating new PDF document: {0}", outputFileName);

   docWriter.BeginDocument(outputFileName, DocumentFormat.Pdf);

   // Ocr document
   using (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument())
   {
      IOcrPage ocrPage = ocrDocument.Pages.AddPage(originalFile, null);
      ocrPage.Recognize(null);
      ocrDocument.Save(outputFileName, DocumentFormat.Pdf, null);
   }
}


Nick Villalobos
Developer Support Engineer
LEAD Technologies, Inc.

LEAD Logo
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.061 seconds.