Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : PDF Functions : PDF_open_image_file

PDF_open_image_file

Read image from file [deprecated] ()
int PDF_open_image_file ( resource p, string imagetype, string filename, string stringparam, int intparam )

Examples ( Source code ) » PDF_open_image_file

<?php
//Create & Open PDF-Object
$pdf pdf_new();
pdf_open_file($pdf);
pdf_set_info($pdf"Author","Bob Nijman");
pdf_set_info($pdf"Title","www.nijman.de");
pdf_set_info($pdf"Creator""bob@nijman.de");
pdf_set_info($pdf"Subject""pdf_open_image_file");
pdf_begin_page($pdf200200);
$pdfimage pdf_open_image_file($pdf"jpeg""test.jpg");
pdf_place_image($pdf$pdfimage10100.6);
//close it up
pdf_end_page($pdf);
pdf_close($pdf);
$data pdf_get_buffer($pdf);
header('Content-type: application/pdf');
header('Content-disposition: inline; filename=image.pdf');
header('Content-length: ' strlen($data));
echo 
$data;
?> 

Related Examples ( Source code ) » pdf_open_image_file


Code Examples / Notes » pdf_open_image_file

darren

when using pdf_open_image_file() with multipage tiffs, the example in the manual won't work (i don't think the function returns -1 like it says)
you can use this instead;
  for ($page=1; ; $page++)
   {
     // our image
$image=pdf_open_image_file($pdf,"tiff",$file,"page",$page);
     // a bad image - page cannot be 0
$bad=pdf_open_image_file($pdf,"tiff",$file,"page",0);
if ($image == $bad)
{
 // done adding pages
 break;
}
     pdf_begin_page($pdf,$width,$height);
     pdf_place_image($pdf,$image,0,0,1);
     pdf_close_image($pdf,$image);
     pdf_end_page($pdf);
   }


ws

when using pdf_open_image_file() with multipage tiffs in php 5.x.x I had to use the following
$pdf = pdf_new();
pdf_open_file($pdf, "test.pdf");
$file = "mutlipg.tif";
// Important to switch off the exceptions
pdf_set_parameter($pdf, "imagewarning", "false");
for($i=1; ; $i++)
{
   $image=@pdf_open_image_file($pdf, "tiff", $file, "page", $i);
   if($image != 0)
   {
       $w = pdf_get_value($pdf, "imagewidth", $image);
       $h = pdf_get_value($pdf, "imageheight", $image);
// use only half of the size
       pdf_begin_page($pdf, $w/2, $h/2);
       pdf_place_image($pdf, $image, 0, 0, 0.5);
       pdf_close_image($pdf, $image);
       pdf_end_page($pdf);
   }
   else
       break;
}
// Send the pdf to the Browser
pdf_close($pdf);
$fp = fopen("test.pdf", "r");
header("Content-type: application/pdf");
fpassthru($fp);
fclose($fp);


bob

Try this.
(don't forget to put a "test.jpg" in the same dir)
<?php
//Create & Open PDF-Object
$pdf = pdf_new();
pdf_open_file($pdf);
pdf_set_info($pdf, "Author","Bob Nijman");
pdf_set_info($pdf, "Title","www.nijman.de");
pdf_set_info($pdf, "Creator", "bob@nijman.de");
pdf_set_info($pdf, "Subject", "pdf_open_image_file");
pdf_begin_page($pdf, 200, 200);
$pdfimage = pdf_open_image_file($pdf, "jpeg", "test.jpg");
pdf_place_image($pdf, $pdfimage, 10, 10, 0.6);
//close it up
pdf_end_page($pdf);
pdf_close($pdf);
$data = pdf_get_buffer($pdf);
header('Content-type: application/pdf');
header('Content-disposition: inline; filename=image.pdf');
header('Content-length: ' . strlen($data));
echo $data;
?>


john middleton

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.


j tse

If the image file is sitting at somewhere (outside the subdirectory), an absolute path must be given instead.

max / poland

another example : PHP 5 & PDFLIB 6.0.2  
<?
$pdf = pdf_new();
if (pdf_begin_document($pdf,"", "") == 0)
{die("Error: " . pdf_get_errmsg());}
  pdf_set_parameter($pdf, "SearchPath", "./");
  pdf_set_parameter($pdf, "hypertextencoding", "winansi");
  pdf_set_parameter($pdf, "imagewarning", "false");
  pdf_set_info($pdf, "Creator", "some INformations");
  pdf_set_info($pdf, "Author", "author");
  pdf_set_info($pdf, "Title", "Raport");
$logo = pdf_open_image_file($pdf, "jpeg", "foto.jpg", "", 0);
pdf_begin_page($pdf, 595, 842);
pdf_place_image($pdf, $logo, 28, 324, 0.125);
pdf_close_image($pdf, $logo);
pdf_end_page($pdf);
pdf_close($pdf);
 $buf = pdf_get_buffer($pdf);
 $len = strlen($buf);
 header("Content-type: application/pdf");
 header("Content-Length: $len");
 header("Content-Disposition: attachment; filename=raport.pdf");
 echo $buf;
?>


alfred dot zingg

...
$logo = pdf_open_image_file($pdf, "jpeg", "logo.jpg");
pdf_place_image($pdf, $logo, 28, 324, 0.125);
pdf_close_im($pdf, $logo);
...
does not work under PHP5, use
...
$logo = pdf_open_image_file($pdf, "jpeg", "logo.jpg", "", 0);
pdf_place_image($pdf, $logo, 28, 324, 0.125);
pdf_close_im($pdf, $logo);
...


Change Language


Follow Navioo On Twitter
PDF_activate_item
PDF_add_annotation
PDF_add_bookmark
PDF_add_launchlink
PDF_add_locallink
PDF_add_nameddest
PDF_add_note
PDF_add_outline
PDF_add_pdflink
PDF_add_table_cell
PDF_add_textflow
PDF_add_thumbnail
PDF_add_weblink
PDF_arc
PDF_arcn
PDF_attach_file
PDF_begin_document
PDF_begin_font
PDF_begin_glyph
PDF_begin_item
PDF_begin_layer
PDF_begin_page_ext
PDF_begin_page
PDF_begin_pattern
PDF_begin_template_ext
PDF_begin_template
PDF_circle
PDF_clip
PDF_close_image
PDF_close_pdi_page
PDF_close_pdi
PDF_close
PDF_closepath_fill_stroke
PDF_closepath_stroke
PDF_closepath
PDF_concat
PDF_continue_text
PDF_create_3dview
PDF_create_action
PDF_create_annotation
PDF_create_bookmark
PDF_create_field
PDF_create_fieldgroup
PDF_create_gstate
PDF_create_pvf
PDF_create_textflow
PDF_curveto
PDF_define_layer
PDF_delete_pvf
PDF_delete_table
PDF_delete_textflow
PDF_delete
PDF_encoding_set_char
PDF_end_document
PDF_end_font
PDF_end_glyph
PDF_end_item
PDF_end_layer
PDF_end_page_ext
PDF_end_page
PDF_end_pattern
PDF_end_template
PDF_endpath
PDF_fill_imageblock
PDF_fill_pdfblock
PDF_fill_stroke
PDF_fill_textblock
PDF_fill
PDF_findfont
PDF_fit_image
PDF_fit_pdi_page
PDF_fit_table
PDF_fit_textflow
PDF_fit_textline
PDF_get_apiname
PDF_get_buffer
PDF_get_errmsg
PDF_get_errnum
PDF_get_font
PDF_get_fontname
PDF_get_fontsize
PDF_get_image_height
PDF_get_image_width
PDF_get_majorversion
PDF_get_minorversion
PDF_get_parameter
PDF_get_pdi_parameter
PDF_get_pdi_value
PDF_get_value
PDF_info_font
PDF_info_matchbox
PDF_info_table
PDF_info_textflow
PDF_info_textline
PDF_initgraphics
PDF_lineto
PDF_load_3ddata
PDF_load_font
PDF_load_iccprofile
PDF_load_image
PDF_makespotcolor
PDF_moveto
PDF_new
PDF_open_ccitt
PDF_open_file
PDF_open_gif
PDF_open_image_file
PDF_open_image
PDF_open_jpeg
PDF_open_memory_image
PDF_open_pdi_page
PDF_open_pdi
PDF_open_tiff
PDF_pcos_get_number
PDF_pcos_get_stream
PDF_pcos_get_string
PDF_place_image
PDF_place_pdi_page
PDF_process_pdi
PDF_rect
PDF_restore
PDF_resume_page
PDF_rotate
PDF_save
PDF_scale
PDF_set_border_color
PDF_set_border_dash
PDF_set_border_style
PDF_set_char_spacing
PDF_set_duration
PDF_set_gstate
PDF_set_horiz_scaling
PDF_set_info_author
PDF_set_info_creator
PDF_set_info_keywords
PDF_set_info_subject
PDF_set_info_title
PDF_set_info
PDF_set_layer_dependency
PDF_set_leading
PDF_set_parameter
PDF_set_text_matrix
PDF_set_text_pos
PDF_set_text_rendering
PDF_set_text_rise
PDF_set_value
PDF_set_word_spacing
PDF_setcolor
PDF_setdash
PDF_setdashpattern
PDF_setflat
PDF_setfont
PDF_setgray_fill
PDF_setgray_stroke
PDF_setgray
PDF_setlinecap
PDF_setlinejoin
PDF_setlinewidth
PDF_setmatrix
PDF_setmiterlimit
PDF_setpolydash
PDF_setrgbcolor_fill
PDF_setrgbcolor_stroke
PDF_setrgbcolor
PDF_shading_pattern
PDF_shading
PDF_shfill
PDF_show_boxed
PDF_show_xy
PDF_show
PDF_skew
PDF_stringwidth
PDF_stroke
PDF_suspend_page
PDF_translate
PDF_utf16_to_utf8
PDF_utf32_to_utf16
PDF_utf8_to_utf16
eXTReMe Tracker