Skip to content
HALOWERK

Formatwerk

pdf compress to size

Measures the largest placed size of every image XObject from the page content (pdf-lib 1.17.1 plus own content interpreter) and derives its effective resolution. Lossless steps come first: uncompressed streams are Flate-compressed, page thumbnails optionally dropped, unreachable objects removed and objects packed into object streams. If the file is still above target_bytes, 8-bit Gray/RGB images (JPEG or Flate, PNG predictors supported) are resampled with Lanczos in sharp/libvips along fixed.

POST https://format.halowerk.com/v1/pdf-compress-to-size

Inputs

Fields of the published input schema
FieldTypeRequiredDescription
content_base64stringNoThe PDF as base64 (a data: prefix and whitespace are tolerated); at most 10 MB decoded.
urlstringNoPublic http(s) URL of the PDF (at most 10 MB). Private, local and reserved addresses are refused.
target_bytesintegerYesDesired maximum file size in bytes.
min_ppiintegerNoReadability limit: images are never resampled below this effective resolution.
min_jpeg_qualityintegerNoReadability limit: JPEG quality (libjpeg scale) is never set below this value.
lossybooleanNoAllow converting lossless (Flate) images to JPEG when that is smaller.
drop_thumbnailsbooleanNoRemove embedded page thumbnails (viewers regenerate them).
Show full input schema
{
  "type": "object",
  "additionalProperties": false,
  "required": [
    "target_bytes"
  ],
  "properties": {
    "content_base64": {
      "type": "string",
      "minLength": 8,
      "maxLength": 13981016,
      "description": "The PDF as base64 (a data: prefix and whitespace are tolerated); at most 10 MB decoded."
    },
    "url": {
      "type": "string",
      "format": "uri",
      "maxLength": 2048,
      "description": "Public http(s) URL of the PDF (at most 10 MB). Private, local and reserved addresses are refused."
    },
    "target_bytes": {
      "type": "integer",
      "minimum": 1000,
      "maximum": 10485760,
      "description": "Desired maximum file size in bytes."
    },
    "min_ppi": {
      "type": "integer",
      "minimum": 72,
      "maximum": 600,
      "default": 150,
      "description": "Readability limit: images are never resampled below this effective resolution."
    },
    "min_jpeg_quality": {
      "type": "integer",
      "minimum": 40,
      "maximum": 95,
      "default": 60,
      "description": "Readability limit: JPEG quality (libjpeg scale) is never set below this value."
    },
    "lossy": {
      "type": "boolean",
      "default": true,
      "description": "Allow converting lossless (Flate) images to JPEG when that is smaller."
    },
    "drop_thumbnails": {
      "type": "boolean",
      "default": true,
      "description": "Remove embedded page thumbnails (viewers regenerate them)."
    }
  }
}

Open original schema

Published input example

{
  "content_base64": "JVBERi0xLjcKMSAwIG9iago8PC9UeXBlL0NhdGFsb2cvUGFnZXMgMiAwIFIvQWNyb0Zvcm08PC9GaWVsZHNbNCAwIFIgNSAwIFJdPj4+PgplbmRvYmoKMiAwIG9iago8PC9UeXBlL1BhZ2VzL0tpZHNbMyAwIFJdL0NvdW50IDE+PgplbmRvYmoKMyAwIG9iago8PC9UeXBlL1BhZ2UvUGFyZW50IDIgMCBSL01lZGlhQm94WzAgMCAzMDAgMjAwXS9Bbm5vdHNbNCAwIFIgNSAwIFJdPj4KZW5kb2JqCjQgMCBvYmoKPDwvVHlwZS9Bbm5vdC9TdWJ0eXBlL1dpZGdldC9GVC9UeC9UKG5hbWUpL1RVKEZ1bGwgbmFtZSkvTWF4TGVuIDQwL0ZmIDIvUmVjdFsyMCAxNTAgMjIwIDE2OF0vUCAzIDAgUj4+CmVuZG9iago1IDAgb2JqCjw8L1R5cGUvQW5ub3QvU3VidHlwZS9XaWRnZXQvRlQvQ2gvVChjb3VudHJ5KS9GZiAxMzEwNzIvT3B0WyhERSkoQVQpKENIKV0vVihERSkvRFYoREUpL1JlY3RbMjAgMTIwIDgwIDEzOF0vUCAzIDAgUj4+CmVuZG9iagp4cmVmCjAgNgowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDAwMDkgMDAwMDAgbiAKMDAwMDAwMDA4NyAwMDAwMCBuIAowMDAwMDAwMTM4IDAwMDAwIG4gCjAwMDAwMDAyMjMgMDAwMDAgbiAKMDAwMDAwMDM0MSAwMDAwMCBuIAp0cmFpbGVyCjw8L1NpemUgNi9Sb290IDEgMCBSPj4Kc3RhcnR4cmVmCjQ3MwolJUVPRgo=",
  "target_bytes": 100000
}

Result & documentation

Machine-readable documentation of this hub

Source of this page: the published HALOWERK catalog. Updated: 2026-11-17 UTC.

More endpoints in this hub

All endpoints in this hub โ†’