Add Files or Documents

Introduction

The Merger component allows you to add PDF documents in 2 ways: It accepts a filename via the addFile() method or an existing document instance via theĀ  addDocument() method. 

The addFile() and addDocument() Methods

Both methods are nearly identical in their method signature. The only difference is that the one accepts a path to a file and the other accepts an existing document instance

addDocument()

Add a document.

addFile()

Add a document by filename.

So a simplest merge process could look like:

PHP
<?php
require_once('library/SetaPDF/Autoload.php');

$merger = new SetaPDF_Merger();
// add files from the file system
$merger->addFile('files/pdfs/camtown/products/Boombastic-Box.pdf');
$merger->addFile('files/pdfs/camtown/products/Fantastic-Speaker.pdf');

// initiate a document instance
$existingDocument = SetaPDF_Core_Document::loadByString(
    file_get_contents('files/pdfs/camtown/products/Noisy-Tube.pdf')
);
// and add this instance
$merger->addDocument($existingDocument);

// merge them together
$merger->merge();

// get the resulting document instance
$document = $merger->getDocument();
// add a writer
$document->setWriter(new SetaPDF_Core_Writer_Http('simple.pdf', true));
// save and finish
$document->save()->finish();            

Details about the other parameters are described on the following pages: