admin管理员组

文章数量:1430924

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.

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.

Share Improve this question asked Oct 17, 2017 at 5:57 Pankaja GamagePankaja Gamage 3043 silver badges16 bronze badges 1
  • Sorry, i don't know neither could i find such thing. – Bárbara Peres Commented Oct 13, 2019 at 9:50
Add a ment  | 

1 Answer 1

Reset to default 1

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-.s3-us-west-2.amazonaws./files/demo-files/cloud-api/doc-to-pdf/sample.docx",
    "pages": "0-",
    "name": "result.pdf"
}

Sample Output

{
    "url": "https://pdf-temp-files.s3.amazonaws./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-.s3-us-west-2.amazonaws./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!

本文标签: Convert Word file to PDF using JavascriptJqueryStack Overflow