Click here to Skip to main content
15,881,413 members
Articles / Web Development / HTML5
Article

Converting and Viewing Documents with LEADTOOLS

12 Dec 2014CPOL4 min read 24.3K  
The new Document Converter and Document Viewer found in LEADTOOLS Version 19 not only make it possible to view and annotate raster and vector based file formats in the same control, they make it easy.

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.

Introduction

Convert a Word document into a PDF file. View the PDF, annotate it and then save it. This process sounds simple enough, right? What if the original document was a TIFF file? Is it just as easy to convert a TIFF to a PDF and then view, annotate and save the new file? What if you have ten different file types to view, annotate and save, and what if those different files are both raster images and vector documents? And what if your job requirement specified that you can only do this task in one application, using one viewer control? This commonly requested task no longer sounds so simple. Only a viewer capable of annotating not just typical document files like PDF and DOC, but also TIFF, JPEG, SVG and more, could do the job. This viewer control would have to be able to display both raster-based images and vector-based documents, and it would have to be able to convert between these two very different image data types. Doing so is not an easy task, even for the most experienced programmer.

The new Document Converter and Document Viewer found in LEADTOOLS Version 19 not only make it possible to view and annotate raster and vector based file formats in the same control, they make it easy. These unique frameworks will both satisfy demands and exceed expectations for developers creating end-to-end enterprise content management (ECM), document retrieval and document normalization solutions. With only a few lines of code, programmers can implement document conversion and viewing features that would normally take years to develop.

In the following white paper, we will take a closer look at the Document Converter and Document Viewer and how to incorporate them into your application.

Document Converter

The Document Converter SDK automatically uses a combination of the LEADTOOLS Raster, SVG and OCR engines to convert images and documents using the best possible combination of accuracy and speed. For example, the SVG conversion mode can convert between any vector or document format at 100% accuracy without having to add the extra step of OCR. On the other hand, if the Converter detects a raster image input file such as TIFF or JPEG, it will use the LEADTOOLS Advantage OCR engine to extract the text and then convert it to any supported document format.

The converter is very simple to use and only requires selecting a few preferences, conversion settings, and of course the input and output files. A basic dialog, such as the one included with the LEADTOOLS Document Converter Demo, will suffice:

Image 1

Once all the preferences and settings have been gathered, plug them into the converter, create a job and run.

DocumentConverter converter = new DocumentConverter();

// Set the RasterCodecs used by the DocumentFactory to load files
DocumentFactory.RasterCodecsTemplate = this.RasterCodecsInstance;

// Set the OCR engine and Document Writer
converter.SetOcrEngineInstance(this.OcrEngineInstance, false);
converter.SetDocumentWriterInstance(this.DocumentWriterInstance);

// Set pre-processing options for raster image file types
converter.Preprocessor.Deskew = this.PreprocessingDeskew;
converter.Preprocessor.Invert = this.PreprocessingInvert;
converter.Preprocessor.Orient = this.PreprocessingOrient;

// Setup the load document options and caching
var loadDocumentOptions = new LoadDocumentOptions();
loadDocumentOptions.UseCache = DocumentFactory.Cache != null;
converter.LoadDocumentOptions = loadDocumentOptions;

// Set options
converter.Options.EnableSvgConversion = this.EnableSvgConversion;
converter.Diagnostics.EnableTrace = this.EnableTrace;

// Create a job
var jobData = new DocumentConverterJobData
{
   InputDocumentFileName = document == null ? this.InputDocumentFileName : null,
   Document = document,
   InputDocumentFirstPageNumber = this.InputFirstPage,
   InputDocumentLastPageNumber = this.InputLastPage,
   DocumentFormat = this.DocumentFormat,
   OutputDocumentFileName = this.OutputDocumentFileName,
   AnnotationsMode = this.OutputAnnotationsMode,
   JobName = this.JobName,
   UserData = null,
};
var job = converter.Jobs.CreateJob(jobData);

// Run the job
converter.Jobs.RunJob(job);

When converting between document formats, the SVG mode can achieve faster speeds along with 100% accuracy without the need for OCR. The Converter is able to handle complex documents with varying fonts, colors, images, and more. As you can see from the comparison below, our source Word document on the left contains all of these characteristics plus some hyperlinks and Unicode Japanese text, all of which was accurately converted into the PDF.

Image 2

Document Viewer

The LEADTOOLS Document Viewer is an OEM-ready document viewing solution for creating robust, fully-featured applications with rich document viewing features including searchable text, annotations, memory-efficient paging, inertial scrolling, and vector display with infinite zoom. Under the hood, it automatically uses the Document Converters as needed to normalize any document, vector or raster image file into SVG, making it possible to view, search and annotate all file types within a single application.

The Document Viewer is fully customizable and comprised of five components which you can enable or disable and place anywhere in your layout.

  1. Viewer
  2. Thumbnails
  3. Bookmarks
  4. Annotations
  5. User Interface Menu and Commands

Image 3

Simply establish your UI layout with generic containers (e.g. HTML <div>, .NET Panel), then add the Document Viewer components to each container as desired.

Viewing Documents in HTML5 / JavaScript

First, create the layout in your HTML:

<!-- View -->
<div id="view"></div>
<!-- Thumbnails -->
<div id="thumbnails"></div>

Then initialize the viewer and its components with JavaScript:

window.onload = function () {
   // Create the document viewer using the DIV elements
   var createOptions = new lt.Documents.UI.DocumentViewerCreateOptions();
   createOptions.viewContainer = document.getElementById("view");
   createOptions.thumbnailsContainer = document.getElementById("thumbnails");
   var documentViewer = lt.Documents.UI.DocumentViewerFactory.createDocumentViewer(createOptions);

   // Load a PDF document
   var factory = new lt.Documents.DocumentFactory();
   var loadDocumentCommand = lt.Documents.LoadDocumentCommand.create(factory, 
      "http://demo.leadtools.com/images/pdf/leadtools.pdf");
   var prom = loadDocumentCommand.run().done(function (document) {
      // Ready, set in the viewer
      documentViewer.setDocument(document);
   });
   
   // Now set some options, not required
   documentViewer.view.preferredItemType = lt.Documents.UI.DocumentViewerItemType.svg;
   documentViewer.commands.run(lt.Documents.UI.DocumentViewerCommands.interactivePanZoom);
};

Image 4

Viewing Documents in .NET

For your .NET applications you can follow the same procedure. Either create your layout in design mode, or add the objects programmatically.

// Create the UI of the application
var splitContainer = new SplitContainer { Dock = DockStyle.Fill };
this.Controls.Add(splitContainer);

// Create the document viewer using panels of a System.Windows.Forms.SplitterPanel
var createOptions = new Leadtools.Documents.UI.DocumentViewerCreateOptions();
createOptions.ViewContainer = splitContainer.Panel2;
createOptions.ThumbnailsContainer = splitContainer.Panel1;
var documentViewer = DocumentViewerFactory.CreateDocumentViewer(createOptions);

// Load a PDF document
var document = DocumentFactory.LoadFromUri(new Uri("http://demo.leadtools.com/images/pdf/leadtools.pdf"), 
  new Leadtools.Documents.LoadDocumentOptions { UseCache = false });

// Ready, set in the viewer
documentViewer.SetDocument(document);

// Now set some options, not required
documentViewer.View.PreferredItemType = DocumentViewerItemType.Svg;
documentViewer.Commands.Run(DocumentViewerCommands.InteractivePanZoom);

Image 5

Conclusion

Converting and viewing hundreds of document, vector and raster image files types in a single application with a single viewer control is just one of many real-world solutions you can tackle with LEADTOOLS. Its state-of-the-art Document Viewer and Document Converter frameworks make it possible to create dynamic and fully-featured document viewing solutions.

Download the Full Document Converter and Document Viewer Examples

You can download the fully functional demo which includes the features discussed above. To run this example you will need the following:

  • LEADTOOLS free 60 day evaluation
  • Visual Studio 2008 or later
  • Browse to the LEADTOOLS Examples folder (e.g. C:\LEADTOOLS 19\Examples\) where you can find example projects for this and many more technologies in LEADTOOLS

Support

Need help getting this sample up and going? Contact our support team for free technical support! For pricing or licensing questions, you can contact our sales team (sales@leadtools.com) or call us at 704-332-5532.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Help desk / Support LEAD Technologies, Inc.
United States United States
Since 1990, LEAD has established itself as the world's leading provider of software development toolkits for document, medical, multimedia, raster and vector imaging. LEAD's flagship product, LEADTOOLS, holds the top position in every major country throughout the world and boasts a healthy, diverse customer base and strong list of corporate partners including some of the largest and most influential organizations from around the globe. For more information, contact sales@leadtools.com or support@leadtools.com.
This is a Organisation (No members)


Comments and Discussions

 
-- There are no messages in this forum --