PDF.co Web API - Excel To PDF API - JavaScript - Convert Excel to PDF in JQuery - ByteScout

PDF.co Web API – Excel To PDF API – JavaScript – Convert Excel to PDF in JQuery

  • Home
  • /
  • Articles
  • /
  • PDF.co Web API – Excel To PDF API – JavaScript – Convert Excel to PDF in JQuery

PDF.co Excel To PDF Web API in JavaScript to Convert Excel to PDF in JQuery

Excel to PDF Web API is programmed to simplify the conversion of Excel to PDF in jQuery (JS). This is just one of this API’s many functionalities that developers would appreciate, whether they are of expert or beginner skill level.

This REST API can also be utilized in other tasks such as data extraction from PDFs, merging or splitting PDFs, and document manipulation. PDF.co Web API can likewise be employed in generating and reading barcodes from images, scanned documents, and PDFs as it has a built-in OCR, as well as image recognition capability.

To get a better grasp of Web API’s functionality in Excel to PDF Web API conversion, we are providing you here with a sample code that you can copy and paste to your JavaScript project. This will save you a significant amount of time and effort in writing and testing codes as it is readily implementable. You may also access our GitHub repository to acquire this JavaScript code snippet.

Download the ByteScout FREE trial version from our website at your convenience. This free trial contains source code samples and the pertinent programming tutorial you need.

converter.js

$(document).ready(function () {
    $("#resultBlock").hide();
    $("#errorBlock").hide();
    $("#result").attr("href", '').html('');
});

$(document).on("click", "#submit", function () {
    $("#resultBlock").hide();
    $("#errorBlock").hide();
    $("#inlineOutput").text(''); // inline output div
    $("#status").text(''); // status div

    var apiKey = $("#apiKey").val().trim(); //Get your API key at https://app.pdf.co/documentation/api

    var formData = $("#form input[type=file]")[0].files[0]; // file to upload
    var toType = $("#convertType").val(); // output type
    var isInline = $("#outputType").val() == "inline"; // if we need output as inline content or link to output file

    $("#status").text('requesting presigned url for upload...');

    $.ajax({
        url: 'https://api.pdf.co/v1/file/upload/get-presigned-url?name=test.pdf&encrypt=true',
        type: 'GET',
        headers: { 'x-api-key': apiKey }, // passing our api key
        success: function (result) {

            if (result['error'] === false) {
                var presignedUrl = result['presignedUrl']; // reading provided presigned url to put our content into
                var accessUrl = result['url']; // reading output url that will indicate uploaded file

                $("#status").text('uploading...');

                $.ajax({
                    url: presignedUrl, // no api key is required to upload file
                    type: 'PUT',
                    data: formData,
                    processData: false,
                    success: function (result) {

                        $("#status").text('converting...');

                        $.ajax({
                            url: 'https://api.pdf.co/v1/xls/convert/to/' + toType + '?url=' + presignedUrl + '&encrypt=true&inline=' + isInline,
                            type: 'POST',
                            headers: { 'x-api-key': apiKey },
                            success: function (result) {

                                $("#status").text('done converting.');

                                // console.log(JSON.stringify(result));

                                $("#resultBlock").show();

                                if (isInline) {
                                    $("#inlineOutput").text(result['body']);
                                }
                                else {
                                    $("#result").attr("href", result['url']).html(result['url']);
                                }

                            }
                        });


                    },
                    error: function () {
                        $("#status").text('error');
                    }
                });


            }
        }
    });
});



  Click here to get your Free Trial version of the SDK

Tutorials:

prev
next