<?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);
function image_rx_ry($image, $x, $y, $width, $height, $right, $bottom, $ox, $oy, $scale) { $tmpname = tempnam(WRITER_TEMPDIR, WRITER_FILE_PREFIX); imagepng($image->get_handle(), $tmpname); $pim = pdf_open_image_file($this->pdf, "png", $tmpname, "", 0); // Fill bottom-right quadrant $cy = $y; while ($cy + $height > $bottom) { $cx = $x; while ($cx < $right) { pdf_place_image($this->pdf, $pim, $cx, $cy, $scale); $cx += $width; } $cy -= $height; } // Fill bottom-left quadrant $cy = $y; while ($cy + $height > $bottom) { $cx = $x; while ($cx + $width > $x - $ox) { pdf_place_image($this->pdf, $pim, $cx, $cy, $scale); $cx -= $width; } $cy -= $height; } // Fill top-right quadrant $cy = $y; while ($cy < $y + $oy) { $cx = $x; while ($cx < $right) { pdf_place_image($this->pdf, $pim, $cx, $cy, $scale); $cx += $width; } $cy += $height; } // Fill top-left quadrant $cy = $y; while ($cy < $y + $oy) { $cx = $x; while ($cx + $width > $x - $ox) { pdf_place_image($this->pdf, $pim, $cx, $cy, $scale); $cx -= $width; } $cy += $height; } pdf_close_image($this->pdf, $pim); unlink($tmpname); }
public function createPDF($fname) { $pdf = pdf_new(); pdf_open_file($pdf, ''); $image = pdf_load_image($pdf, "png", $fname, ""); $w = pdf_get_value($pdf, "imagewidth", $image); $h = pdf_get_value($pdf, "imageheight", $image); pdf_begin_page($pdf, $w * 2, $h * 2); pdf_place_image($pdf, $image, $w / 2, $h / 2, 1); pdf_end_page($pdf); pdf_close($pdf); $mybuf = PDF_get_buffer($pdf); $mylen = strlen($mybuf); header("Content-type: application/pdf"); header("Content-Length: {$mylen}"); header("Content-Disposition: inline; filename=chart.pdf"); print $mybuf; PDF_delete($pdf); unlink($fname); }
<?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_place_image($p, $im, 200, 600, 0.75); pdf_place_image($p, $im, 200, 535, 0.5); pdf_place_image($p, $im, 200, 501, 0.25); pdf_place_image($p, $im, 200, 486, 0.1); $x = pdf_get_value($p, "imagewidth", $im); $y = pdf_get_value($p, "imageheight", $im); pdf_close_image($p, $im); $font = PDF_findfont($p, "Times-Bold", "host", 0); PDF_setfont($p, $font, 28.0); pdf_show_xy($p, "{$x} by {$y}", 25, 800); 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);
/** * Overlay image * * Parameter array: * 'x': int X-point of overlayed image * 'y': int Y-point of overlayed image * 'filename': string The filename of the image to overlay * 'width': int [optional] The width of the overlayed image (resizing if possible) * 'height': int [optional] The height of the overlayed image (resizing if possible) * 'alignment': array [optional] Alignment */ function image($params) { $x = $this->_getX($params['x']); $y = $this->_getY($params['y']); $filename = $params['filename']; $width = isset($params['width']) ? $params['width'] : false; $height = isset($params['height']) ? $params['height'] : false; $alignment = isset($params['alignment']) ? $params['alignment'] : false; if (substr($filename, -4) == '.png') { $type = 'png'; } elseif (substr($filename, -4) == '.jpg') { $type = 'jpeg'; } $image = pdf_load_image($this->_pdf, $type, realpath($filename), ''); $width_ = pdf_get_value($this->_pdf, 'imagewidth', $image); $height_ = pdf_get_value($this->_pdf, 'imageheight', $image); $outputWidth = $width !== false ? $width : $width_; $outputHeight = $height !== false ? $height : $height_; if (!is_array($alignment)) { $alignment = array('vertical' => 'top', 'horizontal' => 'left'); } if (!isset($alignment['vertical'])) { $alignment['vertical'] = 'top'; } if (!isset($alignment['horizontal'])) { $alignment['horizontal'] = 'left'; } if ($alignment['horizontal'] == 'right') { $x -= $outputWidth; } elseif ($alignment['horizontal'] == 'center') { $x -= $outputWidth / 2; } if ($alignment['vertical'] == 'top') { $y += $outputHeight; } elseif ($alignment['vertical'] == 'center') { $y += $outputHeight / 2; } if ($width === false && $height === false) { $scale = 1; } else { $scale = max($height / $height_, $width / $width_); } pdf_place_image($this->_pdf, $image, $this->_getX($x), $this->_getY($y), $scale); pdf_close_image($this->_pdf, $image); parent::image($params); }
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; } } } }
$p = PDF_new(); PDF_open_file($p); $im = pdf_open_jpeg($p, "php-big.jpg"); $template = pdf_begin_template($p, 595, 842); pdf_save($p); pdf_place_image($p, $im, 4, 803, 0.25); pdf_place_image($p, $im, 525, 803, 0.25); pdf_moveto($p, 0, 795); pdf_lineto($p, 595, 795); pdf_stroke($p); $font = PDF_findfont($p, "Times-Bold", "host", 0); PDF_setfont($p, $font, 38.0); pdf_show_xy($p, "PDF Template Example", 100, 807); pdf_restore($p); pdf_end_template($p); pdf_close_image($p, $im); PDF_begin_page($p, 595, 842); pdf_place_image($p, $template, 0, 0, 1.0); PDF_end_page($p); PDF_begin_page($p, 595, 842); pdf_place_image($p, $template, 0, 0, 1.0); 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=gra2.pdf"); echo $buf; PDF_delete($p);
<?php $p = PDF_new(); PDF_open_file($p); $im = pdf_open_png($p, "fr-flag.png"); $pattern = pdf_begin_pattern($p, 21, 14, 25, 18, 1); pdf_save($p); pdf_place_image($p, $im, 0, 0, 1); pdf_restore($p); pdf_end_pattern($p); pdf_close_image($p, $im); PDF_begin_page($p, 595, 842); PDF_setcolor($p, "fill", "pattern", $pattern); PDF_setcolor($p, "stroke", "pattern", $pattern); pdf_setlinewidth($p, 30.0); PDF_circle($p, 200, 680, 120); PDF_stroke($p); 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=gra2.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'); pdf_set_font($pdf, "Helvetica-Bold", 30, winansi);
if ($node->getMainArt() != false) { $extension = substr(strrchr($node->getMainArt(), '.'), 1); $extension = strtolower($extension); if ($extension == 'jpg') { $pdfdfimage = pdf_open_image_file($pdf, 'jpeg', $node->getMainArt(), '', 0); } if ($extension == 'png') { $pdfdfimage = pdf_open_image_file($pdf, 'png', $node->getMainArt(), '', 0); } if ($extension == 'gif') { $pdfdfimage = pdf_open_image_file($pdf, 'gif', $node->getMainArt(), '', 0); } $sx = 121 / pdf_get_value($pdf, 'imagewidth', $pdfdfimage); $sy = 120 / pdf_get_value($pdf, 'imageheight', $pdfdfimage); pdf_scale($pdf, $sx, $sy); pdf_place_image($pdf, $pdfdfimage, 0, 0, 1); } // +---------------------------------------------------------------------------+ // | Close PDF | // +---------------------------------------------------------------------------+ pdf_end_page($pdf); pdf_close($pdf); $buffer = pdf_get_buffer($pdf); $file = $artist . ' - ' . $album . '.pdf'; header('Content-Type: application/force-download'); header('Content-Transfer-Encoding: binary'); header('Content-Disposition: attachment; filename="' . $file . '"'); //rawurlencode not needed for header echo $buffer; pdf_delete($pdf); exit;
$i_left = 50; $i_offset = 200; $str_pdf_name = "invoice.pdf"; $pdf = pdf_new(); pdf_open_file($pdf, "{$str_current_path}/Temp_doc/{$str_pdf_name}"); pdf_set_info($pdf, "Author", "etelegate"); pdf_set_info($pdf, "Title", "Invoice Form"); pdf_set_info($pdf, "Creator", "etelegate"); pdf_set_info($pdf, "Subject", "Invoice"); pdf_begin_page($pdf, 595, 842); //pdf_add_outline($pdf, "Page 5"); $font = pdf_findfont($pdf, "Verdana", "winansi", 1); pdf_setfont($pdf, $font, 12); //pdf_set_value($pdf, "textrendering", 1); $jpeg_image = pdf_open_image_file($pdf, "jpeg", "images/logo2os.jpg"); pdf_place_image($pdf, $jpeg_image, 200, $i_top, 1.0); pdf_close_image($pdf, $jpeg_image); /*$jpeg_image = pdf_open_image_file($pdf, "jpeg", "images/top1.jpg"); pdf_place_image($pdf, $jpeg_image, 300, $i_top+20, 0.5); pdf_close_image($pdf, $jpeg_image); $jpeg_image = pdf_open_image_file($pdf, "jpeg", "images/top4.jpg"); pdf_place_image($pdf, $jpeg_image, 301, $i_top-10, 0.5); pdf_close_image($pdf, $jpeg_image);*/ $i_top -= 50; pdf_show_xy($pdf, "Company Name", $i_left, $i_top); pdf_show_xy($pdf, "[Company Name]", $i_left + $i_offset, $i_top); $i_top -= 30; pdf_show_xy($pdf, "Address", $i_left, $i_top); pdf_show_xy($pdf, "[Address]", $i_left + $i_offset, $i_top); /*if ($str_city != "") { $i_top -= 20;
pdf_show_xy($pdf, 'This is to certify that:', $startx, 430); pdf_show_xy($pdf, strtoupper($name), $startx + 90, 391); $font = pdf_findfont($pdf, $fontname, 'host', 0); if ($font) { pdf_setfont($pdf, $font, 20); } pdf_show_xy($pdf, 'has demonstrated that they are certifiable ' . 'by passing a rigorous exam', $startx, 340); pdf_show_xy($pdf, 'consisting of three multiple choice questions.', $startx, 310); pdf_show_xy($pdf, "{$name} obtained a score of {$score}" . '%.', $startx, 260); pdf_show_xy($pdf, 'The test was set and overseen by the ', $startx, 210); pdf_show_xy($pdf, 'Fictional Institute of PHP Certification', $startx, 180); pdf_show_xy($pdf, "on {$date}.", $startx, 150); pdf_show_xy($pdf, 'Authorised by:', $startx, 100); // add bitmap signature image $signature = pdf_open_image_file($pdf, 'png', 'signature.png'); pdf_place_image($pdf, $signature, 200, 75, 1); pdf_close_image($pdf, $signature); // set up colors for rosette pdf_setrgbcolor_fill($pdf, 0, 0, 0.4); //dark blue pdf_setrgbcolor_stroke($pdf, 0, 0, 0); // black // draw ribbon 1 pdf_moveto($pdf, 630, 150); pdf_lineto($pdf, 610, 55); pdf_lineto($pdf, 632, 69); pdf_lineto($pdf, 646, 49); pdf_lineto($pdf, 666, 150); pdf_closepath($pdf); pdf_fill($pdf); // outline ribbon 1