curl
curl --request POST \
--url https://api.iyzpdf.com/v1/pdf/compress \
--header "X-API-Key: $IYZPDF_API_KEY" \
--form "file=@catalog.pdf" \
--form "quality=medium" \
--output catalog-compressed.pdfimport os
import requests
api_key = os.environ["IYZPDF_API_KEY"]
with open("catalog.pdf", "rb") as file_handle:
response = requests.post(
"https://api.iyzpdf.com/v1/pdf/compress",
headers={"X-API-Key": api_key},
files={"file": ("catalog.pdf", file_handle, "application/pdf")},
data={"quality": "medium"},
timeout=60,
)
if not response.ok:
raise Exception(response.text)
with open("catalog-compressed.pdf", "wb") as output_file:
output_file.write(response.content)import { readFileSync } from "node:fs";
import { writeFile } from "node:fs/promises";
const apiKey = process.env.IYZPDF_API_KEY;
const form = new FormData();
form.append("file", new Blob([readFileSync("catalog.pdf")], { type: "application/pdf" }), "catalog.pdf");
form.append("quality", "medium");
const response = await fetch("https://api.iyzpdf.com/v1/pdf/compress", {
method: "POST",
headers: {
"X-API-Key": apiKey
},
body: form
});
if (!response.ok) {
throw new Error(await response.text());
}
await writeFile("catalog-compressed.pdf", Buffer.from(await response.arrayBuffer()));<?php
$apiKey = getenv('IYZPDF_API_KEY');
$ch = curl_init('https://api.iyzpdf.com/v1/pdf/compress');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'X-API-Key: ' . $apiKey,
],
CURLOPT_POSTFIELDS => [
'file' => new CURLFile('catalog.pdf', 'application/pdf', 'catalog.pdf'),
'quality' => 'medium',
],
]);
$pdf = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($pdf === false || $status !== 200) {
throw new RuntimeException('Request failed: ' . curl_error($ch) . PHP_EOL . $pdf);
}
file_put_contents('catalog-compressed.pdf', $pdf);
curl_close($ch);import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
public class CompressPdfExample {
public static void main(String[] args) throws IOException {
String apiKey = System.getenv("IYZPDF_API_KEY");
OkHttpClient client = new OkHttpClient();
RequestBody formBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart(
"file",
"catalog.pdf",
RequestBody.create(Files.readAllBytes(Path.of("catalog.pdf")), MediaType.parse("application/pdf")))
.addFormDataPart("quality", "medium")
.build();
Request request = new Request.Builder()
.url("https://api.iyzpdf.com/v1/pdf/compress")
.addHeader("X-API-Key", apiKey)
.post(formBody)
.build();
try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful() || response.body() == null) {
String errorBody = response.body() != null ? response.body().string() : "";
throw new IOException("Request failed: " + response.code() + " " + errorBody);
}
Files.write(Path.of("catalog-compressed.pdf"), response.body().bytes());
}
}
}var apiKey = Environment.GetEnvironmentVariable("IYZPDF_API_KEY");
using var client = new HttpClient();
using var form = new MultipartFormDataContent();
await using var fileStream = File.OpenRead("catalog.pdf");
client.DefaultRequestHeaders.Add("X-API-Key", apiKey);
form.Add(new StreamContent(fileStream), "file", "catalog.pdf");
form.Add(new StringContent("medium"), "quality");
using var response = await client.PostAsync(
"https://api.iyzpdf.com/v1/pdf/compress",
form);
response.EnsureSuccessStatusCode();
await using var output = File.Create("catalog-compressed.pdf");
await response.Content.CopyToAsync(output);{
"fileName": "output.pdf",
"size": 183240,
"creditsUsed": 1,
"creditsRemaining": 49,
"contentType": "application/pdf"
}{
"error": {
"code": "INVALID_REQUEST",
"message": "The request payload is invalid or incomplete."
}
}{
"error": {
"code": "UNAUTHORIZED",
"message": "Missing or invalid API key."
}
}{
"error": {
"code": "INSUFFICIENT_CREDITS",
"message": "You need more credits to complete this request.",
"creditsRequired": 2,
"creditsBalance": 0,
"purchaseUrl": "https://iyzpdf.com/portal/credits"
}
}{
"error": {
"code": "FILE_TOO_LARGE",
"message": "The uploaded file or request body exceeds the allowed size limit."
}
}{
"error": {
"code": "UNSUPPORTED_MEDIA_TYPE",
"message": "The uploaded file type or content type is not supported."
}
}{
"error": {
"code": "RATE_LIMIT_EXCEEDED",
"message": "Too many requests. Please retry after the rate limit resets."
}
}{
"error": {
"code": "PROCESSING_FAILED",
"message": "The document could not be processed."
}
}PDF Editing
Compress PDF
Compress a PDF document with low, medium, or high quality settings.
POST
https://api.iyzpdf.com/v1
/
pdf
/
compress
curl
curl --request POST \
--url https://api.iyzpdf.com/v1/pdf/compress \
--header "X-API-Key: $IYZPDF_API_KEY" \
--form "file=@catalog.pdf" \
--form "quality=medium" \
--output catalog-compressed.pdfimport os
import requests
api_key = os.environ["IYZPDF_API_KEY"]
with open("catalog.pdf", "rb") as file_handle:
response = requests.post(
"https://api.iyzpdf.com/v1/pdf/compress",
headers={"X-API-Key": api_key},
files={"file": ("catalog.pdf", file_handle, "application/pdf")},
data={"quality": "medium"},
timeout=60,
)
if not response.ok:
raise Exception(response.text)
with open("catalog-compressed.pdf", "wb") as output_file:
output_file.write(response.content)import { readFileSync } from "node:fs";
import { writeFile } from "node:fs/promises";
const apiKey = process.env.IYZPDF_API_KEY;
const form = new FormData();
form.append("file", new Blob([readFileSync("catalog.pdf")], { type: "application/pdf" }), "catalog.pdf");
form.append("quality", "medium");
const response = await fetch("https://api.iyzpdf.com/v1/pdf/compress", {
method: "POST",
headers: {
"X-API-Key": apiKey
},
body: form
});
if (!response.ok) {
throw new Error(await response.text());
}
await writeFile("catalog-compressed.pdf", Buffer.from(await response.arrayBuffer()));<?php
$apiKey = getenv('IYZPDF_API_KEY');
$ch = curl_init('https://api.iyzpdf.com/v1/pdf/compress');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'X-API-Key: ' . $apiKey,
],
CURLOPT_POSTFIELDS => [
'file' => new CURLFile('catalog.pdf', 'application/pdf', 'catalog.pdf'),
'quality' => 'medium',
],
]);
$pdf = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($pdf === false || $status !== 200) {
throw new RuntimeException('Request failed: ' . curl_error($ch) . PHP_EOL . $pdf);
}
file_put_contents('catalog-compressed.pdf', $pdf);
curl_close($ch);import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
public class CompressPdfExample {
public static void main(String[] args) throws IOException {
String apiKey = System.getenv("IYZPDF_API_KEY");
OkHttpClient client = new OkHttpClient();
RequestBody formBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart(
"file",
"catalog.pdf",
RequestBody.create(Files.readAllBytes(Path.of("catalog.pdf")), MediaType.parse("application/pdf")))
.addFormDataPart("quality", "medium")
.build();
Request request = new Request.Builder()
.url("https://api.iyzpdf.com/v1/pdf/compress")
.addHeader("X-API-Key", apiKey)
.post(formBody)
.build();
try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful() || response.body() == null) {
String errorBody = response.body() != null ? response.body().string() : "";
throw new IOException("Request failed: " + response.code() + " " + errorBody);
}
Files.write(Path.of("catalog-compressed.pdf"), response.body().bytes());
}
}
}var apiKey = Environment.GetEnvironmentVariable("IYZPDF_API_KEY");
using var client = new HttpClient();
using var form = new MultipartFormDataContent();
await using var fileStream = File.OpenRead("catalog.pdf");
client.DefaultRequestHeaders.Add("X-API-Key", apiKey);
form.Add(new StreamContent(fileStream), "file", "catalog.pdf");
form.Add(new StringContent("medium"), "quality");
using var response = await client.PostAsync(
"https://api.iyzpdf.com/v1/pdf/compress",
form);
response.EnsureSuccessStatusCode();
await using var output = File.Create("catalog-compressed.pdf");
await response.Content.CopyToAsync(output);{
"fileName": "output.pdf",
"size": 183240,
"creditsUsed": 1,
"creditsRemaining": 49,
"contentType": "application/pdf"
}{
"error": {
"code": "INVALID_REQUEST",
"message": "The request payload is invalid or incomplete."
}
}{
"error": {
"code": "UNAUTHORIZED",
"message": "Missing or invalid API key."
}
}{
"error": {
"code": "INSUFFICIENT_CREDITS",
"message": "You need more credits to complete this request.",
"creditsRequired": 2,
"creditsBalance": 0,
"purchaseUrl": "https://iyzpdf.com/portal/credits"
}
}{
"error": {
"code": "FILE_TOO_LARGE",
"message": "The uploaded file or request body exceeds the allowed size limit."
}
}{
"error": {
"code": "UNSUPPORTED_MEDIA_TYPE",
"message": "The uploaded file type or content type is not supported."
}
}{
"error": {
"code": "RATE_LIMIT_EXCEEDED",
"message": "Too many requests. Please retry after the rate limit resets."
}
}{
"error": {
"code": "PROCESSING_FAILED",
"message": "The document could not be processed."
}
}Notes
- Credits:
2 - Default quality is
medium - Authenticated uploads are limited to
100 MB - The generated output file name is
compressed.pdf - Success responses also include
X-Original-Size,X-Compressed-Size, andX-Compression-Ratio
Authorizations
Send your server-side API key in the X-API-Key header.
Body
multipart/form-data