title: PHP: Merge PDFs without composer?
body: <p>I am trying to merge PDF documents with PHP and have searched a lot and tried several solutions. What seems to be the most common is using the <strong>FPDI</strong> library and then a small class like <a href="https://github.com/clegginabox/pdf-merger" rel="nofollow noreferrer">PDF-Merger</a>.</p>
  
  <p><strong>But the problem</strong> is that that library is dependent of other libraries and those libraries of others and so on. And the installation examples is mostly how to install with composer. But I wanna be able to merge pdf's for a site that's not using composer. And it seems to be really hard to achieve that.</p>
  
  <p>Due to the <a href="https://manuals.setasign.com/fpdi-manual/v2/installation/" rel="nofollow noreferrer">manual</a>, the only thing to do if I don't wanna use the composer is writing this to your code as the installation of the library:</p>
  
  <pre><code>require_once('path/to/src/autoload.php');
  </code></pre>
  
  <p>Of course, with the correct path. But no, that didn't work for me. Couldn't find the fpdi class. And if you look at the manual again, you see this warning: </p>
  
  <blockquote>
    <p>Don't forget to install FPDF, TCPDF or tFPDF before!</p>
  </blockquote>
  
  <p>So I manually downloaded those three libraries and also those were hard to install without composer. And are still stucked in this mess. I have made some success by changing in the PDFMerger.php file from <code>use fpdi\FPDI;</code> to <code>\setasign\Fpdi\Fpdi</code>. So now is the Fpdi class found. But still get errors.</p>
  
  <p>Let me show you the current situation. <strong>Here is my current code:</strong></p>
  
  <pre><code>&lt;?php
  require_once get_stylesheet_directory().'/classes/fpdf/fpdf.php';
  require_once get_stylesheet_directory().'/classes/tfpdf/tfpdf.php';
  
  require_once get_stylesheet_directory().'/classes/tcpdf/src/Output.php';
  require_once get_stylesheet_directory().'/classes/tcpdf/src/MetaInfo.php';
  require_once get_stylesheet_directory().'/classes/tcpdf/src/ClassObjects.php';
  require_once get_stylesheet_directory().'/classes/tcpdf/src/Tcpdf.php'; 
  
  require_once get_stylesheet_directory().'/classes/FPDI/src/autoload.php';
  require_once get_stylesheet_directory().'/classes/FPDI/src/Fpdi.php';
  
  require_once get_stylesheet_directory().'/classes/PDFMerger/PDFMerger.php';
  
  $pdf = new \Clegginabox\PDFMerger\PDFMerger;
  $pdf-&gt;addPDF('path/to/file1.pdf', 'all', 'P');
  $pdf-&gt;addPDF('path/to/file2.pdf', 'all', 'P');
  $pdf-&gt;merge();
  ?&gt;
  </code></pre>
  
  <p>And here are the error messages in the browser:</p>
  
  <blockquote>
    <p>Notice: Undefined index: w in
    /home/public_html/wp-content/themes/my-theme/classes/PDFMerger/PDFMerger.php
    on line 85</p>
    
    <p>Notice: Undefined index: h in
    /home/public_html/wp-content/themes/my-theme/classes/PDFMerger/PDFMerger.php
    on line 85</p>
    
    <p>Notice: Undefined index: w in
    /home/public_html/wp-content/themes/my-theme/classes/PDFMerger/PDFMerger.php
    on line 85</p>
    
    <p>Notice: Undefined index: h in
    /home/public_html/wp-content/themes/my-theme/classes/PDFMerger/PDFMerger.php
    on line 85</p>
    
    <p>Fatal error: Uncaught Exception: FPDF error: Some data has already
    been output, can't send PDF file in
    /home/public_html/wp-content/themes/my-theme/classes/fpdf/fpdf.php:271
    Stack trace: #0
    /home/public_html/wp-content/themes/my-theme/classes/fpdf/fpdf.php(1063):
    FPDF->Error('Some data has a...') #1
    /home/public_html/wp-content/themes/my-theme/classes/fpdf/fpdf.php(999):
    FPDF->_checkoutput() #2
    /home/public_html/wp-content/themes/my-theme/classes/PDFMerger/PDFMerger.php(107): FPDF->Output('I', 'newfile.pdf') #3
    /home/public_html/wp-content/themes/my-theme/functions.php(269):
    Clegginabox\PDFMerger\PDFMerger->merge() #4
    /home/public_html/wp-includes/class-wp-hook.php(286):
    cdon_woocommerce_loaded('') #5
    /home/public_html/wp-includes/cla
    in
    /home/public_html/wp-content/themes/my-theme/classes/fpdf/fpdf.php
    on line 271</p>
  </blockquote>
  
  <p>And you can see the <a href="https://github.com/clegginabox/pdf-merger/blob/master/src/PDFMerger/PDFMerger.php" rel="nofollow noreferrer">PDFMerger.php here</a> and line 85 is this:</p>
  
  <pre><code>$fpdi-&gt;AddPage($fileorientation, array($size['w'], $size['h']));
  </code></pre>
  
  <p>I mean, I think it's a little exaggerated to have all these dependencies to just merge pdfs. Is this really needed? And if so, what is wrong with my installation?</p>