{
  "openapi": "3.1.1",
  "info": {
    "title": "PDF Compressor API",
    "version": "1.0.0",
    "summary": "Make PDFs smaller with Ghostscript presets or custom image DPI and JPEG quality, with previews.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://pdfcompressor.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Make PDFs smaller with Ghostscript presets or custom image DPI and JPEG quality, with previews.",
        "description": "Re-writes a PDF with Ghostscript using the screen, e-book, printer or prepress preset, or your own image resolution and JPEG quality. Shows the size before and after, can compare up to three presets side by side, and renders page 1 before and after so you can judge the quality. If the result is not smaller, you get the original back.\n\nMethodology:\n- The PDF is validated with qpdf and decrypted with your password if needed. Ghostscript (pdfwrite) then rewrites it: images are downsampled to the preset resolution and re-compressed, fonts are subset and compressed, duplicate images are stored once.\n- Presets follow Ghostscript's -dPDFSETTINGS: screen ≈ 72 DPI images, ebook ≈ 150 DPI, printer and prepress ≈ 300 DPI (prepress keeps more colour information). Custom sets the colour/gray image resolution and the JPEG quality directly.\n- Savings = 1 − new size ÷ original size. When a level does not make the file smaller (common for text-only or already optimised PDFs), the original file is returned for that level instead.\n- Page 1 is rendered at the same size before and after (Poppler) so you can compare image quality and text sharpness.\n- Dates and random IDs are removed from the output so the same input always gives the same file. Document title/author are kept; XMP metadata is removed.\n\nGhostscript re-creates the PDF: interactive elements such as form fields usually survive, but digital signatures become invalid and some rare features may be lost. Keep your original.",
        "tags": [
          "documents"
        ],
        "x-mcp-tool": "pdf_compressor",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PdfCompressorInput"
              },
              "examples": {
                "example1": {
                  "summary": "Text-only PDF with the e-book preset",
                  "value": {
                    "preset": "ebook",
                    "file": {
                      "filename": "report.pdf",
                      "contentType": "application/pdf",
                      "contentBase64": "JVBERi0xLj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aW5nID4+CmVuZG9iagp4cmVmCjAgOAowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDAwMTUgMDAwMDAgbiAKMDAwMDAwMDA2NCAwMDAwMCBuIAowMDAwMDAwMTI3IDAwMDAwIG4gCjAwMDAwMDAyNTMgMDAwMDAgbiAKMDAwMDAwMDQ5NyAwMDAwMCBuIAowMDAwMDAwNjIzIDAwMDAwIG4gCjAwMDAwMDA3MTIgMDAwMDAgbiAKdHJhaWxlcgo8PCAvU2l6ZSA4IC9Sb290IDEgMCBSID4+CnN0YXJ0eHJlZgo4MDkKJSVFT0YK"
                    }
                  }
                },
                "example2": {
                  "summary": "Compare screen, e-book and printer",
                  "value": {
                    "preset": "screen",
                    "compare": true,
                    "file": {
                      "filename": "report.pdf",
                      "contentType": "application/pdf",
                      "contentBase64": "JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUiA1IDAgUl0gL0NvdW50IDIgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvTWVkaWFCb3ggWzAgMCA1OTUgODQyXSAvUmVzb3VyY2VzIDw8IC9Gb250IDw8IC9GMSA3IDAgUiA+PiA+PiAvQ29udGVudHMgNCAwIFIgPj4KZW5kb2JqCjQgMCBvYmoKPDwgL0xlbmd0aCAxOTMgPj4Kc3RyZWFtCkJUIC9GMSAyNCBUZiA3MiA3NDIgVGQgKFF1YXJ0ZXJseSByZXBvcnQpIFRqIEVUCkJUIC9GMSAxNCBUZiA3MiA3MTIgVGQgKFJldmVudWUgZ3JldyAxMiBwZXJjZW50LikgVGogRVQKQlQgL0YxIDE0IFRmIDcyIDY4MiBUZCAoVGhpcyBzYW1wbGUgaGFzIG9ubHkgdGV4dCwgc28gdGhlcmUgaXMgbGl0dGxlIHRvIGNvbXByZXNzLikgVGogRVQKZW5kc3RyZWFtCmVuZG9iago1IDAgb2JqCjw8IC9UeXBlIC9QYWdlIC9QYXJlbnQgMiAwIFIgL01lZGlhQm94IFswIDAgNTk1IDg0Ml0gL1Jlc291cmNlcyA8PCAvRm9udCA8PCAvRjEgNyAwIFIgPj4gPj4gL0NvbnRlbnRzIDYgMCBSID4+CmVuZG9iago2IDAgb2JqCjw8IC9MZW5ndGggMzkgPj4Kc3RyZWFtCkJUIC9GMSAyNCBUZiA3MiA3NDIgVGQgKFBhZ2UgdHdvKSBUaiBFVAplbmRzdHJlYW0KZW5kb2JqCjcgMCBvYmoKPDwgL1R5cGUgL0ZvbnQgL1N1YnR5cGUgL1R5cGUxIC9CYXNlRm9udCAvSGVsdmV0aWNhIC9FbmNvZGluZyAvV2luQW5zaUVuY29kaW5nID4+CmVuZG9iagp4cmVmCjAgOAowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDAwMTUgMDAwMDAgbiAKMDAwMDAwMDA2NCAwMDAwMCBuIAowMDAwMDAwMTI3IDAwMDAwIG4gCjAwMDAwMDAyNTMgMDAwMDAgbiAKMDAwMDAwMDQ5NyAwMDAwMCBuIAowMDAwMDAwNjIzIDAwMDAwIG4gCjAwMDAwMDA3MTIgMDAwMDAgbiAKdHJhaWxlcgo8PCAvU2l6ZSA4IC9Sb290IDEgMCBSID4+CnN0YXJ0eHJlZgo4MDkKJSVFT0YK"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PdfCompressorResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "PdfCompressorInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "file": {
            "title": "PDF",
            "description": "Max 100 MB. Processed on our server and deleted; results can be downloaded for about 2 hours. Upload as {filename, contentType?, contentBase64}. Max 102400 KiB. Accepts .pdf,application/pdf.",
            "type": "object",
            "additionalProperties": false,
            "required": [
              "filename",
              "contentBase64"
            ],
            "properties": {
              "filename": {
                "type": "string"
              },
              "contentType": {
                "type": "string"
              },
              "contentBase64": {
                "type": "string"
              }
            }
          },
          "preset": {
            "title": "Compression level",
            "type": "string",
            "enum": [
              "screen",
              "ebook",
              "printer",
              "prepress",
              "custom"
            ],
            "default": "ebook"
          },
          "compare": {
            "title": "Compare up to three levels (slower)",
            "description": "Also runs the next levels so you can download and compare each.",
            "type": "boolean",
            "default": false
          },
          "imageDpi": {
            "title": "Image resolution (custom)",
            "type": "integer",
            "minimum": 36,
            "maximum": 600,
            "default": 120,
            "x-unit": "DPI"
          },
          "jpegQuality": {
            "title": "JPEG quality (custom)",
            "type": "integer",
            "minimum": 10,
            "maximum": 95,
            "default": 70
          },
          "grayscale": {
            "title": "Convert to grayscale",
            "type": "boolean",
            "default": false
          },
          "password": {
            "title": "PDF password (only if the file is protected)",
            "description": "Used only to open the file for this conversion; it is written to a private temporary file, never to a command line, and deleted with the job.",
            "type": "string",
            "maxLength": 200
          }
        },
        "required": [
          "file"
        ]
      },
      "PdfCompressorResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "originalBytes",
              "pages",
              "preset",
              "outputBytes",
              "savingsPercent",
              "keptOriginal",
              "variants",
              "artifact"
            ],
            "properties": {
              "originalBytes": {
                "type": "integer"
              },
              "pages": {
                "type": "integer"
              },
              "preset": {
                "type": "string"
              },
              "outputBytes": {
                "type": "integer"
              },
              "savingsPercent": {
                "type": "number",
                "description": "Positive = smaller than the original."
              },
              "keptOriginal": {
                "type": "boolean",
                "description": "True when compression did not make the file smaller and the original is returned."
              },
              "variants": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "preset",
                    "label",
                    "bytes",
                    "savingsPercent",
                    "keptOriginal",
                    "artifact"
                  ],
                  "properties": {
                    "preset": {
                      "type": "string"
                    },
                    "label": {
                      "type": "string"
                    },
                    "bytes": {
                      "type": "integer"
                    },
                    "savingsPercent": {
                      "type": "number"
                    },
                    "keptOriginal": {
                      "type": "boolean"
                    },
                    "artifact": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "artifactId",
                        "filename",
                        "mime",
                        "bytes",
                        "sha256",
                        "path"
                      ],
                      "properties": {
                        "artifactId": {
                          "type": "string"
                        },
                        "filename": {
                          "type": "string"
                        },
                        "mime": {
                          "type": "string"
                        },
                        "bytes": {
                          "type": "integer"
                        },
                        "sha256": {
                          "type": "string"
                        },
                        "path": {
                          "type": "string",
                          "description": "Download path on the same site (valid for about 2 hours)."
                        }
                      }
                    }
                  }
                }
              },
              "artifact": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "artifactId",
                  "filename",
                  "mime",
                  "bytes",
                  "sha256",
                  "path"
                ],
                "properties": {
                  "artifactId": {
                    "type": "string"
                  },
                  "filename": {
                    "type": "string"
                  },
                  "mime": {
                    "type": "string"
                  },
                  "bytes": {
                    "type": "integer"
                  },
                  "sha256": {
                    "type": "string"
                  },
                  "path": {
                    "type": "string",
                    "description": "Download path on the same site (valid for about 2 hours)."
                  }
                }
              },
              "previewBefore": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "artifactId",
                  "filename",
                  "mime",
                  "bytes",
                  "sha256",
                  "path"
                ],
                "properties": {
                  "artifactId": {
                    "type": "string"
                  },
                  "filename": {
                    "type": "string"
                  },
                  "mime": {
                    "type": "string"
                  },
                  "bytes": {
                    "type": "integer"
                  },
                  "sha256": {
                    "type": "string"
                  },
                  "path": {
                    "type": "string",
                    "description": "Download path on the same site (valid for about 2 hours)."
                  }
                }
              },
              "previewAfter": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "artifactId",
                  "filename",
                  "mime",
                  "bytes",
                  "sha256",
                  "path"
                ],
                "properties": {
                  "artifactId": {
                    "type": "string"
                  },
                  "filename": {
                    "type": "string"
                  },
                  "mime": {
                    "type": "string"
                  },
                  "bytes": {
                    "type": "integer"
                  },
                  "sha256": {
                    "type": "string"
                  },
                  "path": {
                    "type": "string",
                    "description": "Download path on the same site (valid for about 2 hours)."
                  }
                }
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}