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);
 }
Пример #2
0
pdf_lineto($pdf, 121, -11);
pdf_moveto($pdf, 0, 121);
pdf_lineto($pdf, 0, 131);
pdf_moveto($pdf, 121, 121);
pdf_lineto($pdf, 121, 131);
pdf_moveto($pdf, -1, 0);
pdf_lineto($pdf, -11, 0);
pdf_moveto($pdf, -1, 120);
pdf_lineto($pdf, -11, 120);
pdf_moveto($pdf, 122, 0);
pdf_lineto($pdf, 132, 0);
pdf_moveto($pdf, 122, 120);
pdf_lineto($pdf, 132, 120);
pdf_stroke($pdf);
if ($bitmap['front_resolution'] >= $cfg['image_front_cover_treshold']) {
    $pdfdfimage = pdf_load_image($pdf, 'auto', $cfg['media_dir'] . $bitmap['image_front'], '');
    pdf_fit_image($pdf, $pdfdfimage, 0, 0, 'boxsize {121 120} position {50 50} fitmethod slice');
    $hash_data .= '-' . filesize($cfg['media_dir'] . $bitmap['image_front']) . '-' . filemtime($cfg['media_dir'] . $bitmap['image_front']);
}
//  +------------------------------------------------------------------------+
//  | Close and download PDF                                                 |
//  +------------------------------------------------------------------------+
pdf_end_page($pdf);
pdf_close($pdf);
$data = pdf_get_buffer($pdf);
pdf_delete($pdf);
$filename = $album['artist'] . ' - ' . $album['album'] . '.pdf';
$filename = downloadFilename($filename);
$etag = '"' . md5($hash_data) . '"';
streamData($data, 'application/pdf', 'inline', $filename, $etag);
updateCounter($album_id, NJB_COUNTER_COVER);
Пример #3
0
 /**
  * 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);
 }
 $startx = 70;
 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_load_image($pdf, 'png', '/Program Files/Apache Software Foundation/Apache2.2/htdocs/phpmysql4e/chapter33/signature.png', '');
 pdf_fit_image($pdf, $signature, 200, 75, '');
 pdf_close_image($pdf, $signature);
 // set up colors for ribbon
 pdf_setcolor($pdf, 'fill', 'rgb', 0, 0, 0.4, 0);
 // dark blue
 pdf_setcolor($pdf, 'stroke', 'rgb', 0, 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);