Compress PDF

Purpose

This API allows you to reduce the file size of a PDF for download, WorkDrive storage, or callback delivery.

Quick Reference

PropertyValue
MethodPOST
Request URL (Download)https://{zohoapis_domain}/pdfeditor/api/v1/pdf/compress
Request URL (Store)https://{zohoapis_domain}/pdfeditor/api/v1/pdf/compress/store
Request URL (Callback)https://{zohoapis_domain}/pdfeditor/api/v1/pdf/compress/callback

Body Parameters

ParameterValueMandatory/OptionalDescription
fileFile or StringMandatoryUpload the PDF file from your local drive or desktop. If the PDF file is available via a publicly accessible web URL, you can provide the URL using the same parameter.
input_options{
  "image_settings": { ... },
  "font_settings": { ... },
  "resource_optimization": { ... },
  "discard_objects": { ... },
  "discard_user_data": { ... },
  "color_management": { ... }
}
MandatorySpecify the compression configuration as a JSON object. Only include the setting groups and keys you want to customize.
passwordStringOptionalIf the input PDF is password protected, specify the password to unlock it.
output_settings{
  "name": "<document_name>",
  "folder_id": "<folder_id>",
  "overwrite_existing_file": true | false
}
Mandatory for store variantname – Specify the name for the compressed PDF document.
folder_id – Specify the ID of the WorkDrive folder in which to store the output file.
overwrite_existing_file(optional) – Set to true to overwrite an existing file with the same name in the folder.
callback{
  "invoke_url": "<callback_url>",
  "timeout": 60,
  "retry_interval": 60,
  "headers": {
    "header_name": "header_value"
  },
  "http_method_type": "post"
}
Mandatory for callback variantSpecify the callback delivery configuration for the /callback variant.

input_options Parameters

ParameterData TypePossible ValuesDefault Value
image_settingsJSON ObjectContains compression settings for color, grayscale, and monochrome images.
font_settingsJSON ObjectContains font optimization settings such as deduplicate_fonts and subset_fonts.
resource_optimizationJSON ObjectContains cleanup and stream compression settings.
discard_objectsJSON ObjectContains flags to remove annotations, thumbnails, bookmarks, page actions, and similar objects.
discard_user_dataJSON ObjectContains flags to remove metadata, JavaScript, embedded files, rich media, accessibility tags, and private application data.
color_managementJSON ObjectContains transparency normalization and RGB conversion settings.

The following sub-sections describe each supported settings object.

image_settings.color_images

ParameterTypePossible ValuesDefault Value
enable_resizeBooleantrue / falsefalse
enable_dpi_reductionBooleantrue / falsefalse
target_dpiInteger≥ 72 (Recommended: 72–300)150
max_dimensionInteger≥ 256 (pixels)1500
convert_to_grayscaleBooleantrue / falsefalse
compression_typeStringjpeg / losslessjpeg
qualityFloat0.1 – 1.0 (0.3 = high compression, 0.6 = balanced, 0.8–1.0 = high quality). Applicable only when compression_type is jpeg.0.75
deduplicate_imagesBooleantrue / falsefalse
extract_inline_imagesBooleantrue / falsefalse

image_settings.grayscale_images

ParameterTypePossible ValuesDefault Value
enable_resizeBooleantrue / falsefalse
enable_dpi_reductionBooleantrue / falsefalse
target_dpiInteger≥ 72150
max_dimensionInteger≥ 2561500
compression_typeStringjpeg / losslessjpeg
qualityFloat0.1 – 1.00.8
deduplicate_imagesBooleantrue / falsefalse

image_settings.monochrome_images

ParameterTypePossible ValuesDefault Value
enable_resizeBooleantrue / falsefalse
enable_dpi_reductionBooleantrue / falsefalse
target_dpiInteger≥ 150300
compression_typeStringjpeg / losslesslossless
qualityStringlossless / lossylossless


font_settings

ParameterTypePossible ValuesDefault Value
deduplicate_fontsBooleantrue / falsefalse
subset_fontsBooleantrue / falsefalse

resource_optimization

ParameterTypePossible ValuesDefault Value
remove_unused_resourcesBooleantrue / falsefalse
deduplicate_streamsBooleantrue / falsefalse
compress_objectsBooleantrue / falsefalse
enable_stream_compressionBooleantrue / falsetrue

discard_objects

ParameterTypePossible ValuesDefault Value
discard_form_fieldsBooleantrue / falsefalse
flatten_form_fieldsBooleantrue / falsefalse
discard_annotationsBooleantrue / falsefalse
discard_hidden_annotationsBooleantrue / falsefalse
discard_alternate_imagesBooleantrue / falsefalse
discard_bookmarksBooleantrue / falsefalse
discard_thumbnailsBooleantrue / falsefalse
discard_page_actionsBooleantrue / falsefalse
discard_open_actionsBooleantrue / falsefalse
discard_output_intentsBooleantrue / falsefalse
discard_optional_content_layersBooleantrue / falsefalse

discard_user_data

ParameterTypePossible ValuesDefault Value
discard_metadataBooleantrue / falsefalse
discard_javascriptBooleantrue / falsefalse
discard_embedded_filesBooleantrue / falsefalse
discard_rich_mediaBooleantrue / falsefalse
discard_accessibility_tagsBooleantrue / falsefalse
discard_private_application_dataBooleantrue / falsefalse

color_management

ParameterTypePossible ValuesDefault Value
normalize_transparencyBooleantrue / falsefalse
force_rgbBooleantrue / falsefalse


callback Parameters

ParameterData TypePossible ValuesDefault Value
invoke_urlStringURL. Maximum length: 300 characters.
timeoutInteger10 to 120 seconds60 seconds
retry_intervalInteger60 to 28800 seconds60 seconds
headersJSON ObjectMaximum 10 keys. Allowed characters for keys: alphabets, numbers, hyphen, underscore, dot. Maximum key length: 100. Maximum value length: 2500.
http_method_typeStringput, postpost

Notes and Limits

  • The maximum file size allowed for the input PDF is 50 MB.
  • Only the keys you pass inside input_options are customized. Omitted keys fall back to their default values.
  • This API stores the result in Zoho WorkDrive only for the /store variant. A WorkDrive account is required for that variant.
  • To use the download or callback variants, an OAuth token should be generated with the following scopes: ZohoWriter.pdfEditor.ALL
  • To use the store variant, an OAuth token should be generated with the following scopes: ZohoWriter.pdfEditor.ALL, WorkDrive.files.ALL, WorkDrive.organization.ALL

Possible Errors

Refer to the following pages for the list of possible errors for this API:

Download Variant Sample Request

Copiedcurl --location --request POST "https://{zohoapis_domain}/pdfeditor/api/v1/pdf/compress" \
  --header "Authorization: Zoho-oauthtoken xxx.yyy.zzz" \
  --form 'file=@/Users/username/Documents/Original.pdf' \
  --form 'password="pdf_password"' \
  --form 'input_options={
    "image_settings": {
      "color_images": {
        "enable_resize": true,
        "enable_dpi_reduction": true,
        "target_dpi": 120,
        "max_dimension": 1200,
        "quality": 0.6
      },
      "grayscale_images": {
        "quality": 0.7
      },
      "monochrome_images": {
        "target_dpi": 300
      }
    },
    "font_settings": { "deduplicate_fonts": true },
    "resource_optimization": { "remove_unused_resources": true, "enable_stream_compression": true }
  }'

Store Variant Sample Request

Copiedcurl --location --request POST "https://{zohoapis_domain}/pdfeditor/api/v1/pdf/compress/store" \
  --header "Authorization: Zoho-oauthtoken xxx.yyy.zzz" \
  --form 'file=@/Users/username/Documents/Original.pdf' \
  --form 'password="pdf_password"' \
  --form 'input_options={
    "image_settings": {
      "color_images": {
        "enable_resize": true,
        "enable_dpi_reduction": true,
        "target_dpi": 120,
        "max_dimension": 1200,
        "quality": 0.6
      },
      "grayscale_images": {
        "quality": 0.7
      }
    },
    "font_settings": { "deduplicate_fonts": true },
    "resource_optimization": { "remove_unused_resources": true, "enable_stream_compression": true }
  }' \
  --form 'output_settings={"name": "Compressed_Document.pdf", "folder_id": "<folder_id>", "overwrite_existing_file": true}'

Callback Variant Sample Request

Copiedcurl --location --request POST "https://{zohoapis_domain}/pdfeditor/api/v1/pdf/compress/callback" \
  --header "Authorization: Zoho-oauthtoken xxx.yyy.zzz" \
  --form 'file=@/Users/username/Documents/Original.pdf' \
  --form 'password="pdf_password"' \
  --form 'input_options={
    "image_settings": {
      "color_images": {
        "enable_resize": true,
        "enable_dpi_reduction": true,
        "target_dpi": 120,
        "max_dimension": 1200,
        "quality": 0.6
      },
      "monochrome_images": {
        "target_dpi": 300
      }
    },
    "font_settings": { "deduplicate_fonts": true },
    "resource_optimization": { "remove_unused_resources": true, "enable_stream_compression": true }
  }' \
  --form 'callback={"invoke_url": "https://www.example.com/v1/api/callback/savecallback", "timeout": 120, "retry_interval": 60, "http_method_type": "post"}'

Download Variant Sample Response

Copied{
  "status": "inprogress",
  "status_check_url": "https://pdf.zoho.com/pdfeditor/api/v1/pdf/compress/job/e9051e30fd7f0093cba4247d1f831e03e945a127bde429ed6e9ef3a703b15a6060b830256c650cb88a3f687773c33076"
}

Download Variant Success Response

Copied{
  "status": "success",
  "download_url": "https://pdf.zoho.com/pdfeditor/api/v1/pdf/compress/download/d2e4f6a8b9c1d3e5f7a9b1c3d5e7f9a1",
  "response_generated_time": 1780912499331
}

Store Variant Sample Response

Copied{
  "status": "inprogress",
  "status_check_url": "https://pdf.zoho.com/pdfeditor/api/v1/pdf/compress/job/2ae74c719bdb14ed9941fe351ade742439bf75ab0fb8fdf0a68b57a7a60cbd54ab7cb7bea5d0fafb4d2560a90331aaf8",
  "document_id": "hf3e60435a4c7576f4d21a16cfc292a4c64a9",
  "document_url": "https://workdrive.zoho.com/file/hf3e60435a4c7576f4d21a16cfc292a4c64a9"
}

Store Variant Success Response

Copied{
  "status": "success",
  "document_id": "hf3e60435a4c7576f4d21a16cfc292a4c64a9",
  "document_url": "https://workdrive.zoho.com/file/hf3e60435a4c7576f4d21a16cfc292a4c64a9",
  "response_generated_time": 1780912529135
}

Callback Variant Sample Response

Copied{
  "status": "inprogress",
  "status_check_url": "https://pdf.zoho.com/pdfeditor/api/v1/pdf/compress/job/1d358192770dc68d173ca34b8f7c9dcb121ad0bf3d6307b7387be79e76dacf586f9d62cd253c26020f8c3dcf79d51b6b"
}

Callback Variant Success Response

Copied{
  "status": "success",
  "callback_response": {
    "invoked_time": 1780912655806,
    "http_status_code": 200,
    "message": {
      "download_url": "https://pdf.zoho.com/pdfeditor/api/v1/pdf/compress/download/d2e4f6a8b9c1d3e5f7a9b1c3d5e7f9a1",
      "response_generated_time": 1780912656237
    }
  }
}