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 : Thursday, September 20, 2018 8:07:22 AM(UTC)
BonzoFestoon

Groups: Administrators
Posts: 26

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 PDF

Code:
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:
File Attachment(s):
ConvertToPdf.zip (349kb) downloaded 198 time(s).

Edited by user Thursday, September 20, 2018 2:34:21 PM(UTC)  | Reason: Not specified

Gabriel Smith
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-2020, Yet Another Forum.NET
This page was generated in 0.090 seconds.