使用imagic和PHP输出PDF文件 [英] output a PDF file using imagic and PHP

查看:94
本文介绍了使用imagic和PHP输出PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些PDF,它们存储在数据类型为Image的SQL Server中. 现在,我想通过PHP页面将它们与Imagic合并为一个文档.这是代码:

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 );

这有效,并将test.pdf保存到服务器,但是当我尝试输出浏览器URL时(类似于 http://www.test.com/test.php ),则无法正常运行.代码是:

This works, and the test.pdf is saved to the server, but when I try to output the browser URL (something like http://www.test.com/test.php), it does not work. 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;

推荐答案

这有效:


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();

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

Note that the key word is getImagesBlob, not getImageBlob.

这篇关于使用imagic和PHP输出PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆