Link Search Menu Expand Document

Add Text to Existing PDF (jQuery) - JavaScript

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

// Visit Knowledgebase for adding Text Macros to PDF 

$(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 inputText = $("#inputText").val();
    var fontName = $("#fontName").val();
    var fontSize = $("#fontSize").val();
    var fontColor = $("#fontColor").val();

    var destinationXCoordinate = $("#destinationXCoordinate").val();
    var destinationYCoordinate = $("#destinationYCoordinate").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) {

                        // Request Url
                        var cUrl = '';

                        // Input Data
                        var data = {
                            name: 'result.pdf',
                            url: uploadedUrl,
                            annotations: [{
                                x: destinationXCoordinate,
                                y: destinationYCoordinate,
                                text: inputText,
                                fontname: fontName,
                                size: fontSize,
                                color: fontColor

                        $("#status").html('Processing... &nbsp;&nbsp;&nbsp; <img src="ajax-loader.gif" />');
                            url: cUrl,
                            type: 'POST',
                            headers: { 'x-api-key': apiKey, 'Content-Type': 'application/json'  },
                            processData: false,
                            contentType: false,
                            data: JSON.stringify(data),
                            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="addTextToPDF.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" />
            <input type="text" id="inputText" placeholder="Input Text" value="APPROVED" />
            <label>Font Name</label>
            <input type="text" id="fontName" placeholder="Font Name" value="Times New Roman" />
            <label>Font Size</label>
            <input type="text" id="fontSize" placeholder="Font Size" value="24" />
            <input type="text" id="fontColor" placeholder="Color" value="FF0000" />
            <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="600" /> 
            <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