示例#1
0
 function pdf_set_font($pdf, $font_name, $fs, $encoding)
 {
     $font = pdf_findfont($pdf, $font_name, $encoding, 0);
     if ($font) {
         return pdf_setfont($pdf, $font, $fs);
     }
     return false;
 }
示例#2
0
function center($s, $y, $size, $fontname = "Times-Roman", $outline = 0)
{
    global $pdf, $font, $width;
    pdf_set_value($pdf, "textrendering", $outline);
    $font = pdf_findfont($pdf, $fontname, "iso8859-2");
    pdf_setfont($pdf, $font, $size);
    $w = pdf_stringwidth($pdf, $s);
    pdf_show_xy($pdf, $s, ($width - $w) / 2, $y);
}
示例#3
0
 function drawText($text, $left, $right, $height, $style)
 {
     $h = $height;
     // Creating duplicate (temp)
     $this->_convertPosition($left, $height);
     $this->_convertPosition($right, $h);
     pdf_setcolor($this->pdf, 'fill', $style['fill'][0], $style['fill'][1], $style['fill'][2], $style['fill'][3], $style['fill'][4]);
     pdf_setfont($this->pdf, $this->font, $style['font']);
     pdf_show_boxed($this->pdf, $text, $left, $height - $style['font'], $right - $left, $style['font'], $style['align'], '');
 }
 function _show_watermark($watermark)
 {
     $font = $this->findfont('Helvetica', 'iso-8859-1');
     pdf_setfont($this->pdf, $font, 100);
     $x = $this->left + $this->width / 2;
     $y = $this->bottom + $this->height / 2 + $this->offset;
     pdf_set_value($this->pdf, "textrendering", 1);
     pdf_translate($this->pdf, $x, $y);
     pdf_rotate($this->pdf, 60);
     pdf_show_xy($this->pdf, $watermark, -pdf_stringwidth($this->pdf, $watermark, $font, 100) / 2, -50);
 }
示例#5
0
 /**
  * Set the PDF font
  *
  * @access private
  */
 function _setFont()
 {
     $this->_pdfFont = false;
     if (isset($this->_font['name'])) {
         pdf_set_parameter($this->_pdf, 'FontOutline', $this->_font['name'] . '=' . $this->_font['file']);
         $this->_pdfFont = pdf_findfont($this->_pdf, $this->_font['name'], $this->_font['encoding'], 1);
         if ($this->_pdfFont) {
             pdf_setfont($this->_pdf, $this->_pdfFont, $this->_font['size']);
             $this->_setFillStyle($this->_font['color']);
         }
     } else {
         $this->_setFillStyle('black');
     }
 }
 function _show_watermark()
 {
     if (is_null($this->_watermark) || $this->_watermark == "") {
         return;
     }
     $font = $this->_control_font();
     pdf_setfont($this->pdf, $font, 100);
     $x = $this->left + $this->width / 2;
     $y = $this->bottom + $this->height / 2 + $this->offset;
     pdf_set_value($this->pdf, "textrendering", 1);
     pdf_translate($this->pdf, $x, $y);
     pdf_rotate($this->pdf, 60);
     pdf_show_xy($this->pdf, $this->_watermark, -pdf_stringwidth($this->pdf, $this->_watermark, $font, 100) / 2, -50);
 }
示例#7
0
<?php

//create file
$fp = fopen('hello.pdf', 'w');
if (!$fp) {
    echo "Error: could not create the PDF file";
    exit;
}
// start the pdf document
$pdf = pdf_open($fp);
pdf_set_info($pdf, "Creator", "pdftest.php");
pdf_set_info($pdf, "Author", "Luke Welling and Laura Thomson");
pdf_set_info($pdf, "Title", "Hello World (PHP)");
// US letter is 11" x 8.5" and there are 72 points per inch
pdf_begin_page($pdf, 8.5 * 72, 11 * 72);
pdf_add_outline($pdf, 'Page 1');
$font = pdf_findfont($pdf, 'Times-Roman', 'host', 0);
pdf_setfont($pdf, $font, 24);
pdf_set_text_pos($pdf, 50, 700);
// write text
pdf_show($pdf, 'Hello,world!');
pdf_continue_text($pdf, '(says PHP)');
// end the document
pdf_end_page($pdf);
pdf_close($pdf);
fclose($fp);
// display a link to download
echo "download the pdf <a href = 'hello.pdf'>here</a>";
?>
    
示例#8
0
         $text .= $track['artist'] . ' - ' . $track['title'] . "\n";
     }
     $previous_disc = $track['disc'];
 }
 // $text = iconv(NJB_DEFAULT_CHARSET, 'UTF-8', $text);
 pdf_setfont($pdf, $font, 3);
 pdf_show_boxed($pdf, $text, 6.5, 0, 138, 108, 'center', '');
 $query = mysql_query('SELECT artist, album FROM album WHERE album_id = "' . mysql_real_escape_string($album_id) . '"');
 $album = mysql_fetch_assoc($query);
 if (in_array(strtolower($album['artist']), $cfg['no_album_artist'])) {
     $title = $album['album'];
 } else {
     $title = $album['artist'] . ' - ' . $album['album'];
 }
 // $title = iconv(NJB_DEFAULT_CHARSET, 'UTF-8', $title);
 pdf_setfont($pdf, $font, 4);
 pdf_save($pdf);
 pdf_rotate($pdf, 90);
 pdf_set_text_pos($pdf, 2, -4.5);
 // y, -x
 pdf_show($pdf, $title);
 pdf_restore($pdf);
 // Restore rotate
 pdf_save($pdf);
 pdf_rotate($pdf, -90);
 pdf_set_text_pos($pdf, -116, 151 - 4.5);
 // -y, x
 pdf_show($pdf, $title);
 pdf_restore($pdf);
 // Restore rotate
 $hash_data .= '-' . $text . '-' . $title;
示例#9
0
<?php

// create handle for new PDF document
$pdf = pdf_new();
// open a file
pdf_open_file($pdf, "philosophy.pdf");
// start a new page (A4)
pdf_begin_page($pdf, 595, 842);
// get and use a font object
$arial = pdf_findfont($pdf, "Arial", "host", 1);
pdf_setfont($pdf, $arial, 10);
// print text
pdf_show_xy($pdf, "There are more things in heaven and earth, Horatio,", 50, 750);
pdf_show_xy($pdf, "than are dreamt of in your philosophy", 50, 730);
// end page
pdf_end_page($pdf);
// close and save file
pdf_close($pdf);
示例#10
0
// the data and color for each column
$data = array('120', '160', '300', '240');
$color = array('#4EC3BC', '#DAA876', '#E29CC8', '#FDE0C6');
// get into some meat now, cheese for vegetarians;
for ($i = 0; $i < count($data); $i++) {
    // calculate the height of the bar
    $y_ht = $data[$i] / max($data) * 100;
    // set the color for each bar
    list($r, $g, $b) = hex2rgb($color[$i]);
    pdf_setcolor($pdf, "fill", "rgb", $r, $g, $b, 0);
    // draw the bar
    pdf_rect($pdf, $x, $y, $w, $y_ht);
    pdf_fill_stroke($pdf);
    // write the bar label
    pdf_setcolor($pdf, "fill", "rgb", 0, 0, 0, 0);
    pdf_setfont($pdf, $font, 10);
    pdf_show_xy($pdf, $data[$i], $x + 12, $y - 16);
    // go to the next bar
    $x = $x + $w + 40;
}
// done
pdf_end_page($pdf);
pdf_close($pdf);
pdf_delete($pdf);
// send it to browser
header("Content-type: application/pdf");
header("Content-Disposition: inline; filename=pdf_example3.pdf");
readfile($filename);
unlink($filename);
// function to convert a standard rgb from hex to float
function hex2rgb($hex)
示例#11
0
<?php

define('PAGE_WIDTH', 612);
define('PAGE_HEIGHT', 792);
$pdf = pdf_new();
pdf_open_file($pdf);
pdf_begin_page($pdf, PAGE_WIDTH, PAGE_HEIGHT);
$font = pdf_findfont($pdf, "Helvetica", "auto", false);
pdf_setfont($pdf, $font, 30);
pdf_show_xy($pdf, "PHP Developer's Handbook", 10, PAGE_HEIGHT - 40);
pdf_setfont($pdf, $font, 12);
pdf_show_xy($pdf, "Hello, World! Using PDFLib and PHP", 10, PAGE_HEIGHT - 55);
pdf_end_page($pdf);
pdf_close($pdf);
$data = pdf_get_buffer($pdf);
header('Content-type: application/pdf');
header("Content-disposition: inline; filename=output.pdf");
header("Content-length: " . strlen($data));
echo $data;
示例#12
0
 function message_header($subject, $author, $date, $id, $th)
 {
     $y = pdf_get_value($this->pdf, 'texty', 0) - 3;
     if ($y < 100) {
         $this->end_page();
         $this->begin_page($this->pg_title);
         $y = $this->ph - $this->hmargin;
     }
     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 - 5);
     pdf_setfont($this->pdf, $this->fonts['Helvetica'], 14);
     pdf_continue_text($this->pdf, 'Subject: ' . $subject);
     pdf_continue_text($this->pdf, 'Posted by ' . $author . ' on ' . gmdate('D, d M Y H:i:s \\G\\M\\T', $date));
     pdf_continue_text($this->pdf, 'URL: ');
     $url = $GLOBALS['WWW_ROOT'] . '?t=rview&th=' . $th . '&goto=' . $id;
     $this->add_link($url, $url);
     $this->draw_line();
     pdf_set_text_pos($this->pdf, $this->wmargin, $this->y - 3);
 }
 if ($font) {
     pdf_setfont($pdf, $font, 48);
 }
 $startx = ($width - pdf_stringwidth($pdf, 'PHP Certification', $font, '12')) / 2;
 pdf_show_xy($pdf, 'PHP Certification', $startx, 490);
 // add text
 $font = pdf_findfont($pdf, $fontname, 'host', 0);
 if ($font) {
     pdf_setfont($pdf, $font, 26);
 }
 $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_show_xy($pdf, "Attendance:", 50, 100);
    // Full Days Text //
    pdf_setfont($pdf, $body, 10);
    pdf_show_xy($pdf, "Full Days", 150, 100);
    // Full Days Text Above Line //
    pdf_setfont($pdf, $body, 10);
    pdf_show_xy($pdf, "{$full}", 125, 100);
    // Full Days Line //
    pdf_moveto($pdf, 110, 99);
    pdf_lineto($pdf, 145, 99);
    pdf_stroke($pdf);
    // Half Days Text //
    pdf_setfont($pdf, $body, 10);
    pdf_show_xy($pdf, "Half Days", 240, 100);
    // Half Days Text Above Line //
    pdf_setfont($pdf, $body, 10);
    pdf_show_xy($pdf, "{$half}", 215, 100);
    // Half Days Line //
    pdf_moveto($pdf, 200, 99);
    pdf_lineto($pdf, 235, 99);
    pdf_stroke($pdf);
    pdf_end_page($pdf);
}
//close it up
pdf_close($pdf);
$data = pdf_get_buffer($pdf);
// Close up the db connection //
mysql_close($dbcnx);
header('Content-type: application/pdf');
header('Content-disposition: attachment; filename=ReportCard.pdf');
header('Content-length: ' . strlen($data));