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:
Once all the preferences and settings have been gathered, plug them into the converter, create a job and run.
DocumentConverter converter = new DocumentConverter();
DocumentFactory.RasterCodecsTemplate = this.RasterCodecsInstance;
converter.SetOcrEngineInstance(this.OcrEngineInstance, false);
converter.SetDocumentWriterInstance(this.DocumentWriterInstance);
converter.Preprocessor.Deskew = this.PreprocessingDeskew;
converter.Preprocessor.Invert = this.PreprocessingInvert;
converter.Preprocessor.Orient = this.PreprocessingOrient;
var loadDocumentOptions = new LoadDocumentOptions();
loadDocumentOptions.UseCache = DocumentFactory.Cache != null;
converter.LoadDocumentOptions = loadDocumentOptions;
converter.Options.EnableSvgConversion = this.EnableSvgConversion;
converter.Diagnostics.EnableTrace = this.EnableTrace;
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);
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.
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.
- Viewer
- Thumbnails
- Bookmarks
- Annotations
- User Interface Menu and Commands
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:
<!---->
<div id="view"></div>
<!---->
<div id="thumbnails"></div>
Then initialize the viewer and its components with JavaScript:
window.onload = function () {
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);
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) {
documentViewer.setDocument(document);
});
documentViewer.view.preferredItemType = lt.Documents.UI.DocumentViewerItemType.svg;
documentViewer.commands.run(lt.Documents.UI.DocumentViewerCommands.interactivePanZoom);
};
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.
var splitContainer = new SplitContainer { Dock = DockStyle.Fill };
this.Controls.Add(splitContainer);
var createOptions = new Leadtools.Documents.UI.DocumentViewerCreateOptions();
createOptions.ViewContainer = splitContainer.Panel2;
createOptions.ThumbnailsContainer = splitContainer.Panel1;
var documentViewer = DocumentViewerFactory.CreateDocumentViewer(createOptions);
var document = DocumentFactory.LoadFromUri(new Uri("http://demo.leadtools.com/images/pdf/leadtools.pdf"),
new Leadtools.Documents.LoadDocumentOptions { UseCache = false });
documentViewer.SetDocument(document);
documentViewer.View.PreferredItemType = DocumentViewerItemType.Svg;
documentViewer.Commands.Run(DocumentViewerCommands.InteractivePanZoom);
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.