FPDI - File size problem when splitting PDF

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
apor
Forum Newbie
Posts: 1
Joined: Tue Oct 04, 2016 12:31 pm

FPDI - File size problem when splitting PDF

Post by apor »

If I have a PDF on 10 pages with a file size of 4.5mb. When I split all the pages of this larger pdf into 10 pdf files with one page each, each file will then also be 4.5mb. So the size of every individual page split into single pdf's does not reduce size.

Is there anyway I can reduce the size? because when I rearrange the 10 pages and combine the 10 pdf's again into a new file it will be 45mb, which is super unhandy.

Code: Select all

require_once "$docroot/fpdf/fpdf.php"; 
require_once "$docroot/fpdi/fpdi.php"; 

function split_sample_pdf() 
{ 

$files = glob("./samplepdfs/*"); 

$pdf = new FPDI(); 
$pageCount = $pdf->setSourceFile($files[0]); 
$pdf->close(); 
for ($x = 1; $x <= $pageCount; $x++) 
{ 
$pdf = new FPDI(); 
$pdf->addPage(); 
$pdf->setSourceFile($files[0]); 

$pdf->useTemplate($pdf->importPage($x)); 

$pdf->Output("./split_samples/pdf-". $x .".pdf", "F"); 

$pdf->close(); 

} 

}
Post Reply