function _example(&$example) { global $pres; // Bring posted variables into the function-local namespace // so examples will work foreach ($_POST as $_html_key => $_html_val) { ${$_html_key} = $_html_val; } foreach ($_SERVER as $_html_key => $_html_val) { ${$_html_key} = $_html_val; } if (!empty($example->title)) { $this->pdf_cy = pdf_get_value($this->pdf, "texty", null); pdf_set_text_pos($this->pdf, $this->pdf_cx, $this->pdf_cy); // Force to left-margin pdf_set_font($this->pdf, $this->pdf_font, -16, 'winansi'); pdf_continue_text($this->pdf, strip_markups($example->title)); pdf_continue_text($this->pdf, ""); } $this->pdf_cy = pdf_get_value($this->pdf, "texty", null); if (!$example->hide) { if (!empty($example->filename)) { $_html_filename = preg_replace('/\\?.*$/', '', $this->slideDir . $example->filename); $_html_file = @file_get_contents($_html_filename); } else { $_html_file = $example->text; } switch ($example->type) { case 'php': case 'genimage': case 'iframe': case 'link': case 'embed': case 'flash': case 'system': case 'shell': case 'c': case 'perl': case 'java': case 'python': case 'sql': case 'html': default: if ($_html_file[strlen($_html_file) - 1] != "\n") { $_html_file .= "\n"; } $this->my_pdf_paginated_code($this->pdf, $_html_file, $this->pdf_x, $this->pdf_y, $this->pdf_cy + 10, 60, $this->pdf_cx + 30, $this->pdf_cx, $this->pdf_example_font, -10); pdf_continue_text($this->pdf, ""); break; } } $this->pdf_cy = pdf_get_value($this->pdf, "texty", null); if ($example->result && $example->type != 'iframe' && (empty($example->condition) || isset(${$example->condition})) && (empty($example->required_extension) || extension_loaded($example->required_extension))) { if (!$example->hide) { $this->pdf_cy = pdf_get_value($this->pdf, "texty", null); pdf_set_text_pos($this->pdf, $this->pdf_cx + 20, $this->pdf_cy); // Force to left-margin pdf_set_font($this->pdf, $this->pdf_font, -14, 'winansi'); pdf_continue_text($this->pdf, "Output:"); pdf_continue_text($this->pdf, ""); } $this->pdf_cy = pdf_get_value($this->pdf, "texty", null); if (!empty($example->global) && !isset($GLOBALS[$example->global])) { global ${$example->global}; } if (!empty($example->filename)) { $_html_filename = preg_replace('/\\?.*$/', '', $this->slideDir . $example->filename); switch ($example->type) { case 'genimage': $fn = tempnam("/tmp", "pres2"); $img = file_get_contents("http://" . $_SERVER['HTTP_HOST'] . "/" . $this->baseDir . $this->slideDir . $example->filename, "r"); $fp_out = fopen($fn, "wb"); fwrite($fp_out, $img); fclose($fp_out); list($dx, $dy, $type) = getimagesize($fn); $dx = $this->pdf_x * $dx / 1024; $dy = $this->pdf_x * $dy / 1024; switch ($type) { case 1: $im = pdf_open_gif($this->pdf, $fn); break; case 2: $im = pdf_open_jpeg($this->pdf, $fn); break; case 3: $im = pdf_open_png($this->pdf, $fn); break; case 7: $im = pdf_open_tiff($this->pdf, $fn); break; } if (isset($im)) { $this->pdf_cy = pdf_get_value($this->pdf, "texty", null); if ($this->pdf_cy + $dy > $this->pdf_y - 60) { $this->my_pdf_page_number($this->pdf, $this->pdf_x, $this->pdf_y); $this->my_new_pdf_end_page($this->pdf); $this->my_new_pdf_page($this->pdf, $this->pdf_x, $this->pdf_y, true); $this->pdf_cx = 40; $this->pdf_cy = 60; } pdf_save($this->pdf); pdf_translate($this->pdf, 0, $this->pdf_y); $scale = $this->pdf_x / 1024; pdf_scale($this->pdf, 1 * $scale, -1 * $scale); pdf_place_image($this->pdf, $im, $this->pdf_cx, $this->pdf_y - $this->pdf_cy - $dy, $scale); pdf_restore($this->pdf); pdf_set_text_pos($this->pdf, $this->pdf_cx, $this->pdf_cy + $dy); } unlink($fn); break; case 'iframe': case 'link': case 'embed': // don't think we can do these in pdf break; case 'flash': // Definitely can't do this one break; case 'system': // system("DISPLAY=localhost:0 $this->slideDir$example->filename"); break; default: // Need something to turn html into pdf here? // Perhaps just output buffering and stripslashes // include $_html_filename; // -- copying code from below as a temp solution -- ob_start(); eval('?>' . file_get_contents($_html_filename)); $data = strip_tags(ob_get_contents()); ob_end_clean(); if (strlen($data) && $data[strlen($data) - 1] != "\n") { $data .= "\n"; } $this->my_pdf_paginated_code($this->pdf, $data, $this->pdf_x, $this->pdf_y, $this->pdf_cy, 60, $this->pdf_cx + 30, $this->pdf_cx, $this->pdf_example_font, -10); pdf_continue_text($this->pdf, ""); break; } } else { switch ($example->type) { default: ob_start(); eval('?>' . $example->text); $data = strip_tags(ob_get_contents()); ob_end_clean(); if (strlen($data) && $data[strlen($data) - 1] != "\n") { $data .= "\n"; } $this->my_pdf_paginated_code($this->pdf, $data, $this->pdf_x, $this->pdf_y, $this->pdf_cy, 60, $this->pdf_cx + 30, $this->pdf_cx, $this->pdf_example_font, -10); pdf_continue_text($this->pdf, ""); break; } } } }
<?php $p = PDF_new(); PDF_open_file($p); PDF_begin_page($p, 595, 842); $im = pdf_open_jpeg($p, "php-big.jpg"); pdf_place_image($p, $im, 200, 700, 1.0); PDF_save($p); // Save current coordinate system settings $nx = 50 / PDF_get_value($p, "imagewidth", $im); $ny = 100 / PDF_get_value($p, "imageheight", $im); PDF_scale($p, $nx, $ny); pdf_place_image($p, $im, 200 / $nx, 600 / $ny, 1.0); PDF_restore($p); // Restore previous pdf_close_image($p, $im); PDF_end_page($p); PDF_close($p); $buf = PDF_get_buffer($p); $len = strlen($buf); Header("Content-type:application/pdf"); Header("Content-Length:{$len}"); Header("Content-Disposition:inline; filename=coords.pdf"); echo $buf; PDF_delete($p);
} $pdf = pdf_new(); pdf_open_file($pdf); pdf_set_info($pdf, "Author", "Jesús M. Castagnetto"); pdf_set_info($pdf, "Title", "Ejemplo de Factura"); pdf_set_info($pdf, "Creator", "Jesús M. Castagnetto"); pdf_set_info($pdf, "Subject", "Ejemplo de Factura"); $sizes = array('a4' => '595x842', 'letter' => '612x792', 'legal' => '612x1008'); if (!isset($type)) { $type = 'a4'; } list($x, $y) = explode('x', $sizes[$type]); $items = array(array('Un programa simple que hace de todo', '299.99'), array('El programa especial sin el que el anterior no corre', '1899'), array('Una libreria de comunicacion', '29.95'), array('Un programa para bloquear la comunicacion', '49.95'), array('Una libreria que comprime todo a 1 byte', '49.9'), array('Y un programa que permite recuperar lo comprimido a 1 byte', '39999.95')); pdf_begin_page($pdf, $x, $y); $imagepath = realpath('../images/booger.jpg'); $im = pdf_open_jpeg($pdf, $imagepath); pdf_place_image($pdf, $im, 5, $y - 72, 0.5); pdf_close_image($pdf, $im); pdf_set_value($pdf, 'textrendering', 0); // fill pdf_set_font($pdf, "Helvetica", 12, winansi); pdf_show_xy($pdf, 'Micro Snot & L4m3r5 S.R.L.', 145, $y - 20); pdf_continue_text($pdf, '123 Calle del Dolor'); pdf_continue_text($pdf, 'Tacora, Lima 666'); pdf_set_font($pdf, "Helvetica", 10, winansi); pdf_show_xy($pdf, 'Cliente Sin Salvacion S.A.', 20, $y - 100); pdf_continue_text($pdf, '1 Calle Pequena'); pdf_continue_text($pdf, 'Cuidad Perdida, Puno 123'); pdf_set_font($pdf, "Helvetica", 10, winansi); pdf_show_xy($pdf, 'Terminos: Pago Completo 15 horas', 150, $y - 100); pdf_continue_text($pdf, 'Apt. Postal: 12345');