Import and Export File Streams with the Document Converter

The LEADTOOLS Document Converter allows you to convert files between any of 150+ file formats that the LEADTOOLS SDK supports. (Yes, you read that right. Our toolkit offers unparalleled format support). With the use of Intelligent OCR (where the LEAD OCR engine is only used when needed), you can easily convert images to documents, documents to images, images to images, and documents to documents; all using the same code.

The Document Converter works with files from a file path or a memory stream. Using memory streams is ideal for applications that are processing files that are stored in blob storage or a database. This is also useful in cloud-based deployments where file system storage is expensive and unreliable.

Below is a C# code sample to import and export files using streams with the LEADTOOLS Document Converter.


using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD))
using (DocumentConverter docConverter = new DocumentConverter())
    ocrEngine.Startup(null, null, null, @"C:\LEADTOOLS22\Bin\Common\OcrLEADRuntime");
    docConverter.SetOcrEngineInstance(ocrEngine, false);

    string filename = @"FILE PATH TO INPUT FILE";
    byte[] bytes = File.ReadAllBytes(filename);
    var inputStream = new MemoryStream(bytes);
    LEADDocument loadedDocument = DocumentFactory.LoadFromStream(inputStream, new LoadDocumentOptions { UseCache = false });
    var outStream = new MemoryStream();
    var job = docConverter.Jobs.CreateJob(new DocumentConverterJobData
        Document = loadedDocument,
        DocumentFormat = Leadtools.Document.Writer.DocumentFormat.Pdf,
        OutputDocumentStream = outStream

Free Evaluation, Free Technical Support, Free Demos, and More!

Download our FREE 60-day evaluation and test all features and actually program before a purchase is even made. Gain access to our extensive documentation, sample source code, demos, and tutorials.

Our support team is here to help! Contact our support team for free technical support via live chat or email.

For pricing or licensing questions, contact our sales team via email or call us at 704-332-5532.


Developer Support Manager

This entry was posted in Document Imaging and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *