PDF Squeezer API Sign Up

PHP PDF Compression API

Call the PDF Squeezer PDF compression REST API from PHP using cURL or Guzzle. Send a file and optional parameters to get an optimized PDF.

$apiKey = getenv('PDF_SQUEEZER_KEY');
$apiUrl = 'https://api.pdfsqueezer.io/v1/compress';
$inputPath = 'original.pdf';
$outputPath = 'optimized.pdf';

$curl = curl_init();
curl_setopt_array($curl, [
  CURLOPT_URL => $apiUrl . '?quality=85&maxDimension=1600&stripMetadata=true&convertToJpeg=true',
  CURLOPT_POST => true,
  CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $apiKey],
  CURLOPT_POSTFIELDS => [
    'file' => new CURLFile($inputPath, 'application/pdf', basename($inputPath))
  ],
  CURLOPT_RETURNTRANSFER => true
]);

$response = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);

if ($httpCode === 200) {
  file_put_contents($outputPath, $response);
  echo "Compression successful.\n";
} else {
  echo "API Error: $response\n";
}

Full endpoint reference ยท Authentication

Get a free API key