Convert Multi-page TIFF to Searchable PDF in C#, Java, and C

Posted on 2021-05-19 Gabriel Smith

TIFF to PDF conversion

It is tax season in the US. My CPA wants all of my supporting documentation to be saved as PDF, but I saved all as one multi-page TIFF when I scanned them. Fortunately, I have access to LEADTOOLS OCR.

In terms of functionality and platform support, LEADTOOLS OCR is the most flexible OCR engine available. It makes converting more than 200 image types to PDF and other document formats an easy task. The resulting PDF can be an image-based or text-searchable PDF. It can even be a combination of image over text so the resulting PDF has the text, but looks exactly like the TIFF.

The following simplified C# code will convert any supported image format, including TIFF, to a text-searchable PDF file.

Convert TIFF to PDF in C#


static void OCR(string inputFile, string outputFile) 
{ 
    using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD)) 
    { 
        //Startup the LEADTOOLS OCR Engine 
        ocrEngine.Startup(null, null, null, null); 
        //Run the AutoRecognizeManager and specify PDF format 
        ocrEngine.AutoRecognizeManager.Run(inputFile, outputFile, DocumentFormat.Pdf, null, null); 
        Console.WriteLine($"OCR output saved to {outputFile}"); 
    } 
} 

Complete tutorial to convert TIFF to PDF in C#

Convert TIFF to PDF in Java


static void OCR(String input, String output)  
{ 
    OcrEngine ocrEngine = OcrEngineManager.createEngine(OcrEngineType.LEAD); 
    ocrEngine.startup(new RasterCodecs(), new DocumentWriter(), null, null); 
    ocrEngine.getAutoRecognizeManager().run(input, output, DocumentFormat.PDF, null); 
    System.out.println("OCR output saved to " + output); 
}

Complete tutorial to convert TIFF to PDF in Java

Convert TIFF to PDF in C


void OcrAndSaveResult(HWND hwnd) 
{ 
   L_OcrEngine engine = NULL; 
   L_OcrDocumentManager documentManager = NULL; 
   L_OcrDocument document = NULL; 
   L_OcrPage page = NULL; 
   L_OcrLanguageManager languageManager = NULL; 
   L_OcrLanguage langs[] = { L_OcrLanguage_EN }; 
 
   const TCHAR* outputFile = TEXT("C:\\Temp\\output.pdf"); 
 
#define LTOCR_CHECK_NRET if(nRet != SUCCESS) goto LTOCR_CLEANUP 
 
   L_INT nRet = L_OcrEngineManager_CreateEngine(L_OcrEngineType_LEAD, &engine); 
   LTOCR_CHECK_NRET; 
   nRet = L_OcrEngine_Startup(engine, NULL, TEXT("C:\\LEADTOOLS21\\Bin\\Common\\OcrLEADRuntime")); 
   LTOCR_CHECK_NRET; 
   nRet = L_OcrEngine_GetDocumentManager(engine, &documentManager); 
   LTOCR_CHECK_NRET; 
   nRet = L_OcrDocumentManager_CreateDocument(documentManager, &document, L_OcrCreateDocumentOptions_AutoDeleteFile, NULL); 
   LTOCR_CHECK_NRET; 
   // Create the OCR page from the loaded bitmap  
   nRet = L_OcrPage_FromBitmap(engine, &page, &LEADBmp, L_OcrBitmapSharingMode_None, NULL, NULL); 
   LTOCR_CHECK_NRET; 
 
   // Set the language we want to use 
   nRet = L_OcrEngine_GetLanguageManager(engine, &languageManager); 
   LTOCR_CHECK_NRET; 
   nRet = L_OcrLanguageManager_EnableLanguages(languageManager, langs, _countof(langs)); 
   LTOCR_CHECK_NRET; 
   // Try to recognize the text in the document 
   nRet = L_OcrPage_Recognize(page, NULL, NULL); 
   LTOCR_CHECK_NRET; 
   // Add the created OCR page into the file-based OCR document  
   nRet = L_OcrDocument_AddPage(document, page); 
   LTOCR_CHECK_NRET; 
   nRet = L_OcrDocument_Save(document, outputFile, DOCUMENTFORMAT_PDF, NULL, NULL); 
 
LTOCR_CLEANUP: 
   TCHAR message[1024]; 
   if (nRet != SUCCESS) 
      wsprintf(message, TEXT("OCR failed with error code: %d"), nRet); 
   else 
      wsprintf(message, TEXT("OCR succeeded and result saved to %s"), outputFile);       
 
   MessageBox(hwnd, message, TEXT("LEADTOOLS OCR Demo"), MB_OK); 
 
   if(document) 
      L_OcrDocument_Destroy(document); 
   if(engine) 
      L_OcrEngine_Destroy(engine); 
} 

Complete tutorial to convert TIFF to PDF in C

It is just that easy. Further, LEADTOOLS is all you need to accomplish this task. No third-party software is needed.

See For Yourself - Free Evaluation

Download the LEADTOOLS SDK for free. It’s fully-functional for 60 days and comes with free chat and email support.

Stay Tuned For More Conversion Samples

Did you see our previous post, “Convert PDF to Text in C#, VB, and Java”? Stay tuned for more conversion examples to see how the LEADTOOLS document converter will easily fit into any workflow converting PDF files into other document files or images and back again. Need help in the meantime? Contact our support team for free technical support! For pricing or licensing questions, you can contact our sales team via email or call us at 704-332-5532.

LEADTOOLS Blog

LEADTOOLS Powered by Apryse,the Market Leading PDF SDK,All Rights Reserved