Merge PDFs API
Category: pdf
Combine multiple PDF files into a single PDF document. Files are merged in the order they are uploaded.
Endpoint
POST
https://anythingtext.com/api/tools/pdfmerge
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 |
Two or more PDF files to merge
Example: file1.pdf, file2.pdf
|
Response
Content-Type: application/pdf
Merged PDF file as binary download
(binary PDF data)
Error Responses
| Status | Description | Body |
|---|---|---|
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/pdfmerge \ -H "X-API-Key: your_api_key_here" \ -F "files=@file1.pdf" \ -F "files=@file2.pdf" \ --output merged.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/pdfmerge', {
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/pdfmerge',
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/pdfmerge"))
.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");