Splitting a PDF into pages
Splitting a PDF into pages will allow you to break the document down into multiple pages using the PDF.API.
The splitNumber
parameter dictates how many pages per PDF document you desire.
Example 1
If you supply a PDF document that has 5 pages and the splitNumber
parameter = 2, the output will be 3 documents in total:
- the first document with 2 pages
- another document with 2 pages
- the final document with 1 page
Example 2
If you supply a PDF with 5 pages and the splitNumber
= 1, the output will be 5 documents each containing 1 page.
The important thing to remember is that splitting keeps the original order of the document.
You can view the full Swagger documentation here.
Request
- cURL
- Javascript
- PHP
curl --location 'https://pdf-api.doclabs.cloud/api/v1/MyDocumentWith5Pages.pdf/intopages?storageName=MyBucketName' \
--header 'Content-Type: application/json' \
--header 'x-api-key: ••••••' \
--data '{
"splitNumber": 2
}'
var settings = {
"url": "https://pdf-api.doclabs.cloud/api/v1/MyDocumentWith5Pages.pdf/intopages?storageName=MyBucketName",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "application/json",
"x-api-key": "••••••"
},
"data": JSON.stringify({
"splitNumber": 2
}),
};
$.ajax(settings).done(function (response) {
console.log(response);
});
<?php
$client = new Client();
$headers = [
'Content-Type' => 'application/json',
'x-api-key' => '••••••'
];
$body = '{
"splitNumber": 2
}';
$request = new Request('POST', 'https://pdf-api.doclabs.cloud/api/v1/MyDocumentWith5Pages.pdf/intopages?storageName=MyBucketName', $headers, $body);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
Response
{
"bucketName": "MyBucketName",
"contentPathNames": [
"DocumentWith2Pages.pdf",
"DocumentWith2Pages.pdf",
"DocumentWith1Pages.pdf"
]
}