如何将 2 个 tiff 图像转换为 PDF,我已经知道如何将图像从数据库中取出,然后使用 echo 打印它并设置 MIME 类型。
但是,知道我需要使用双面打印机选项,所以我需要一种从我的 PHP 页面内部生成 PDF 的方法,该 PDF 必须包含两个 TIFF 图像(每页一个)我该怎么做?php 需要什么才能使用该库。
非常感谢。
编辑:
是一个自托管的应用程序,我拥有服务器(实际上我使用的是 WAMP 2)。
我从 MySQL DB 中提取图像(使用 LONGBLOBS 存储)。
如何将 2 个 tiff 图像转换为 PDF,我已经知道如何将图像从数据库中取出,然后使用 echo 打印它并设置 MIME 类型。
但是,知道我需要使用双面打印机选项,所以我需要一种从我的 PHP 页面内部生成 PDF 的方法,该 PDF 必须包含两个 TIFF 图像(每页一个)我该怎么做?php 需要什么才能使用该库。
非常感谢。
编辑:
是一个自托管的应用程序,我拥有服务器(实际上我使用的是 WAMP 2)。
我从 MySQL DB 中提取图像(使用 LONGBLOBS 存储)。
There is a very simple PHP script that interfaces with ImageMagick:
How to convert multipage TIFF to PDF in PHP
I haven't used it myself but it looks all right. For this you will need
the linked article describes how to install those in a Ubuntu Linux environment.
Another road to take would be inserting the images directly into a auto-generated PDF file without ImageMagick. The best-known PDF generation library, FPDF, can do this, but for JPEG, PNG and GIF only.
Maybe one of these works for you.
您真正需要的是一个为您带来 PDF 合成引擎的库。当然,您需要该引擎来支持图像插入(特别是 TIFF)。
最好的选择是 iText。
public void createPdf(String filename) throws DocumentException, IOException
{
// step 1
Document document = new Document();
// step 2
PdfWriter.getInstance(document, new FileOutputStream(filename));
// step 3
document.open();
// step 4
document.add(new Paragraph("PDF Title"));
// step 5
document.add(new Image("Tiff image path..."));
// step 6
document.close();
}
希望能帮助到你!
使用 imagick 库,以下解决方案对我有用 -
$document = new Imagick($path."/".$fileName.tiff);
$data = $document->getImageBlob();
$document->setImageFormat("pdf");
$document->writeImages($path."/".$fileName.pdf, true);