LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Use Virtual LEADDocument to Merge Documents and Images into One Text-searchable PDF File
#1
Posted
:
Thursday, September 20, 2018 8:02:22 AM(UTC)
Groups: Administrators
Posts: 27
Was thanked: 1 time(s) in 1 post(s)
Multiple files consisting of multiple formats can be loaded into a single virtual LEADDocument to be processed by the DocumentConverter, which results in a single merged document.
For more background information and real-world examples, please visit this blog post:
Solution to 4 Common First-world Problems – Convert and Merge to PDFCode:private static void MergeAndConvertToPdf(IReadOnlyCollection<string> inputFiles)
{
Console.WriteLine();
ConsoleHelper.WriteStatus("Converting Files... ");
using (var documentConverter = new DocumentConverter())
{
var firstFile = GetFirst(inputFiles);
var outputFile = GetNewFilePath(firstFile);
var loadOptions = new LoadDocumentOptions {UseCache = false};
var createOptions = new CreateDocumentOptions {UseCache = false};
documentConverter.SetDocumentWriterInstance(GetDocumentWriter());
using (var ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, false))
{
ocrEngine.Startup(null, null, null, null);
documentConverter.SetOcrEngineInstance(ocrEngine, false);
using (var masterDocument = DocumentFactory.Create(createOptions))
{
masterDocument.AutoDisposeDocuments = true;
foreach (var inputFile in inputFiles)
masterDocument.Pages.AddRange(DocumentFactory.LoadFromFile(inputFile, loadOptions).Pages);
var jobData =
DocumentConverterJobs.CreateJobData(masterDocument, outputFile, DocumentFormat.Pdf);
jobData.JobName = "merge and convert job";
var job = documentConverter.Jobs.CreateJob(jobData);
documentConverter.Jobs.JobOperation += JobOperationEventHandler;
documentConverter.Jobs.RunJob(job);
documentConverter.Jobs.JobOperation -= JobOperationEventHandler;
DisplayResultMessage(job, outputFile);
}
ocrEngine.Shutdown();
}
}
}
Download the entire Visual Studio 2017 .NET Core 2 project here:
Edited by user Thursday, September 20, 2018 2:29:21 PM(UTC)
| Reason: Not specified
Gabriel Smith
LEAD Technologies, Inc.
LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Use Virtual LEADDocument to Merge Documents and Images into One Text-searchable PDF File
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.