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); }
/** * 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 font_descender($name, $encoding) { return -pdf_get_value($this->pdf, "descender", $this->findfont($name, $encoding)); }
/** * Check which major version of PDFlib is installed * * @return int The mahor version number of PDFlib * @access private */ function _version() { $result = false; $version = ''; if (function_exists('pdf_get_majorversion')) { $version = pdf_get_majorversion(); } else { if (function_exists('pdf_get_value')) { $version = pdf_get_value($this->_pdf, 'major', 0); } else { ob_start(); phpinfo(8); $php_info = ob_get_contents(); ob_end_clean(); if (ereg("<td[^>]*>PDFlib GmbH Version *<\\/td><td[^>]*>([^<]*)<\\/td>", $php_info, $result)) { $version = $result[1]; } } } if (ereg('([0-9]{1,2})\\.[0-9]{1,2}(\\.[0-9]{1,2})?', trim($version), $result)) { return $result[1]; } else { return $version; } }
<?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);
function _link(&$link) { if (empty($link->text)) { $link->text = preg_replace('/:-:(.*?):-:/e', '$this->pres->\\1', $link->href); } if (!empty($link->leader)) { $leader = preg_replace('/:-:(.*?):-:/e', '$this->pres->\\1', $link->leader); } else { $leader = ''; } if (!empty($link->text)) { $this->pdf_cy = pdf_get_value($this->pdf, "texty", null) + 10; pdf_set_font($this->pdf, $this->pdf_font, -12, 'winansi'); $fnt = pdf_findfont($this->pdf, $this->pdf_font, 'winansi', 0); if (strlen($leader)) { $lx = pdf_stringwidth($this->pdf, $leader, $fnt, -12); } else { $lx = 0; } $dx = pdf_stringwidth($this->pdf, $link->text, $fnt, -12); $cw = pdf_stringwidth($this->pdf, 'm', $fnt, -12); // em unit width switch ($link->align) { case 'center': $x = (int) ($this->pdf_x / 2 - $dx / 2 - $lx / 2); break; case 'right': $x = $this->pdf_x - $this->pdf_cx - $dx - $lx - 15; break; case 'left': default: $x = $this->pdf_cx; break; } if ($link->marginleft) { $x += (int) ((double) $link->marginleft * $cw); } pdf_add_weblink($this->pdf, $x + $lx, $this->pdf_y - $this->pdf_cy - 3, $x + $dx + $lx, $this->pdf_y - $this->pdf_cy + 12, $link->text); pdf_show_xy($this->pdf, strip_markups($leader) . strip_markups($link->text), $x, $this->pdf_cy); pdf_continue_text($this->pdf, ""); } }
} pdf_open_file($pdf, ''); $font = pdf_load_font($pdf, 'Helvetica', 'host', ''); // winansi, host, iso8859-1, unicode >> unicode and glyph id addressing not supported in PDFlib Lite!!! if (NJB_DEFAULT_CHARSET == 'UTF-8') { pdf_set_parameter($pdf, 'textformat', 'utf8'); } pdf_set_info($pdf, 'Creator', 'netjukebox ' . NJB_VERSION); pdf_set_info($pdf, 'Title', $album['artist'] . ' - ' . $album['album']); $width = 210; // A4 $height = 297; // A4 $scale = 72 / 25.4; // mm to dtp-point (1 point = 1/72 inch; 1 inch = 25.4 mm) $hash_data = pdf_get_value($pdf, 'major', 0) . '-' . pdf_get_value($pdf, 'minor', 0) . '-' . NJB_VERSION; $hash_data .= '-' . $album['artist'] . ' - ' . $album['album'] . '-' . $width . '-' . $height; pdf_begin_page($pdf, $width * $scale, $height * $scale); pdf_scale($pdf, $scale, $scale); pdf_setlinewidth($pdf, 0.1); // +------------------------------------------------------------------------+ // | PDF back cover | // +------------------------------------------------------------------------+ $x0 = 30; $y0 = 22; pdf_translate($pdf, $x0, $y0); pdf_moveto($pdf, 0, -1); pdf_lineto($pdf, 0, -11); pdf_moveto($pdf, 6.5, -1); pdf_lineto($pdf, 6.5, -11); pdf_moveto($pdf, 144.5, -1);
<?php if (extension_loaded('pdf')) { $pdf = pdf_new(); print pdf_get_value($pdf, 'major', 0); print pdf_get_value($pdf, 'minor', 0); print pdf_get_value($pdf, 'revision', 0); }
pdf_stroke($pdf); // Do we have album art? 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;
function end_message() { $y = pdf_get_value($this->pdf, 'texty', 0) - 10; pdf_moveto($this->pdf, $this->wmargin, $y); pdf_lineto($this->pdf, $this->pw - $this->wmargin, $y); pdf_moveto($this->pdf, $this->wmargin, $y - 3); pdf_lineto($this->pdf, $this->pw - $this->wmargin, $y - 3); pdf_stroke($this->pdf); pdf_set_text_pos($this->pdf, $this->wmargin, $y - 20); }