tags:

views:

50

answers:

3

i have some pdf's that are stored in a SQL server with data type Image. Now I want to merge them into a single document with Imagic from a PHP page. here is the code


$combined   =   new Imagick();

while( $document    =   mssql_fetch_assoc( $mssqlResult ){
    $image      =   new Imagick(); 
    $image->readImageBlob( $document['Contents'] ) ;
    $combined->addImage( $image );
    $image->clear();
    $image->destroy(); 
}
$combined->setImageFormat("pdf");
$combined->writeImages( 'test.pdf', true );

this will work and the test.pdf will be saved to sever. but when I try to output therough browser url(some thing like http://www.test.com/test.php), it will not works. the code is

$combined   =   new Imagick();

while( $document    =   mssql_fetch_assoc( $mssqlResult ){
    $image      =   new Imagick(); 
    $image->readImageBlob( $document['Contents'] ) ;
    $combined->addImage( $image );
    $image->clear();
    $image->destroy(); 
}

//$combined->getImageBlob();

//$combined->setImageFormat("pdf");

//$combined->writeImages( 'test.pdf', true );

header('Content-type: application/pdf');

header('Content-Disposition: attachment; filename="test.pdf"');

echo $combined;

any help would be appreciated

A: 
$combined   =   new Imagick();

while( $document    =   mssql_fetch_assoc( $mssqlResult ){
    $image      =   new Imagick(); 
    $image->readImageBlob( $document['Contents'] ) ;
    $combined->addImage( $image );
    $image->clear();
    $image->destroy(); 
}

$combined->getImageBlob();

$combined->setImageFormat("pdf");

$combined->writeImages( 'test.pdf', true );

header('Content-type: application/pdf');

header('Content-Disposition: attachment; filename="test.pdf"');

echo file_get_contents('test.pdf');
Flave
A: 

thanks for the replay from Flave. But my problem is, I need to remove the following code pice

$combined->writeImages( 'test.pdf', true );

Because, we allready have entire pdf content($document['Contents']) from the database. my object is read it something like this

  $var =  file_get_contents('http://www.test.com/test.php') 

and save to database againe

riyas kp
A: 

i got a solution for this


combined   =   new Imagick();

while( $document    =   mssql_fetch_assoc( $mssqlResult ){
    $image      =   new Imagick(); 
    $image->readImageBlob( $document['Contents'] ) ;
    $combined->addImage( $image );
    $image->clear();
    $image->destroy(); 
}

$combined->setImageFormat("pdf");

header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="test.pdf"');
echo $combined->getImagesBlob();

this will works. not that the keyword is getImagesBlob not getImageBlob

riyas kp