Example #1
0
 function OpenFile()
 {
     $caminho = 'tmp/';
     $lim_dir = opendir('tmp/');
     $fonte = APP_ROOT . DS . 'arquivos/fontes/FreeMonoBold.ttf';
     while ($lim_file = readdir($lim_dir)) {
         if ($lim_file != '.' && $lim_file != '..') {
             if (!substr_count($lim_file, date('Y-m-d'))) {
                 @unlink('tmp/' . $lim_file);
             }
         }
     }
     $caminho .= date('Y-m-d') . '-';
     list($usec, $sec) = explode(' ', microtime());
     $caminho .= substr(md5($usec . $sec), 0, 8);
     $caminho .= '.pdf';
     $this->caminho = APP_ROOT . DS . $caminho;
     $this->LinkArquivo = $caminho;
     $this->pdf = PDF_new();
     pdf_set_parameter($this->pdf, 'FontOutline', 'monospaced=' . $fonte);
     PDF_open_file($this->pdf, $this->caminho);
     PDF_set_info($this->pdf, 'Creator', $this->owner);
     PDF_set_info($this->pdf, 'Author', $this->owner);
     PDF_set_info($this->pdf, 'Title', $this->titulo);
     if ($this->depurar) {
         echo '<b>PDF:</b> Objeto criado!<br>';
         echo '<b>PDF:</b> O objeto foi criado no seguinte local -> ' . $this->LinkArquivo . '<br>';
     }
     $this->OpenPage();
 }
 function reset(&$media)
 {
     OutputDriverGenericPDF::reset($media);
     // Check if PDFLIB is available
     if (!extension_loaded('pdf')) {
         // Try to use "dl" to dynamically load PDFLIB
         $result = dl(PDFLIB_DL_PATH);
         if (!$result) {
             readfile(HTML2PS_DIR . 'templates/missing_pdflib.html');
             error_log("No PDFLIB extension found");
             die("HTML2PS Error");
         }
     }
     $this->pdf = pdf_new();
     // Set PDF compatibility level
     pdf_set_parameter($this->pdf, "compatibility", $this->get_pdf_version());
     /**
      * Use PDF license key, if present
      *
      * PDFLIB_LICENSE constant is defined in 'config.inc.php' file in "PDFLIB-specific" section.
      */
     if (defined("PDFLIB_LICENSE")) {
         pdf_set_parameter($this->pdf, "license", PDFLIB_LICENSE);
     }
     pdf_open_file($this->pdf, $this->get_filename());
     // @TODO: compression level, debug
     pdf_set_value($this->pdf, "compress", 0);
     // Set path to the PDFLIB UPR file containig information about fonts and encodings
     if (defined("PDFLIB_UPR_PATH")) {
         pdf_set_parameter($this->pdf, "resourcefile", PDFLIB_UPR_PATH);
     }
     // Setup encodings not bundled with PDFLIB
     $filename = $this->generate_cpg('koi8-r');
     pdf_set_parameter($this->pdf, 'Encoding', sprintf('koi8-r=%s', $filename));
     // Setup font outlines
     global $g_font_resolver_pdf;
     $g_font_resolver_pdf->setup_ttf_mappings($this->pdf);
     $pdf = $this->pdf;
     pdf_set_info($pdf, "Creator", "html2ps (PHP version)");
     // No borders around links in the generated PDF
     pdf_set_border_style($this->pdf, "solid", 0);
     $this->_status = PDFLIB_STATUS_DOCUMENT_STARTED;
 }
Example #3
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 setup_ttf_mappings($pdf)
 {
     foreach ($this->ttf_mappings as $typeface => $file) {
         pdf_set_parameter($pdf, "FontOutline", $typeface . "=" . TTF_FONTS_REPOSITORY . $file);
     }
 }
Example #5
0
}
// A4 page: 595 x 842 points
$radius = 177;
$margin = 120;
$ring = 40;
$header = 20;
$footer = 228;
$file = tempnam("", "tests") . '.pdf';
$width = 2 * ($radius + $margin);
$height = 2 * ($radius + $margin) + $header + $footer;
$pdf = pdf_new();
if (!pdf_open_file($pdf, $file)) {
    echo "error";
    exit;
}
pdf_set_parameter($pdf, "warning", "true");
pdf_set_info($pdf, "Creator", "Phalanger");
pdf_set_info($pdf, "Author", "Uwe Steinmann");
pdf_set_info($pdf, "Title", "Analog Clock");
pdf_begin_page($pdf, $width, $height);
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);
}
/* outlined */
center("It is {$texttime}.", $height - 60, 42, "Times-Roman", 1);
Example #6
0
 function _presentation(&$presentation)
 {
     global $pres;
     $_SESSION['selected_display_mode'] = get_class($this);
     // In PDF mode we loop through all the slides and make a single
     // big multi-page PDF document.
     $this->page_number = 0;
     $this->pdf = pdf_new();
     if (!empty($pdfResourceFile)) {
         pdf_set_parameter($this->pdf, "resourcefile", $pdfResourceFile);
     }
     pdf_open_file($this->pdf, null);
     pdf_set_info($this->pdf, "Author", isset($presentation->speaker) ? $presentation->speaker : "Anonymous");
     pdf_set_info($this->pdf, "Title", isset($presentation->title) ? $presentation->title : "No Title");
     pdf_set_info($this->pdf, "Creator", "See Author");
     pdf_set_info($this->pdf, "Subject", isset($presentation->topic) ? $presentation->topic : "");
     while (list($this->slideNum, $slide) = each($presentation->slides)) {
         // testing hack
         $slideDir = dirname($this->presentationDir . '/' . $presentation->slides[$this->slideNum]->filename) . '/';
         $fn = $this->presentationDir . '/' . $presentation->slides[$this->slideNum]->filename;
         $fh = fopen($fn, "rb");
         $r =& new XML_Slide($fh);
         $r->setErrorHandling(PEAR_ERROR_DIE, "%s ({$fn})\n");
         $r->parse();
         $this->objs = $r->getObjects();
         $this->my_new_pdf_page($this->pdf, $this->pdf_x, $this->pdf_y, true);
         $this->pdf_cx = $this->pdf_cy = 0;
         // Globals that keep our current x,y position
         while (list($this->coid, $obj) = each($this->objs)) {
             $obj->display();
         }
         $this->my_new_pdf_end_page($this->pdf);
     }
     $this->my_new_pdf_page($this->pdf, $this->pdf_x, $this->pdf_y, true);
     pdf_set_font($this->pdf, $this->pdf_font, -20, 'winansi');
     $fnt = pdf_findfont($this->pdf, $this->pdf_font, 'winansi', 0);
     $dx = pdf_stringwidth($this->pdf, "Index", $fnt, -20);
     $x = (int) ($this->pdf_x / 2 - $dx / 2);
     pdf_set_parameter($this->pdf, "underline", 'true');
     pdf_show_xy($this->pdf, "Index", $x, 60);
     pdf_set_parameter($this->pdf, "underline", 'false');
     $this->pdf_cy = pdf_get_value($this->pdf, "texty", null) + 30;
     $old_cy = $this->pdf_cy;
     pdf_set_font($this->pdf, $this->pdf_font, -12, 'winansi');
     if (is_array($this->page_index)) {
         foreach ($this->page_index as $pn => $ti) {
             if ($ti == 'titlepage') {
                 continue;
             }
             $ti .= '    ';
             while (pdf_stringwidth($this->pdf, $ti, $fnt, -12) < $this->pdf_x - $this->pdf_cx * 2.5 - 140) {
                 $ti .= '.';
             }
             pdf_show_xy($this->pdf, $ti, $this->pdf_cx * 2.5, $this->pdf_cy);
             $dx = pdf_stringwidth($this->pdf, $pn, $fnt, -12);
             pdf_show_xy($this->pdf, $pn, $this->pdf_x - 2.5 * $this->pdf_cx - $dx, $this->pdf_cy);
             $this->pdf_cy += 15;
             if ($this->pdf_cy > $this->pdf_y - 50) {
                 $this->my_new_pdf_end_page($this->pdf);
                 $this->my_new_pdf_page($this->pdf, $this->pdf_x, $this->pdf_y, false);
                 $this->pdf_cy = $old_cy;
                 pdf_set_font($this->pdf, $this->pdf_font, -12, 'winansi');
             }
         }
     }
     $this->my_new_pdf_end_page($this->pdf);
     pdf_close($this->pdf);
     $data = pdf_get_buffer($this->pdf);
     header('Content-type: application/pdf');
     header('Content-disposition: inline; filename=' . $_SESSION['currentPres'] . '.pdf');
     header("Content-length: " . strlen($data));
     echo $data;
 }
Example #7
0
	FROM bitmap
	WHERE album_id = "' . mysql_real_escape_string($album_id) . '"');
$bitmap = mysql_fetch_assoc($query);
//  +------------------------------------------------------------------------+
//  | Initialize PDF                                                         |
//  +------------------------------------------------------------------------+
$pdf = pdf_new();
if (pdf_get_value($pdf, 'major', 0) < 5) {
    pdf_close($pdf);
    message(__FILE__, __LINE__, 'error', '[b]netjukebox requires PDFlib 5 or later[/b]');
}
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);
//  +------------------------------------------------------------------------+
Example #8
0
<?php

# pdf_example4
# a simple bar graph
// create a new pdf document
$pdf = pdf_new();
$filename = 'c:pdf_example4.pdf';
pdf_open_file($pdf, $filename);
// start a new page (Letter size)
pdf_begin_page($pdf, 612, 792);
// setup font and print hello world
pdf_set_parameter($pdf, 'FontOutline', 'Arial=c:windowsfontsarial.ttf');
$font = pdf_findfont($pdf, "Arial", "host", 1);
pdf_setfont($pdf, $font, 16);
pdf_show_xy($pdf, "Simple Bar Graph", 50, 720);
// draw the x and y axis
pdf_moveto($pdf, 50, 690);
pdf_lineto($pdf, 50, 520);
pdf_lineto($pdf, 400, 520);
pdf_stroke($pdf);
// draw the bar chart
$x = 80;
$y = 520;
$w = 40;
// 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;
Example #9
0
<?php

$p = PDF_new();
PDF_open_file($p);
PDF_set_info($p, "Creator", "hello.php");
PDF_set_info($p, "Author", "Rasmus Lerdorf");
PDF_set_info($p, "Title", "Hello world (PHP)");
pdf_set_parameter($p, "resourcefile", "/usr/share/fonts/pdflib/pdflib.upr");
PDF_begin_page($p, 595, 842);
PDF_set_text_pos($p, 25, 800);
$fonts = array('Courier' => 0, 'Courier-Bold' => 0, 'Courier-BoldOblique' => 0, 'Courier-Oblique' => 0, 'Helvetica' => 0, 'Helvetica-Bold' => 0, 'Helvetica-BoldOblique' => 0, 'Helvetica-Oblique' => 0, 'Times-Bold' => 0, 'Times-BoldItalic' => 0, 'Times-Italic' => 0, 'Times-Roman' => 0, 'LuciduxSans' => 1, 'Utopia-Regular' => 1, 'URWGothicL-BookObli' => 1, 'URWPalladioL-Roma' => 1, 'NimbusMonL-ReguObli' => 1, 'CANDY' => 1, 'Arial' => 1);
foreach ($fonts as $f => $embed) {
    $font = PDF_findfont($p, $f, "host", $embed);
    PDF_setfont($p, $font, 25.0);
    PDF_continue_text($p, "{$f} (" . chr(128) . " Ç à á â ã ç è é ê)");
}
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=hello_php.pdf");
echo $buf;
PDF_delete($p);