Split PDF in PHP SDK
Split PDF files in PHP Cloud API without the use of any software like Adobe PDF.
Get StartedHow to Split PDF files Using Cloud API for PHP
Why do I need to split PDF documents? Splitting PDFs with PHP can be necessary when managing and organizing large documents or working in a data processing environment. Sometimes a larger document requires only a separate section or set of pages. The PDF split allows you to highlight and extract the corresponding pages without the rest of the document.
Also, sending or sharing all of the PDFs may be inefficient, especially if the document is large and contains more information than necessary. When splitting PDFs, you only need to separate the corresponding pages, which makes the process faster and saves bandwidth.
Splitting PDF into smaller sections can reduce the file size, which is useful when you are having storage problems or loading documents onto systems with size restrictions.
Package Manager Console Command
composer install
Steps for Splitting PDF via Cloud PHP SDK
A basic splitting pdfs programmatically with Aspose.PDF Cloud PHP SDK APIs can be done with just few lines of code.
- Install PHP SDK.
- Go to the Aspose Cloud Dashboard.
- Create a new Account to access all applications and services or Sign In to your account.
- Click on Applications in the left menu to get Client Id and Client Secret.
- Check out the Developer Guide to split a PDF in PHP.
- Check out our GitHub repository for a complete API list along with working examples.
- Check out the API Reference page for the description of APIs parameters.
System Requirements
It is easy to get started with Aspose.PDF Cloud PHP SDK and there is nothing to install. Simply create an account at Aspose for Cloud and get your application information. Once you have the App SID & key, you are ready to give the Aspose.PDF Cloud PHP SDK.
- PHP 7.4 and later.
Split single PDF Files using PHP
<?php
require_once 'vendor/autoload.php';
use Aspose\Pdf\Configuration;
use Aspose\Pdf\Api\PdfApi;
use Aspose\Pdf\Model\SplitResult;
function splitSingle()
{
// Load credentials from JSON file
$credentials = json_decode(file_get_contents('credentials.json'), true);
$appSid = $credentials['id'];
$appKey = $credentials['key'];
// Initialize the PDF API
$config = new Configuration();
$config->setAppSid($appSid);
$config->setAppKey($appKey);
$pdfApi = new PdfApi($config);
// Define local and storage file names
$localFileName = 'input.pdf';
$storageFileName = 'uploaded_input.pdf';
try {
// Upload the PDF file to Aspose Cloud Storage
$pdfApi->uploadFile($storageFileName, fopen($localFileName, 'r'));
// Split the PDF document
$splitResult = $pdfApi->splitDocument($storageFileName);
// Check if the split operation was successful
if ($splitResult->getCode() === 200) {
echo "Split operation successful.\n";
// Download each split document
$documents = $splitResult->getResult()->getDocuments();
foreach ($documents as $index => $document) {
$fileName = "page" . ($index + 1) . ".pdf";
$fileContent = $pdfApi->downloadFile($document->getHref());
file_put_contents($fileName, $fileContent);
echo "Downloaded: $fileName\n";
}
} else {
echo "Error: " . $splitResult->getStatus() . "\n";
}
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), "\n";
}
}
With our PHP library you can:
- Add PDF document’s header & footer in text or image format.
- Add tables & stamps (text or image) to PDF documents.
- Append multiple PDF documents to an existing file.
- Work with PDF attachments, annotations, & form fields.
- Apply encryption or decryption to PDF documents & set a password.
- Delete all stamps & tables from a page or entire PDF document.
- Delete a specific stamp or table from the PDF document by its ID.
- Replace single or multiple instances of text on a PDF page or from the entire document.
- Extensive support for converting PDF documents to various other file formats.
- Extract various elements of PDF files & make PDF documents optimized.
- You can try out our free App to split PDF files online and test the functionality.
- Learning Resources
- Documentation
- Source Code
- API References
- Product Support
- Free Support
- Paid Support
- Blog
- Why Aspose.PDF Cloud for PHP?
- Customers List
- Security