Exemplo n.º 1
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>";
?>
    
Exemplo n.º 2
0
 function my_pdf_paginated_code(&$pdf, $data, $x, $y, $tm, $bm, $lm, $rm, $font, $fs)
 {
     $data = strip_markups($data);
     pdf_set_font($pdf, $font, $fs, 'winansi');
     $fnt = pdf_findfont($pdf, $font, 'winansi', 0);
     $cw = pdf_stringwidth($pdf, 'm', $fnt, $fs);
     // Width of 1 char - assuming monospace
     $linelen = (int) (($x - $lm - $rm) / $cw);
     // Number of chars on a line
     $pos = $i = 0;
     $len = strlen($data);
     pdf_set_text_pos($pdf, $lm, $tm);
     $np = true;
     while ($pos < $len) {
         $nl = strpos(substr($data, $pos), "\n");
         if ($nl === 0) {
             if ($np) {
                 pdf_show($pdf, "");
                 $np = false;
             } else {
                 pdf_continue_text($pdf, "");
             }
             $pos++;
             continue;
         }
         if ($nl !== false) {
             $ln = substr($data, $pos, $nl);
         } else {
             $ln = substr($data, $pos);
             $nl = $len - $pos;
         }
         if ($nl > $linelen) {
             // Line needs to be wrapped
             $ln = wordwrap($ln, $linelen);
             $out = explode("\n", $ln);
         } else {
             $out = array($ln);
         }
         foreach ($out as $l) {
             $l = str_replace("\t", '    ', $l);
             // 4-space tabs - should probably be an attribute
             if ($np) {
                 pdf_show($pdf, $l);
                 $np = false;
             } else {
                 pdf_continue_text($pdf, $l);
             }
         }
         $pos += $nl + 1;
         if (pdf_get_value($pdf, "texty", null) >= $y - $bm) {
             $this->my_pdf_page_number($pdf, $x, $y);
             $this->my_new_pdf_end_page($pdf);
             $this->my_new_pdf_page($pdf, $x, $y, true);
             pdf_set_font($pdf, $font, $fs, 'winansi');
             pdf_set_text_pos($pdf, $lm, 60);
             $np = true;
         }
     }
 }
Exemplo n.º 3
0
     $temp .= "         " . $meta['number'] . " - " . $track->getName() . "\n";
 }
 $font = pdf_findfont($pdf, 'Helvetica', 'winansi', 0);
 pdf_setfont($pdf, $font, 3);
 pdf_show_boxed($pdf, $temp, 6.5, 0, 138, 108, 'left', '');
 pdf_setfont($pdf, $font, 4);
 pdf_set_text_pos($pdf, 2, -4.5);
 //y,-x
 pdf_rotate($pdf, 90);
 pdf_show($pdf, $artist . ' - ' . $album);
 pdf_rotate($pdf, -90);
 pdf_setfont($pdf, $font, 4);
 pdf_set_text_pos($pdf, -116, 151 - 4.5);
 //-y,x
 pdf_rotate($pdf, -90);
 pdf_show($pdf, $artist . ' - ' . $album);
 pdf_rotate($pdf, 90);
 //  +---------------------------------------------------------------------------+
 //  | PDF Front Cover                                                           |
 //  +---------------------------------------------------------------------------+
 $x0 = 44 - $x0;
 $y0 = 160 - $y0;
 pdf_translate($pdf, $x0, $y0);
 pdf_moveto($pdf, 0, -1);
 pdf_lineto($pdf, 0, -11);
 pdf_moveto($pdf, 121, -1);
 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);
Exemplo n.º 4
0
        $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;
}
//  +------------------------------------------------------------------------+
//  | PDF front cover                                                        |
//  +------------------------------------------------------------------------+
$x0 = 44 - $x0;
$y0 = 160 - $y0;
pdf_translate($pdf, $x0, $y0);
pdf_moveto($pdf, 0, -1);
pdf_lineto($pdf, 0, -11);
pdf_moveto($pdf, 121, -1);
pdf_lineto($pdf, 121, -11);
pdf_moveto($pdf, 0, 121);
Exemplo n.º 5
0
 function add_poll($name, $opts, $ttl_votes)
 {
     $this->y = pdf_get_value($this->pdf, 'texty', 0) - 3;
     pdf_set_text_pos($this->pdf, $this->wmargin, $this->y - 3);
     pdf_setfont($this->pdf, $this->fonts['Courier-Bold'], 20);
     pdf_continue_text($this->pdf, $name);
     pdf_setfont($this->pdf, $this->fonts['Courier-Bold'], 16);
     pdf_show($this->pdf, '(total votes: ' . $ttl_votes . ')');
     $this->draw_line();
     $ttl_w = round($this->pw * 0.66);
     $ttl_h = 20;
     $p1 = floor($ttl_w / 100);
     $this->y -= 10;
     /* avoid /0 warnings and safe to do, since we'd be multiplying 0 since there are no votes */
     if (!$ttl_votes) {
         $ttl_votes = 1;
     }
     pdf_setfont($this->pdf, $this->fonts['Helvetica-Bold'], 14);
     foreach ($opts as $o) {
         $w1 = $p1 * ($o['votes'] / $ttl_votes * 100);
         $h1 = $this->y - $ttl_h;
         pdf_setcolor($this->pdf, 'both', 'rgb', 0.92, 0.92, 0.92);
         pdf_rect($this->pdf, $this->wmargin, $h1, $w1, $ttl_h);
         pdf_fill_stroke($this->pdf);
         pdf_setcolor($this->pdf, 'both', 'rgb', 0, 0, 0);
         pdf_show_xy($this->pdf, $o['name'] . "\t\t" . $o['votes'] . '/(' . round($o['votes'] / $ttl_votes * 100) . '%)', $this->wmargin + 2, $h1 + 3);
         $this->y = $h1 - 10;
     }
 }