PDF Generator API icon

PDF Generator API

Generate PDFs, manage templates, convert HTML/URLs to PDF, and perform PDF operations like watermarking, encryption, and optimization

Overview

The "Optimize Document" operation in the PDF Service resource allows users to reduce the file size of existing PDF documents for better performance and storage efficiency. This node accepts a PDF document either from a public URL or as base64 encoded content, sends it to an optimization API endpoint, and returns the optimized PDF in various output formats.

This operation is beneficial when you need to:

  • Reduce bandwidth usage when sharing PDFs.
  • Improve loading times for PDFs on websites or applications.
  • Save storage space by compressing large PDF files.

Example use cases:

  • Automatically optimize invoices or reports before emailing them.
  • Compress scanned PDFs to speed up upload/download processes.
  • Optimize PDFs generated from other workflows before archiving.

Properties

Name Meaning
PDF Source Source of the PDF document to process. Options: "From URL" (use a PDF from a public URL), "From Base64" (use a PDF from base64 encoded content).
PDF URL Public URL to the PDF document. Required if PDF Source is "From URL".
PDF Base64 Base64 encoded PDF content. Required if PDF Source is "From Base64".
Output Format Choose output format:
- Base64 (JSON): Returns JSON response with base64 string.
- File (Binary): Returns binary file data for download/attachment.
- URL (JSON): Returns JSON response with download URL.

Output

The output depends on the selected "Output Format":

  • Base64 (JSON): The node returns a JSON object containing the optimized PDF as a base64 encoded string.
  • File (Binary): The node outputs the optimized PDF as binary data suitable for direct download or attachment in subsequent workflow steps.
  • URL (JSON): The node returns a JSON object containing a URL where the optimized PDF can be downloaded.

Additionally, when optimizing, the node provides optimization statistics in the JSON output, including:

  • originalSize: Original PDF size in bytes.
  • optimizedSize: Optimized PDF size in bytes.
  • savedBytes: Number of bytes saved after optimization.
  • compressionRatio: Percentage reduction in size.

Example JSON output snippet for Base64 or URL formats:

{
  "success": true,
  "operation": "optimize",
  "format": "base64",
  "data": "<base64-string>",
  "optimizationStats": {
    "originalSize": 1048576,
    "optimizedSize": 524288,
    "savedBytes": 524288,
    "compressionRatio": "50.00%"
  }
}

For binary output, the file is named processed-document.pdf and includes the same metadata fields.

Dependencies

  • Requires an API key credential for the PDF Generator API service.
  • The node makes authenticated HTTP POST requests to the /pdfservices/optimize endpoint of the configured API base URL.
  • The user must provide either a publicly accessible PDF URL or base64 encoded PDF content.
  • No additional environment variables are required beyond the API credential configuration.

Troubleshooting

  • Invalid PDF input: If the provided URL is inaccessible or the base64 content is invalid, the API will return an error. Ensure the URL is publicly reachable and the base64 string is correctly encoded.
  • Unsupported output format: Selecting an unsupported output format may cause errors. Use one of the provided options: base64, file, or url.
  • API authentication errors: Verify that the API key credential is correctly set up and has permissions to access the PDF optimization endpoint.
  • Large file sizes: Very large PDFs might time out or fail during optimization depending on API limits. Consider splitting large PDFs before optimization.
  • Error message "The operation 'optimize' is not supported for resource 'pdfServices'": This indicates a misconfiguration or outdated node version; ensure the node supports this operation.

Links and References

Discussion