|
PDF_load_image
Open image file
()
Examples ( Source code ) » PDF_load_image
Code Examples / Notes » pdf_load_imagemike zmuda
This program takes a picture from a dynamic image selector (ie: banner ad selector software, or whatever,) and inserts it into your pdf. You can use something like this to insert coupons on PDFs (such as register receipts, bills, receipts, etc...) just like they do at the supermarket checkout! <?php //Set up a document (PHP5 standard.) $p = new PDFlib(); if ($p->begin_document("", "") == 0) { die("Error: " . $p->get_errmsg()); } $p->set_info("Creator", "Homer"); $p->set_info("Author", "Lisa"); $p->set_info("Title", "Simpsons Image"); $p->begin_page_ext(612, 792, ""); // This is letter. //Open the url for the image server we wish to use. // (When I say "Image Server," I mean any program or // script which will render image data as output. That // means that it has to output the raw data, unmodified, // such that it could be accessed like this in a standard // html instruction call: // // <img src="http://site.com/getimg.php?pic=18"> // // If it adds border or other text, the data will be // corrupted, and thus cause the pdf to misrender. if ($stream = fopen('http://site.com/getimg.php?pic=18', 'r')) { $MyImage= stream_get_contents($stream, -1); fclose($stream); } //First, create a PDF Virtual File (PVF) out of our data... $pvf_filename = "/pvf/image/image1.jpg"; //and store the $MyImage data (picture data from above) // in it! $p->create_pvf($pvf_filename,$MyImage, ""); //Load the image from the PVF into, er, uh, ram..., and, uh... $image = $p->load_image("jpeg", $pvf_filename,""); //Put it on the screen! :) $p->fit_image($image, 100,500,"boxsize {100 100} position 50 fitmethod meet"); //Be cool and clean up after yourself... $p->delete_pvf($pvf_filename); //And... Render! $p->end_page_ext(""); $p->end_document(""); $buf = $p->get_buffer(); $len = strlen($buf); header("Content-type: application/pdf"); header("Content-Length: $len"); header("Content-Disposition: inline; filename=urlImageTest.pdf"); print $buf; ?> klassen dot tony
I've had a difficult time trying to load images to the pdf with pdflib, and tried many examples. I came across this one and it actually works for me in IE and Firefox. I hope this can be of some help to someone. <?php $searchpath = "path/to/image/dir"; $p = new PDFlib(); $p->set_parameter("errorpolicy", "return"); // check return values of load_font() etc. $p->set_parameter("hypertextencoding", "winansi"); // used to prevent problems with japanese systems $p->set_parameter("SearchPath", $searchpath); // **set search path parameter in pdf if ($p->begin_document("", "") == 0) { die("Error: " . $p->get_errmsg()); } $p->set_info("Creator", " the creator"); $p->set_info("Author", " you "); $p->set_info("Title", " imageInsert "); $p->begin_page_ext(612, 792, ""); // declare page with standard letter size $certLogo = "stamp.jpg"; // your image name $image = $p->load_image("auto", $certLogo, ""); if (!$image) { die("Error: " . $p->get_errmsg()); } $p->fit_image($image, 390,575, ""); //place image within page coordinates $p->close_image($image); // close resource $p->end_page_ext(""); $p->end_document(""); $data = $p->get_buffer(); $len = strlen($data); header("Content-type: application/pdf"); header("Content-Length: $len"); header("Content-Disposition: inline; filename=hello.pdf"); print $data; $p = 0; ?> nicolas padfield nicolasatpadfielddotdk
Example use of PDF_load_image(): <?php $pdf = PDF_new(); PDF_open_file($pdf,''); PDF_begin_page($pdf,595,842); $image = PDF_load_image($pdf,"png","myimage.png",""); PDF_place_image($pdf,$image,64,26,.24); ?> If you want something that is more free for commercial use, open source and does not require compiling, you could look at for example http://www.fpdf.org in stead of PDFlib |
Change LanguagePDF_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 |