views:

339

answers:

2

How can I convert 2 tiff images to PDF, I already knows how to get the image out of the DB, and I print it using echo and setting up the MIME type.

But, right know I need to use a duplex printer option, so I need a way to generate a PDF from inside my PHP page, that PDF must containt both TIFF images (one per page) How can I do that? What do I need for php to work with that library.

Thank you very much.

EDIT:

Is a self hosted app, I own the server (actually I'm using WAMP 2).

I extract the images from the MySQL DB (stored using LONGBLOBS).

A: 

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

  • ImageMagick installed
  • Ghostscript installed

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.

Pekka
+1  A: 

What you really need is a library that brings you a PDF composition engine. And of course you need that engine to support image insertions (specifically TIFF).

The best option is 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();
}

Hope it helps!

Randolf R-F