Image to PDF API

Category: pdf

Convert one or more images (JPG, PNG, WebP) into a multi-page PDF document.

Endpoint

POST https://anythingtext.com/api/tools/img2pdf
Authentication Required Content-Type: multipart/form-data

Authentication

This API requires an API key. Generate one from the API Keys section in your dashboard settings.

Include the X-API-Key header in all API requests:

X-API-Key: atk_your_api_key_here

Rate Limiting

API requests are limited to 60 requests per minute per user. If you exceed this limit, the API returns a 429 Too Many Requests response.

Every response includes rate limit headers:

X-RateLimit-Limit: 60
X-RateLimit-Remaining: 57
X-RateLimit-Reset: 42

When rate limited, the response body contains:

{ "error": "Rate limit exceeded. Maximum 60 requests per minute.", "retryAfter": 42, "limit": 60 }

Request Parameters

Name Type Required Description
files File[] Required Image files to convert (JPG, PNG, WebP)
Example: photo1.jpg, photo2.png

Response

Content-Type: application/pdf

PDF document containing the images

(binary PDF data)

Error Responses

StatusDescriptionBody
401 Not authenticated {"error": "Please log in..."}
400 Bad request / Missing required params {"error": "... is required"}
500 Internal server error {"error": "Failed to ..."}

cURL Example

curl -X POST https://anythingtext.com/api/tools/img2pdf \
  -H "X-API-Key: your_api_key_here" \
  -F "files=@photo1.jpg" \
  -F "files=@photo2.png" \
  --output images.pdf

Code Samples

const formData = new FormData();

// Add multiple files
for (const file of fileInput.files) {
    formData.append('files', file);
}

const response = await fetch('https://anythingtext.com/api/tools/img2pdf', {
    method: 'POST',
    headers: { 'X-API-Key': 'your_api_key_here' },
    body: formData
});

const blob = await response.blob();
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'output.pdf';
a.click();
import requests

files = [
    ('files', open('file1.pdf', 'rb')),
    ('files', open('file2.pdf', 'rb')),
]

response = requests.post(
    'https://anythingtext.com/api/tools/img2pdf',
    files=files,
    headers={'X-API-Key': 'your_api_key_here'}
)

with open('output.pdf', 'wb') as f:
    f.write(response.content)

print('Saved to output.pdf')
import java.net.URI;
import java.net.http.*;
import java.nio.file.*;
import java.io.*;

HttpClient client = HttpClient.newHttpClient();
String boundary = "----Boundary" + System.currentTimeMillis();

// Build multipart body with multiple files
ByteArrayOutputStream baos = new ByteArrayOutputStream();
for (String filePath : List.of("file1.pdf", "file2.pdf")) {
    byte[] fileBytes = Files.readAllBytes(Path.of(filePath));
    String part = "--" + boundary + "\r\n"
        + "Content-Disposition: form-data; name=\"files\"; filename=\"" + filePath + "\"\r\n"
        + "Content-Type: application/octet-stream\r\n\r\n";
    baos.write(part.getBytes());
    baos.write(fileBytes);
    baos.write("\r\n".getBytes());
}
baos.write(("--" + boundary + "--").getBytes());

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://anythingtext.com/api/tools/img2pdf"))
    .header("Content-Type", "multipart/form-data; boundary=" + boundary)
    .header("X-API-Key", "your_api_key_here")
    .POST(HttpRequest.BodyPublishers.ofByteArray(baos.toByteArray()))
    .build();

HttpResponse<byte[]> response = client.send(request,
    HttpResponse.BodyHandlers.ofByteArray());

Files.write(Path.of("output.pdf"), response.body());
System.out.println("Saved to output.pdf");