views:

18

answers:

0

I have a bunch of files in my database that I want to combine to a single PDF. I am trying to do this with Imagick. I cannot seem to find good documentation and could use some help. I want to read the binary data from my database for each file and then stream the combined file to the users.

Here is what I have:

//create the Imagick object
$im = new Imagick();

//get the documents
$query = GetDocuments();

//for each document
foreach ($query['documents'] as $document) {

//create the new Imakick object
$new_file = new Imagick();

//get the new documents binary data    
$filedata = GetFileData($document['id']);

//create the new ImageBlob
$new_file->readImageBlob($filedata->Blob);
$new_file->setImageFormat($filedata->ImageFormat);

//add the new file to the total file
$im->addImage($new_file);

}

//show the file
header("Content-type: application/pdf");
$im->setImageFormat('PDF');
echo $im->getImageBlob();

What am I doing wrong? Thanks in advance!