1

我有一些 PDF 存储在 SQL 服务器中,数据类型为 Image。现在我想用 PHP 页面中的 Imagic 将它们合并到一个文档中。这是代码:

$combined = new Imagick();

而($document = mssql_fetch_assoc($mssqlResult){
    $image = 新的想象();
    $image->readImageBlob($document['Contents']);
    $combined->addImage($image);
    $图像->清除();
    $image->destroy();
}
$combined->setImageFormat("pdf");
$combined->writeImages('test.pdf', true);

这有效,并且 test.pdf 保存到服务器,但是当我尝试输出浏览器 URL(类似于http://www.test.com/test.php)时,它不起作用。代码是:

$combined = new Imagick();

而($document = mssql_fetch_assoc($mssqlResult){
    $image = 新的想象();
    $image->readImageBlob($document['Contents']);
    $combined->addImage($image);
    $图像->清除();
    $image->destroy();
}

//$combined->getImageBlob();

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

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

header('内容类型:应用程序/pdf');

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

回声$组合;
4

2 回答 2

1

这有效:

组合 = 新的 Imagick();

而($document = mssql_fetch_assoc($mssqlResult){
    $image = 新的想象();
    $image->readImageBlob($document['Contents']);
    $combined->addImage($image);
    $图像->清除();
    $image->destroy();
}

$combined->setImageFormat("pdf");

header('内容类型:应用程序/pdf');
header('Content-Disposition: attachment; filename="test.pdf"');
echo $combined->getImagesBlob();

请注意,关键字是getImagesBlob,不是getImageBlob

于 2010-10-06T10:53:59.667 回答
1
$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');
于 2010-10-06T09:16:06.910 回答