Link Search Menu Expand Document

Add Image to Existing PDF (jQuery) - JavaScript

PDF Add Text, Signatures and Images to PDF sample in JavaScript demonstrating ‘Add Image to Existing PDF (jQuery)’

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

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

    var apiKey = $("#apiKey").val().trim(); //Get your API key at

    var signatureImageUrl = $("#signatureImageUrl").val();
    var destinationXCoordinate = $("#destinationXCoordinate").val();
    var destinationYCoordinate = $("#destinationYCoordinate").val();
    var destinationHeight = $("#destinationHeight").val();
    var destinationWidth = $("#destinationWidth").val();

    var formData = $("#SourceFile")[0].files[0]; // file to upload

    $("#status").html('Getting presigned url... &nbsp;&nbsp;&nbsp; <img src="ajax-loader.gif" />');

        url: '',
        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 uploadedUrl = result['url']; // Uploaded URL

                $("#status").html('Uploading... &nbsp;&nbsp;&nbsp; <img src="ajax-loader.gif" />');

                    url: presignedUrl, // no api key is required to upload file
                    type: 'PUT',
                    headers: { 'content-type': 'application/pdf' }, // setting to pdf type as we are uploading pdf file
                    data: formData,
                    processData: false,
                    success: function (result) {

                        // API URL
                        var cUrl = '';

                        // Input data
                        var data = {
                            name: 'result.pdf',
                            url: uploadedUrl,
                            images: [
                                    url: signatureImageUrl,
                                    x: destinationXCoordinate,
                                    y: destinationYCoordinate,
                                    width: destinationWidth,
                                    height: destinationHeight


                        $("#status").html('Processing... &nbsp;&nbsp;&nbsp; <img src="ajax-loader.gif" />');
                            url: cUrl,
                            type: 'POST',
                            headers: { 'x-api-key': apiKey, 'Content-Type': 'application/json' },
                            data: JSON.stringify(data),
                            processData: false,
                            contentType: false,
                            //data: oData,
                            success: function (result) {
                                $("#status").text('done processing.');

                                if (result.error) {
                                } else {
                                    $("#iframeResultPdf").prop("src", result.url);

                    error: function () {

<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8">
    <title>Cloud API JQuery sample</title>
    <script src=""></script>
    <script src="addImageToPDF.js" type="text/javascript" encoding="UTF-8"></script>
    <form id="form" enctype="multipart/form-data">
            <label>Copy-paste your API Key for ByteScout Cloud API here</label>
            <input type="text" id="apiKey" placeholder="your cloud API Key" value=""/> 
            <a href="" target="_blank">no api key yet? sign up here</a>
            <label>Source PDF File Url</label>
            <input type="file" id="SourceFile" placeholder="Upload Source File" />
            <label>Signature Image Url</label>
            <input type="text" id="signatureImageUrl" placeholder="Signature Image Url" style="min-width: 500px;" value="" />
            <label>Destination Co-ordinates - </label>
            <b>X: </b> <input type="text" id="destinationXCoordinate" value="400" /> &nbsp;&nbsp;&nbsp;
            <b>Y: </b> <input type="text" id="destinationYCoordinate" value="20" /> 
            <label>Destination Image Size - </label>
            <b>Height: </b> <input type="text" id="destinationHeight" value="32" /> &nbsp;&nbsp;&nbsp;
            <b>Width: </b> <input type="text" id="destinationWidth" value="119" /> 
        <button type="button" id="submit">Convert</button> <span id="status"></span>

    <div id="errorBlock">
        <h4>Code: <span id="statusCode"></span></h4>
        <ul id="errors"></ul>
    <div id="resultBlock">
        <pre id="inlineOutput"></pre><br/>
        <iframe id="iframeResultPdf" src="" width="100%" height="500px"></iframe>
</html> Web API: the Web API with a set of tools for documents manipulation, data conversion, data extraction, splitting and merging of documents. Includes image recognition, built-in OCR, barcode generation and barcode decoders to decode bar codes from scans, pictures and pdf.

Get your API key here!

Download Source Code (.zip)

return to the previous page explore PDF Add Text, Signatures and Images to PDF endpoint