Search code examples
phppdfimagemagicktiff

ImageMagick: Tiff to PDF from PHP


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


Solution

  • 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!