LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Creating a Searchable PDF from a TIF containing Images using ImageOverText
#1
Posted
:
Friday, August 18, 2017 3:54:33 PM(UTC)
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.
LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Creating a Searchable PDF from a TIF containing Images using ImageOverText
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.