docx-to-pdf-axios
Advanced tools
Comparing version 1.1.1 to 1.1.2
/// <reference types="node" /> | ||
import { AxiosResponse } from 'axios'; | ||
export default function docxToPdfAxios(docx: Blob | Buffer): Promise<AxiosResponse<ArrayBuffer>>; | ||
export default function docxToPdfAxios(docx: Blob | Buffer): Promise<ArrayBuffer>; |
@@ -46,12 +46,22 @@ "use strict"; | ||
let formData = new (browser_or_node_1.isNode ? NodeFormData : FormData)(); | ||
formData.append('__EVENTTARGET', ''); | ||
formData.append('__EVENTARGUMENT', ''); | ||
formData.append('__VIEWSTATE', ''); | ||
formData.append('ctl00$MainContent$fu', docx, 'output.docx'); | ||
formData.append('ctl00$MainContent$btnConvert', 'Convert'); | ||
formData.append('ctl00$MainContent$fuZip', ''); | ||
let options = { responseType: 'arraybuffer' }; | ||
formData.append('file', docx, 'output.docx'); | ||
let options = { responseType: 'json' }; | ||
if (browser_or_node_1.isNode) | ||
options.headers = formData.getHeaders(); | ||
return axios_1.default.post('http://mirror1.convertonlinefree.com', formData, options); | ||
let uploadData = (yield axios_1.default.post('https://filetools2.pdf24.org/client.php?action=upload', formData, options)).data; | ||
delete options.headers; | ||
let convertData = (yield axios_1.default.post('https://filetools2.pdf24.org/client.php?action=convertToPdf', { files: [uploadData] }, options)).data; | ||
options.params = convertData; | ||
let jobStatusData = (yield axios_1.default.get('https://filetools2.pdf24.org/client.php?action=getStatus', options)).data; | ||
while (jobStatusData.status !== 'done') { | ||
try { | ||
yield new Promise(resolve => setTimeout(resolve, 2000)); | ||
jobStatusData = (yield axios_1.default.get('https://filetools2.pdf24.org/client.php?action=getStatus', options)).data; | ||
} | ||
catch (error) { | ||
console.log(error); | ||
} | ||
} | ||
options.responseType = 'arraybuffer'; | ||
return (yield axios_1.default.get('https://filetools2.pdf24.org/client.php?mode=download&action=downloadJobResult', options)).data; | ||
}); | ||
@@ -58,0 +68,0 @@ } |
{ | ||
"name": "docx-to-pdf-axios", | ||
"version": "1.1.1", | ||
"description": "Convert docx files to pdf using http://convertonlinefree.com. Convert docx files to pdf using http://convertonlinefree.com. This fork uses axios so it is compatible with both the browser and node.", | ||
"version": "1.1.2", | ||
"description": "Convert docx files to pdf using https://tools.pdf24.org. This fork uses axios so it is compatible with both the browser and node.", | ||
"main": "dist/index.js", | ||
@@ -21,3 +21,3 @@ "types": "dist/index.d.ts", | ||
"axios", | ||
"convertonlinefree" | ||
"pdf24" | ||
], | ||
@@ -24,0 +24,0 @@ "devDependencies": { |
# docx-to-pdf-axios | ||
Convert docx files to pdf using http://convertonlinefree.com. Convert docx files to pdf using http://convertonlinefree.com. This fork uses axios so it is compatible with both the browser and node. | ||
Convert docx files to pdf using https://tools.pdf24.org. This fork uses axios so it is compatible with both the browser and node. | ||
@@ -29,5 +29,5 @@ ## Copyright Notice | ||
```typescript | ||
docxToPdfAxios(docx:Blob|Buffer):Promise<AxiosResponse<ArrayBuffer>> | ||
docxToPdfAxios(docx:Blob|Buffer):Promise<ArrayBuffer> | ||
``` | ||
Converts a docx Blob (browser) or Buffer (node) to a PDF ArrayBuffer. |
6416
71