note 73864 added to function.pdf-open-image-file

From: Date: Tue, 13 Mar 2007 13:07:56 +0000
Subject: note 73864 added to function.pdf-open-image-file
Groups: php.notes 
Request: Send a blank email to php-notes+get-124410@lists.php.net to get a copy of this message
This short script will create a scaled PDF from a multi-page tiff file (tested and implemented in PHP 5): <?php // Declare pdf File $pdf = pdf_new(); pdf_open_file($pdf, "test.pdf"); // Convert and add pages until you reach end of the tiff for($page = 1; $image = @pdf_open_image_file($pdf, "tiff", "test.tif", "page", $page); $page++) { // Set page scale to 72 dpi using the width of the image (72 * 8.5 inches = 612 dpi) $scale = 612 / pdf_get_value($pdf, "imagewidth", $image); // Create a new page using the scaled height and width of the image pdf_begin_page($pdf, $scale * pdf_get_value($pdf, "imagewidth", $image), $scale * pdf_get_value($pdf, "imageheight", $image)); // Place the scaled image in the top left corner of the page and end this page of the pdf pdf_place_image($pdf, $image, 0, 0, $scale); pdf_end_page($pdf); } // Finish the pdf File pdf_close($pdf); ?> Please note that this script disregards whether the height of the image is unable to scale comparably to an 8.5x11 inch document. Depending on the images you are working with, you may want to add some logic to set your scale value based on the true height and width of the image. ---- Server IP: 64.71.164.2 Probable Submitter: 68.156.145.3 ---- Manual Page -- http://www.php.net/manual/en/function.pdf-open-image-file.php Edit -- https://master.php.net/note/edit/73864 Del: integrated -- https://master.php.net/note/delete/73864/integrated Del: useless -- https://master.php.net/note/delete/73864/useless Del: bad code -- https://master.php.net/note/delete/73864/bad+code Del: spam -- https://master.php.net/note/delete/73864/spam Del: non-english -- https://master.php.net/note/delete/73864/non-english Del: in docs -- https://master.php.net/note/delete/73864/in+docs Del: other reasons-- https://master.php.net/note/delete/73864 Reject -- https://master.php.net/note/reject/73864 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#124410) next »