My requirement is to convert a word file(docx) to a pdf file in the client side before sending the file to the server.
I have already found solutions to implement this using c# and nodejs, but it doesn't meet my requirement since I'm not using nodejs in my project and to convert using c# I need to send the files to the server.
Any alternate methods such as converting the word file to html or a canvas before exporting as a pdf is fine.
gamage,
I am not sure if you are still looking for answer to this question but let me try to provide solution anyway for anyone in same scenario.
As you are not looking for nodejs solution, We can solve this by calling external api endpoint which does this work for us.
In one of my previous project I have used PDF.co library to extract data from PDF. PDF.co also has endpoint to convert Documents such as doc, docx to PDF.
Following is the pdf.co api endpoint and code snippets for converting doc to pdf.
API Endpoint: https://api.pdf.co/v1/pdf/convert/from/doc
Sample Request:
{
"url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/doc-to-pdf/sample.docx",
"pages": "0-",
"name": "result.pdf"
}
Sample Output
{
"url": "https://pdf-temp-files.s3.amazonaws.com/ce9c93849b604956bc9abadb0ce4b0b3/result.pdf",
"pageCount": 1,
"error": false,
"status": 200,
"name": "result.pdf",
"remainingCredits": 930668,
"credits": 21
}
Following is postman generated code snippet in case you want to consume this using jQuery.
var settings = {
"url": "https://api.pdf.co/v1/pdf/convert/from/doc",
"method": "POST",
"timeout": 0,
"headers": {
"x-api-key": "--your-pdf-co-api-key--",
"Content-Type": "application/json"
},
"data": JSON.stringify({"url":"https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/doc-to-pdf/sample.docx","pages":"0-","name":"result.pdf"}),
};
$.ajax(settings).done(function (response) {
console.log(response);
});
Explore more about this API endpoint with documentation at here. https://apidocs.pdf.co/23-pdf-from-doc-docx-rtf-txt-xps-document-to-pdf
Thank you!
© 2022 - 2024 — McMap. All rights reserved.