|
| 1 | +--- |
| 2 | +title: "AsposePdfToDocXEnhanced" |
| 3 | +second_title: Aspose.PDF for JavaScript via C++ |
| 4 | +description: "Convert a PDF-file to DocX with Enhanced Recognition Mode." |
| 5 | +type: docs |
| 6 | +url: /javascript-cpp/convert/asposepdftodocxenhanced/ |
| 7 | +--- |
| 8 | + |
| 9 | +_Convert a PDF-file to DocX with Enhanced Recognition Mode (fully editable tables and paragraphs)._ |
| 10 | + |
| 11 | +```js |
| 12 | +function AsposePdfToDocXEnhanced( |
| 13 | + fileBlob, |
| 14 | + fileName, |
| 15 | + fileNameResult |
| 16 | +) |
| 17 | +``` |
| 18 | + |
| 19 | +**Parameters**: |
| 20 | + |
| 21 | +* **fileBlob** Blob object |
| 22 | +* **fileName** file name |
| 23 | +* **fileNameResult** result file name |
| 24 | + |
| 25 | +**Return**: |
| 26 | +JSON object |
| 27 | + * **errorCode** - code error (0 no error) |
| 28 | + * **errorText** - text error ("" no error) |
| 29 | + * **fileNameResult** - result file name |
| 30 | + |
| 31 | + |
| 32 | +**Web Worker example**: |
| 33 | +```js |
| 34 | + /*Create Web Worker*/ |
| 35 | + const AsposePDFWebWorker = new Worker("AsposePDFforJS.js"); |
| 36 | + AsposePDFWebWorker.onerror = evt => console.log(`Error from Web Worker: ${evt.message}`); |
| 37 | + AsposePDFWebWorker.onmessage = evt => document.getElementById('output').textContent = |
| 38 | + (evt.data == 'ready') ? 'loaded!' : |
| 39 | + (evt.data.json.errorCode == 0) ? `Result:\n${DownloadFile(evt.data.json.fileNameResult, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", evt.data.params[0])}` : `Error: ${evt.data.json.errorText}`; |
| 40 | +
|
| 41 | + /*Event handler*/ |
| 42 | + const ffileToDocXEnhanced = e => { |
| 43 | + const file_reader = new FileReader(); |
| 44 | + file_reader.onload = event => { |
| 45 | + /*Convert a PDF-file to DocX and with Enhanced Recognition Mode (fully editable tables and paragraphs) save the "ResultPDFtoDocXEnhanced.docx" - Ask Web Worker*/ |
| 46 | + AsposePDFWebWorker.postMessage({ "operation": 'AsposePdfToDocXEnhanced', "params": [event.target.result, e.target.files[0].name, "ResultPDFtoDocXEnhanced.docx"] }, [event.target.result]); |
| 47 | + }; |
| 48 | + file_reader.readAsArrayBuffer(e.target.files[0]); |
| 49 | + }; |
| 50 | +
|
| 51 | + /*Make a link to download the result file*/ |
| 52 | + const DownloadFile = (filename, mime, content) => { |
| 53 | + mime = mime || "application/octet-stream"; |
| 54 | + var link = document.createElement("a"); |
| 55 | + link.href = URL.createObjectURL(new Blob([content], {type: mime})); |
| 56 | + link.download = filename; |
| 57 | + link.innerHTML = "Click here to download the file " + filename; |
| 58 | + document.body.appendChild(link); |
| 59 | + document.body.appendChild(document.createElement("br")); |
| 60 | + return filename; |
| 61 | + } |
| 62 | +``` |
| 63 | +**Simple example**: |
| 64 | +```js |
| 65 | + var ffileToDocXEnhanced = function (e) { |
| 66 | + const file_reader = new FileReader(); |
| 67 | + file_reader.onload = (event) => { |
| 68 | + /*Convert a PDF-file to DocX with Enhanced Recognition Mode (fully editable tables and paragraphs) and save the "ResultPDFtoDocXEnhanced.docx"*/ |
| 69 | + const json = AsposePdfToDocXEnhanced(event.target.result, e.target.files[0].name, "ResultPDFtoDocXEnhanced.docx"); |
| 70 | + if (json.errorCode == 0) document.getElementById('output').textContent = json.fileNameResult |
| 71 | + else document.getElementById('output').textContent = json.errorText; |
| 72 | + /*Make a link to download the result file*/ |
| 73 | + DownloadFile(json.fileNameResult, "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); |
| 74 | + } |
| 75 | + file_reader.readAsArrayBuffer(e.target.files[0]); |
| 76 | + } |
| 77 | +``` |
0 commit comments