Edit PDF

Purpose 

This API allows you to upload existing PDF document, either from a local device or a publicly accessible URL for online editing using Zoho PDF Editor.

HTTP Request URL

https://{api.office-integrator_domain}/pdfeditor/officeapi/v1/pdf

Request Parameters

ParameterValueDescription
Mandatory Parameter
apikey423s*****Uniquely identifies the web application in which the PDF editor is integrated.
document

or

url
File

or

String
Method of providing the input file depending on its location.

document - if the input file is from your local drive or desktop.

url - if the input file is from a publicly accessible Web URL.
callback_settings{
 "save_format":"pdf",
 "save_url":<Your Save URL>,
 "http_method_type": "post",
 "retries": <Integer>,
 "timeout": <Integer>,
 "save_url_params": {
                ....
         }
}

Using this param, you will be able to specify the following;

 

save_format -> Specify the output format in which the edited document needs to be saved.

Supported formats: pdf and pdfform

 

save_url -> Provide your server location to which the latest content needs to be pushed back when the 'Save' is performed.

 

The below key values are optional;

 

http_method_type -> Specify the http method in which the save request has to be triggered.

 

retries -> Specify the number of retries required when the 'Save' fails.

 

timeout -> Specify the timeout for the given saveurl.

 

save_url_params -> To customize the output parameters in which the document details will be pushed from our end.

 

Optional Parameters - Editor Customization
editor_settings{
  "unit":"in",
  "language":"en"
}
Set Editor preferences like Unit in inch/mm and interface language for new documents.
document_info{
 "document_name":"New",
 "document_id":"1349"
}
Set a unique id and specify display name of the new document.
user_info{
  "user_id":"1973",
  "display_name":"Ken"
}
Identify the user in the document with "user_id" and "display_name".
ui_options{
  "save_button":"show",
  "file_menu":"show"
}
Specify whether the "Save button"and "File menu" option needs to be shown or hidden.

Note

Editor customization parameters and their values are case-sensitive.

Editor Customization Parameters

editor_settings

ParameterTypePossible ValuesDefault Value
unitstringin/mmin (inch)
languagestringen / de / es / fr / ja / nl more... en

callback_settings

ParameterTypePossible ValuesDefault Value
Mandatory Keys
save_formatstringpdf / pdfformpdf
save_urlstringURL - Maximum length -> 65535URL
Optional Keys
save_url_paramsJSON
  • Maximum key count - 10
  • Allowed characters for <additional_user_key> - Alphabets, Numbers, Hyphen, Underscore and Dot. Maximum Length - 100 characters
  • Maximum length of <value> - 1000 characters
 
http_method_typestringpost / putpost
retriesinteger0 to 30
timeoutinteger1 to 120000 milliseconds120000

document_info

ParameterTypePossible ValuesDefault Value
document_idstring13d4vh9eh 
document_namestringSampleUntitled

user_info

ParameterTypePossible ValuesDefault Value
user_idinteger1973564 
display_namestringKen/James/AdamGuest

ui_options

ParameterTypePossible ValuesDefault Value
save_buttonstringshow/hideshow
file_menustringshow/hideshow

save_url usage:

Zoho Office Integrator allows partners and businesses to save the document content back to their specified storage server through "saveurl" method.

A saveurl is a publicly accessible web URL/Service to which Zoho will push the updated document content from Writer editor to the partner's server.

In order to use the saveurl method, partners should fulfill the below requirements:

  1. Partner's remote servers need to expose one of their ports - port 443 (https) or port 80 (http) - from their location, for Zoho PDF Editor to push the data back.
  2. The saveurl value specified in the HTTPS/HTTP POST request should be a proper domain name and publicly accessible over the web. Example: https://yourdomain.com/save.php

save_url_params usage:

By default, when the 'Save' is performed, we will be pushing back the information with the following key names:

Key NameTypeDescription
contentFileDocument content will be pushed back in the form of bytes.
filenameStringDocument name
formatStringSpecifies the format in which the document has been exported. 

If you wish to customize the above key names that you need to send back during save call, you can make use of the 'save_url_params' key inside 'callback_settings' parameter.

Once the 'save_url_params' key is configured, only the key values defined inside will be pushed back to your server. The default key names (like filename and format) will not be included. To include them, you need to define your own keys for format and filename by using the system variable $format and $filename respectively.

If the 'save_url_params' is passed as an empty JSON or the system variable $content is not configured, the document bytes will be pushed back with the multipart name 'content' by default.

Syntax:

"save_url_params": {
      <custom_content_key>: $content,
      <custom_format_key>: $format,
      <custom_filename_key>: $filename,
      <additional_user_key>: <value>,
      <additional_user_key>: <value>,
      ....
      <additional_user_key>: <value>
      },

Example:

"save_url_params": {
      file: $content,
      extension: $format,
      document_name: $filename,
      <additional_user_key>: <value>,
      <additional_user_key>: <value>
      },

In the above example, the document bytes will be pushed back in the multipart name 'file', document format in the key name 'extension' and document filename in the key name 'document_name'. 

Sample Request

Copiedcurl -X POST \
  https://api.office-integrator.com/pdfeditor/officeapi/v1/pdf \
 -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F  document=@/Users/username/Documents/Sample.pdf \
  -F 'editor_settings={'\''unit'\'':'\''in'\'','\''language'\'':'\''en'\''}' \
  -F 'callback_settings={'\''save_format'\'':'\''pdf'\'','\''save_url'\'':'\''https://domain.com/save.php/'\'}' \
  -F 'document_info={'\''document_name'\'':'\''New'\'', '\''document_id'\'':1349}' \
  -F 'user_info={'\''user_id'\'':'\''1973'\'','\''display_name'\'':'\''Ken'\''}' \
  -F 'ui_options={"save_button":"show","file_menu":"show"}'
		
Copiedimport * as SDK from "@zoho-corp/office-integrator-sdk";
import { readFileSync, writeFileSync } from 'fs';
const __dirname = import.meta.dirname;

class EditPDF {

    static async execute() {
        
        //Initializing SDK once is enough. Calling here since code sample will be tested standalone. 
        //You can place SDK initializer code in you application and call once while your application start-up. 
        await this.initializeSdk();

        try {
            var sdkOperations = new SDK.V1.V1Operations();
            var editPdfParameters = new SDK.V1.EditPdfParameters();

            editPdfParameters.setUrl("https://demo.office-integrator.com/zdocs/EventForm.pdf");
            
            var documentInfo = new SDK.V1.DocumentInfo();

            //Time value used to generate unique document everytime. You can replace based on your application.
            documentInfo.setDocumentId("" + new Date().getTime());
            documentInfo.setDocumentName("EventForm.pdf");

            editPdfParameters.setDocumentInfo(documentInfo);

            var userInfo = new SDK.V1.UserInfo();

            userInfo.setUserId("1000");
            userInfo.setDisplayName("Amelia");

            editPdfParameters.setUserInfo(userInfo);

            var editorSettings = new SDK.V1.PdfEditorSettings();

            editorSettings.setUnit("in");
            editorSettings.setLanguage("en");

            editPdfParameters.setEditorSettings(editorSettings);

            var editorUiOptions = new SDK.V1.PdfEditorUiOptions();

            editorUiOptions.setFileMenu("show");
            editorUiOptions.setSaveButton("show");

            editPdfParameters.setUiOptions(editorUiOptions);

            var callbackSettings = new SDK.V1.CallbackSettings();
            var saveUrlParams = new Map();

            saveUrlParams.set("auth_token", "1234");
            saveUrlParams.set("id", "123131");

            var saveUrlHeaders = new Map();

            saveUrlHeaders.set("header1", "value1");
            saveUrlHeaders.set("header2", "value2");

            callbackSettings.setSaveUrlHeaders(saveUrlHeaders);
            callbackSettings.setSaveUrlParams(saveUrlParams);
            callbackSettings.setSaveFormat("pdf");
            callbackSettings.setSaveUrl("https://officeintegrator.zoho.com/v1/api/webhook/savecallback/601e12157a25e63fc4dfd4e6e00cc3da2406df2b9a1d84a903c6cfccf92c8286");

            editPdfParameters.setCallbackSettings(callbackSettings);

            var responseObject = await sdkOperations.editPdf(editPdfParameters);

            if(responseObject != null) {
                console.log("\nStatus Code: " + responseObject.statusCode);
    
                let pdfSessionResponseObj = responseObject.object;
    
                if(pdfSessionResponseObj != null){

                    if(pdfSessionResponseObj instanceof SDK.V1.CreateDocumentResponse){
                        console.log("\nPDF Document ID - " + pdfSessionResponseObj.getDocumentId());
                        console.log("\nPDF session ID - " + pdfSessionResponseObj.getSessionId());
                        console.log("\nPDF session URL - " + pdfSessionResponseObj.getDocumentUrl());
                        console.log("\nPDF save URL - " + pdfSessionResponseObj.getSaveUrl());
                        console.log("\nPDF delete URL - " + pdfSessionResponseObj.getDocumentDeleteUrl());
                        console.log("\nPDF session delete URL - " + pdfSessionResponseObj.getSessionDeleteUrl());
                    } else if (pdfSessionResponseObj instanceof SDK.V1.InvalidConfigurationException) {
                        console.log("\nInvalid configuration exception. Exception json - ", pdfSessionResponseObj);
                    } else {
                        console.log("\nRequest not completed successfullly");
                    }
                }
            }
        } catch (error) {
            console.log("\nException while running sample code", error);
        }
    }

    //Include office-integrator-sdk package in your package json and the execute this code.

    static async initializeSdk() {

        // Refer this help page for api end point domain details -  https://www.zoho.com/officeintegrator/api/v1/getting-started.html
        let environment = await new SDK.DataCenter.Production("https://api.office-integrator.com");

        let auth = new SDK.AuthBuilder()
                        .addParam("apikey", "2ae438cf864488657cc97*******") //Update this apikey with your own apikey signed up in office integrator service
                        .authenticationSchema(await new SDK.V1.Authentication().getTokenFlow())
                        .build();

        let tokens = [ auth ];

        //Sdk application log configuration
        let logger = new SDK.LogBuilder()
            .level(SDK.Levels.INFO)
            //.filePath("<file absolute path where logs would be written>") //No I18N
            .build();

        let initialize = await new SDK.InitializeBuilder();

        await initialize.environment(environment).tokens(tokens).logger(logger).initialize();

        console.log("SDK initialized successfully.");
    }
}

EditPDF.execute();

Sample Response

Copied{
    "session_delete_url": "https://api.officeintegrator.com/pdfeditor/officeapi/v1/sessions/e0914ec6c08023bd577ad75adcbe1368ce95c9ebf786e6838dce69742560212a5435989d3f69e6100a25aa0b56f4d8d8e289894830b7cc62753ba01a7440f9056f00f94660eaea3d60892c22012c7531",
    "save_url": "https://api.office-integrator.com /pdfeditor/officeapi/v1/pdf/e0914ec6c08023bd577ad75adcbe1368ce95c9ebf786e6838dce69742560212a5435989d3f69e6100a25aa0b56f4d8d8e289894830b7cc62753ba01a7440f9056f00f94660eaea3d60892c22012c7531/save",
    "session_id": "e0914ec6c08023bd577ad75adcbe1368ce95c9ebf786e6838dce69742560212a5435989d3f69e6100a25aa0b56f4d8d8e289894830b7cc62753ba01a7440f9056f00f94660eaea3d60892c22012c7531",
    "document_delete_url": "https://api.office-integrator.com /pdfeditor/officeapi/v1/pdf/49706a6f-2bc8-4f75-9152-74534ee6047e",
    "document_id": "49706a6f-2bc8-4f75-9152-74534ee6047e",
    "document_url": "https://api.office-integrator.com/pdfeditor/officeapi/v1/pdf/e0914ec6c08023bd577ad75adcbe1368ce95c9ebf786e6838dce69742560212a5435989d3f69e6100a25aa0b56f4d8d8e289894830b7cc62753ba01a7440f9056f00f94660eaea3d60892c22012c7531/edit"
}