PDFMerger in loop


Can you guys help me, I try to merge a pdf file with PDFMerger, this is the sample code :

$pdf->addPDF('samplepdfs/one.pdf', '1, 3, 4') ->addPDF('samplepdfs/two.pdf', '1-2') ->addPDF('samplepdfs/three.pdf', 'all') ->merge('browser', 'samplepdfs/TEST2.pdf');

and how do I put the 'addPDF('samplepdfs/filename.pdf', '1-2')' in loop, so I can merge many pdf files in php dynamically ?


Well, never used that library, but I would expect this wo work:

<?php $pdfCatalog = [ ['samplepdfs/one.pdf', '1, 3, 4'], ['samplepdfs/two.pdf', '1-2'], ['samplepdfs/three.pdf', 'all'] ]; // $pdf = ....... (instantiation of the $pdf object, missing in your code above...) foreach ($pdfCatalog as $pdfDocument) { $pdf->addPDF($pdfDocument[0], $pdfDocument[1]); } $pdf->merge('browser', 'samplepdfs/TEST2.pdf');

<em>Note: I did not test this, but it appears logical from a normal understanding of the php syntax. It should work unless that library has been implemented totally borked...</em>


  • How do I convert Rtf to Text using ASP.Net?
  • Turn list output into an array of objects or something similar using Powershell
  • Conditional render in tagfile depending on whether the attribute is specified or not
  • How can I add web content type in liferay 6?
  • what makes a request a new request in asp.net C#
  • List images(01.png) and descriptions(01.txt) from directory
  • how to upload multiple files in c# windows application
  • System.InvalidCastException: Specified cast is not valid
  • debug library loaded with ctypes using gdb
  • Mysterious problem with floating point in LISP - time axis generation
  • How to know when stdin is empty if it contains EOF?
  • Combining SpatialPolygonsDataFrame of two neighbour countries
  • Refering to the class itself from within a class mehod in Objective C
  • Read a local file using javascript
  • Get data from AJAX - How to
  • How to install a .deb file on a jailbroken iphone programmatically?
  • How to use an array of arrays with array_map(…) in PHP?
  • ImageMagick, replace semi-transparent white with opaque white
  • Handling un-mapped Rest path
  • Java: can you cast Class into a specific interface?
  • Initializer list vs. initialization method
  • FB SDK and cURL: Unknown SSL protocol error in connection to graph.facebook.com:443
  • Nant, Vault & Windows Integrated Authentication
  • Apache 2.4 and php-fpm does not trigger apache http basic auth for php pages
  • AES padding and writing the ciphertext to a disk file
  • Updating server-side rendering client-side
  • Does CUDA 5 support STL or THRUST inside the device code?
  • How to extract text from Word files using C#?
  • Upload files with Ajax and Jquery
  • Timeout for blocking function call, i.e., how to stop waiting for user input after X seconds?
  • Do I've to free mysql result after storing it?
  • Why winpcap requires both .lib and .dll to run?
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • How do I rollback to a specific git commit
  • Is there a mandatory requirement to switch app.yaml?
  • A cron job substitute?
  • json Serialization in asp
  • Busy indicator not showing up in wpf window [duplicate]
  • reshape alternating columns in less time and using less memory
  • Reading document lines to the user (python)