Split PDF programmatically
Contents
[
Hide
]
You can split PDF files using Aspose.PDF and get the results online at this link: products.aspose.app/pdf/splitter
This topic shows how to split PDF pages with Aspose.PDF for PHP via Java into individual PDF files in your PHP applications. To split PDF pages into single page PDF files using PHP, the following steps can be followed:
- Loop through the pages of PDF document through the Document object’s PageCollection collection.
- For each iteration, create a new Document object and add the individual Page object into the empty document.
- Save the new PDF using Save method.
The following PHP code snippet shows you how to split PDF pages into individual PDF files.
// Open document
$document = new Document($inputFile);
$pages = $document->getPages();
$pagesSize = java_values($pages->size());
// Loop through all the pages
for ($pageCount = 1; $pageCount <= $pagesSize; $pageCount++) {
$page = $pages->get_Item($pageCount);
$newDocument = new Document();
$newDocument->getPages()->add($page);
$newDocument->save($outputFile . "page_" . $pageCount . ".pdf");
$newDocument->close();
}
$document->close();