views:

265

answers:

3

Hi, i'm just feeling that my head will explode unless someone help me with this problem:

I have stored a pair of TIFF images (related by a common key) for each one of almos 100.000 registries. And I create a PHP script that receives a key and echo the tiff image, so the browser return the tiff image:

<?php
    // Determine the primary key to relate with the image table
    $numero_registro = $_GET['numero_registro'];

    $imagen = $_GET['imagen'];

    if ($numero_registro != "")
    {
        $con = mysql_connect("localhost","XXXXX","XXXXXX");
        if (!$con)
          {
          die('Problems with db: ' . mysql_error());
          }

        mysql_select_db("XXXXX", $con);

        $result = mysql_query("SELECT img FROM image_table i WHERE i.fk_civil_registry_code = $numero_registro");

        $i = 1;
        while($row = mysql_fetch_array($result) )
        {
            if ( $imagen == $i ) 
            {
                #img is a long blob field
                $ext="tiff";
                header("Content-type: image/{$ext}");
                echo $row['img'];
            }
            $i++;
        }

        mysql_close($con);
    }

?>

This just works and the tiff image is displayed by the browser. But, this is a tiff image, so is displayed lonely (and viewed using alternaTiff). Until know this was no problem, cause I just needed to print a single image. But now my boss buy a big automatic duplex printer, and put it on his office, so I need a way to generate a pdf (of two pages) and put both images (echo $row['img'];) each one on a single page, so they can print the PDF.

Can anyone help me to do that?

Thank you very much.

+1  A: 

So you want to generate a 2-page PDF which consists of a tiff image on each page?

Perhaps the following links will be of interest:

http://www.fpdf.org/

http://kevin.vanzonneveld.net/techblog/article/php_tiff2pdf/

Then you can just flush the PDF to the browser.

Sbm007
A: 

Instead of a pdf document you could also use an html document with page-break-before css properties. e.g. try

<html>
  <head><title>...</title></head>
  <body>
    <div><img src="http://sstatic.net/so/img/logo.png" /></div>
    <div style="page-break-before:always;"><img src="http://sstatic.net/so/img/logo.png" /></div>
  </body>
</html>

and then go to the print preview in your browser.

VolkerK
That sounds great.But the problem is that Tiff gets displayed on all the browser (not the web page). Do you know maybe hoy to display two tiffs at the same place.
Sheldon
Note sure what you're asking for, but do you mean something like `<img src="script.php?id=1234" /> .... <img src="script.php?id=1235" />`?
VolkerK
That works with JPEG and PNG but not with TIFF cause browser doesn't know how to handle it. It just ask for download when fount the first one. And with a plugin like AlternaTIFF, the plugin load the first also.
Sheldon
dang, you're right ...haven't thought of that :(
VolkerK
+1  A: 

Are you stuck with PHP? If you can work with ASP.NET, my company has a set of tools that will display and print TIFF images from AJAX controls as well as code that will generate self-printing PDF files. If you did the latter, you could keep your web work in PHP and hook up to a .NET service that takes N tiff files and generates a single printable PDF.

To give you a sense of what that would look like, the C# code to take two tiff images and convert to PDF would be:

FileSystemImageSource images = new FileSystemImageSource(pathToTiff1, pathToTiff2);
PdfEncoder encoder = new PdfEncoder();
encoder.CreateSelfPrintingPdf = true;
encoder.Save(outputStream, images, null);
plinth
I'll give it a try, thank you very much.
Sheldon