PDF Merger

Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.

Popular code excerpts may be moved to "Code Snippets" by the moderators.

Moderator: General Moderators

Post Reply
User avatar
JNettles
Forum Contributor
Posts: 228
Joined: Mon Oct 05, 2009 4:09 pm

PDF Merger

Post by JNettles »

http://pdfmerger.codeplex.com/Release/P ... adId=99109

(Its a 1mb download but half of it is the example PDFs I put - generously provided by the United States Internal Revenue Service.)

Born out of my frustration in merging PDFs together in PHP, PDF Merger lets you concatenate PDFs (or certain pages of) together. If someone could take a look at my class in PDFMerger.php and offer some feedback I'd appreciate it.

You can merge all the pages or do it printer style - 1, 3, 17, 22-43 or 'all'. After you unpack, upload it and then the code is as follows.

Code: Select all

<?php
include 'PDFMerger.php';
 
$pdf = new PDFMerger;
 
$pdf->addPDF('samplepdfs/one.pdf', '1, 3, 4')
    ->addPDF('samplepdfs/two.pdf', '1-2')
    ->addPDF('samplepdfs/three.pdf', 'all')
    ->merge('file', 'samplepdfs/TEST2.pdf');
    
    //REPLACE 'file' WITH 'browser', 'download', 'string', or 'file' for output options
    //You do not need to give a file path for browser, string, or download - just the name.
 
It uses the FreePDF and FPDI libraries (which I included in the download since they seem pretty obscure) for PDF handling.
Post Reply