Leadtools.Documents Namespace > Document Object : Convert Method |
function Leadtools.Documents.Document.convert( jobData )
Parameter | Type | Description |
---|---|---|
jobData | DocumentConverterJobData | The job data. |
Type | Description |
---|---|
jQueryApi.IDeferred | A Promise object that may resolve succesfully to an object of type DocumentConvertResult object. |
The Convert method allows conversion the document to any of the supported formats with minimal amount of code.
The output document types can be any type of file formats supported by LEADTOOLS. but not limited to:
The Convert method will analyze the input and output documents types and then automatically uses a combination of the LEADTOOLS Raster, SVG and OCR engines to convert the data using the best possible combination of accuracy and speed. Each conversion operation is called a Document Converter Job in the framework.
function convertDocumentExample() { // Load a new document var url = "http://demo.leadtools.com/images/pdf/leadtools.pdf"; console.log("Loading document ..."); lt.Documents.DocumentFactory.loadFromUri(url, null) .done(function (document) { console.log("Loaded, converting..."); // Convert this document to Microsoft Word DOCX format var jobData = new lt.Documents.DocumentConverterJobData(); jobData.documentFormat = lt.Documents.Writers.DocumentFormat.docx; jobData.rasterImageFormat = lt.Documents.RasterImageFormat.unknown; // Set document options var docxOptions = new lt.Documents.Writers.DocxDocumentOptions(); docxOptions.textMode = lt.Documents.Writers.DocumentTextMode.auto; jobData.documentOptions = docxOptions; document.convert(jobData) .done(function (result) { console.log("Converted..."); // Show it in a new tab // This is generic code, we know the result is in "document" since DOCX supports that // But this code checks if the results have been archived into a ZIP file if this // example was converting to, say SVG var resultDocument = result.document != null ? result.document.url : result.archive.url; window.open(resultDocument); }) .fail(function (jqXHR, statusText, errorThrown) { alert("Error converting document " + errorThrown); }); }) .fail(function (jqXHR, statusText, errorThrown) { alert("Error loading document " + errorThrown); }); }