Exemplo n.º 1
0
<?php

$p = PDF_new();
PDF_open_file($p);
PDF_begin_page($p, 595, 842);
$im = pdf_open_png($p, "fr-flag.png");
pdf_add_thumbnail($p, $im);
pdf_close_image($p, $im);
$top = PDF_add_bookmark($p, "Countries");
$font = PDF_findfont($p, "Helvetica-Bold", "host", 0);
PDF_setfont($p, $font, 20);
PDF_add_bookmark($p, "France", $top);
PDF_show_xy($p, "This is a page about France", 50, 800);
PDF_end_page($p);
PDF_begin_page($p, 595, 842);
$im = pdf_open_png($p, "dk-flag.png");
pdf_add_thumbnail($p, $im);
pdf_close_image($p, $im);
PDF_setfont($p, $font, 20);
PDF_add_bookmark($p, "Denmark", $top);
PDF_show_xy($p, "This is a page about Denmark", 50, 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=gra2.pdf");
echo $buf;
PDF_delete($p);
Exemplo n.º 2
0
<?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);
Exemplo n.º 3
0
 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;
             }
         }
     }
 }
<?php

$p = PDF_new();
PDF_open_file($p);
$im = pdf_open_png($p, "wa.png");
$pattern = pdf_begin_pattern($p, 81, 41, 81, 41, 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, 50.0);
PDF_circle($p, 200, 680, 140);
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);