I know there are LOTS of threads on this on SO and I have tried everyone of them, and not been able to make one of them work.
In SO thread:
Creating a new PDF by Merging PDF documents using TCPDF
this snippet by @Sygmoral sounds as if it should work (I added the Output() line and the path/files are mine):
require_once('tcpdf/tcpdf.php');
require_once('fpdi/fpdi.php'); // the addon
// FPDI extends the TCPDF class, so you keep all TCPDF functionality
$pdf = new FPDI();
$pdf->setSourceFile('pdfs/January-2014-test-1.pdf');
// FPDI's importPage returns an object that you can insert with TCPDF's useTemplate
$pdf->useTemplate($pdf->importPage(1));
$pdf->Output('mergedfile.pdf');
But I cannot for the life of me get it to function. Running in an OSX MAMP environment, PHP 5.6.2, latest versions of FPDI and TCPDF. Trying to process PDF documents created by GNUplot pdfcairo output terminal which show version 1.5, created by cairographics.
I am stumped; pointers most welcome.
In response to @Jon C:
#0 /Applications/MAMP/htdocs/fpdi/fpdi.php(327): FPDF_TPL->useTemplate(1, NULL, NULL, 0, 0)
#1 /Applications/MAMP/htdocs/mergePDF.php(10): FPDI->useTemplate(1)
#2 {main} thrown in /Applications/MAMP/htdocs/fpdi/fpdf_tpl.php on line 214
[30-Apr-2015 16:55:21 Europe/Berlin] PHP Fatal error: Uncaught exception 'LogicException' with message 'You have to add at least a page first!' in /Applications/MAMP/htdocs/fpdi/fpdf_tpl.php:214
Stack trace:
#0 /Applications/MAMP/htdocs/fpdi/fpdi.php(327): FPDF_TPL->useTemplate(1, NULL, NULL, 0, 0)
#1 /Applications/MAMP/htdocs/mergePDF.php(10): FPDI->useTemplate(1)
#2 {main} thrown in /Applications/MAMP/htdocs/fpdi/fpdf_tpl.php on line 214