function output($options = null) {

    // Add page text
    $this->_add_page_text();

    if ( isset($options["compress"]) && $options["compress"] != 1 )
      $this->_pdf->set_value("compress", 0);
    else
      $this->_pdf->set_value("compress", 6);

    $this->_close();

    if ( self::$IN_MEMORY )
      $data = $this->_pdf->get_buffer();

    else {
      $data = file_get_contents($this->_file);

      //debugpng
      if (DEBUGPNG) print '[pdflib output unlink '.$this->_file.']';
      if (!DEBUGKEEPTEMP)

      unlink($this->_file);
      $this->_file = null;
      unset($this->_file);
    }

    return $data;
  }
Example #2
0
 public function __construct(Document $doc, $canvas = null)
 {
     if (self::DEBUG) {
         echo __FUNCTION__ . "\n";
     }
     $dimensions = $doc->getDimensions();
     $w = $dimensions["width"];
     $h = $dimensions["height"];
     if (!$canvas) {
         $canvas = new \PDFlib();
         /* all strings are expected as utf8 */
         $canvas->set_option("stringformat=utf8");
         $canvas->set_option("errorpolicy=return");
         /*  open new PDF file; insert a file name to create the PDF on disk */
         if ($canvas->begin_document("", "") == 0) {
             die("Error: " . $canvas->get_errmsg());
         }
         $canvas->set_info("Creator", "PDFlib starter sample");
         $canvas->set_info("Title", "starter_graphics");
         $canvas->begin_page_ext($w, $h, "");
     }
     // Flip PDF coordinate system so that the origin is in
     // the top left rather than the bottom left
     $canvas->setmatrix(1, 0, 0, -1, 0, $h);
     $this->width = $w;
     $this->height = $h;
     $this->canvas = $canvas;
 }
Example #3
0
 function output($options = null)
 {
     // Add page text
     $this->_add_page_text();
     if (isset($options["compress"]) && $options["compress"] != 1) {
         $this->_pdf->set_value("compress", 0);
     } else {
         $this->_pdf->set_value("compress", 6);
     }
     $this->_close();
     if (self::$IN_MEMORY) {
         $data = $this->_pdf->get_buffer();
     } else {
         $data = file_get_contents($this->_file);
         //debugpng
         if ($this->_dompdf->get_option("debugPng")) {
             print '[pdflib output unlink ' . $this->_file . ']';
         }
         if (!$this->_dompdf->get_option("debugKeepTemp")) {
             unlink($this->_file);
         }
         $this->_file = null;
         unset($this->_file);
     }
     return $data;
 }
 function output()
 {
     $this->_close();
     if (self::$IN_MEMORY) {
         $data = $this->_pdf->get_buffer();
     } else {
         $data = file_get_contents($this->_file);
         unlink($this->_file);
         $this->_file = null;
     }
     return $data;
 }
Example #5
0
 function output($options = null)
 {
     // Add page text
     $this->_add_page_text();
     if (isset($options["compress"]) && $options["compress"] != 1) {
         $this->_pdf->set_value("compress", 0);
     } else {
         $this->_pdf->set_value("compress", 6);
     }
     $this->_close();
     if (self::$IN_MEMORY) {
         $data = $this->_pdf->get_buffer();
     } else {
         $data = file_get_contents($this->_file);
         unlink($this->_file);
         $this->_file = null;
     }
     return $data;
 }
Example #6
0
 /**
  * Get a configured instance of PDFLib
  * @return \PDFlib
  * @throws Exception
  */
 protected function getPdf()
 {
     $pdf = new \PDFlib();
     if ($this->_licenseKey) {
         try {
             $pdf->set_option("license={$this->_licenseKey}");
         } catch (PDFlibException $e) {
             throw new Exception("Unable to validate PDFLib license key, check that your PDFLib version is compatible with your key: " . $e->getMessage());
         }
     }
     //This means we must check return values of load_font() etc.
     $pdf->set_option("errorpolicy=exception");
     //  open new PDF file in memory
     $pdf->begin_document("", "");
     $pdf->set_info("Creator", "Jazzee");
     $pdf->set_info("Author", "Jazzee Open Application Platform");
     return $pdf;
 }
 public function generateTanPdf(Customer $customer, $password)
 {
     $tanRepository = $this->getTanRepository();
     $tans = array();
     for ($i = 0; $i < self::NUMBER_OF_INIT_TANS; $i++) {
         $tan = Tan::generate($customer->id);
         if ($tanRepository->saveTan($tan)) {
             $tans[] = $tan;
         }
     }
     $tans = array_map(function ($tan) {
         return $tan->value;
     }, $tans);
     function wrapWithWhitespace($str, $length)
     {
         $neededPadding = $length - strlen($str);
         $front = floor($neededPadding / 2) > 0 ? floor($neededPadding / 2) : 0;
         $back = ceil($neededPadding / 2) > 0 ? ceil($neededPadding / 2) : 0;
         $str = str_repeat(" ", $front) . $str . str_repeat(" ", $back);
         return substr($str, 0, $length);
     }
     try {
         $p = new \PDFlib();
         if ($p->begin_document("", "") == 0) {
             die("Error: " . $p->get_errmsg());
         }
         $p->set_info("Creator", "SitzBank");
         $p->set_info("Author", "SitzBank App");
         $p->set_info("Title", "Tans for {$customer->firstname} {$customer->lastname}");
         $p->set_parameter("textformat", "utf8");
         $p->begin_page_ext(595, 842, "");
         $font = $p->load_font("Helvetica-Bold", "winansi", "");
         $p->setfont($font, 18.0);
         $p->set_text_pos(25, 780);
         $p->show("Tans for {$customer->firstname} {$customer->lastname}");
         $font = $p->load_font("Courier", "winansi", "");
         $p->setfont($font, 9.0);
         $p->set_text_pos(20, 750);
         $p->show(str_repeat("-", 100));
         $tansPerRow = 4;
         for ($i = 0; $i < count($tans); $i += $tansPerRow) {
             $limit = min($i + $tansPerRow, count($tans));
             $row = array_slice($tans, $i, $limit);
             $row = array_map(function ($str) {
                 return wrapWithWhitespace($str, 25);
             }, $row);
             $p->continue_text(implode('|', $row));
         }
         $p->continue_text(str_repeat("-", 100));
         $p->end_page_ext("");
         $p->end_document("");
         $buf = $p->get_buffer();
     } catch (\Exception $e) {
         return JsonErrorResponse::fromKey(JsonErrorResponse::UNEXPECTED_ERROR);
     }
     $temp_file = tempnam(sys_get_temp_dir(), 'SBTanPdf');
     file_put_contents($temp_file, $buf);
     $temp_file_output = $temp_file . "-pw";
     if (in_array(strtoupper(substr(PHP_OS, 0, 3)), array('DAR', 'WIN'))) {
         shell_exec("cp {$temp_file} {$temp_file_output}");
     } else {
         shell_exec("/usr/bin/pdftk {$temp_file} output {$temp_file_output} user_pw {$password}");
     }
     return $temp_file_output;
 }
$sql = "SELECT content FROM site_text WHERE tname = '" . eCRC(dirname($environment["ebene"])) . "." . basename($environment["ebene"]) . "' AND status = '1'";
include $pathvars["moduleroot"] . "wizard/wizard.cfg.php";
$cfg["wizard"]["function"]["print"][] = "makece";
include $pathvars["moduleroot"] . "wizard/wizard-functions.inc.php";
if (($cfg["print"]["path"] == "" || strstr($environment["ebene"], $cfg["print"]["path"])) && class_exists('PDFlib')) {
    $sql = "SELECT content FROM site_text WHERE tname = '" . eCRC(dirname($environment["ebene"])) . "." . basename($environment["ebene"]) . "' AND status = '1'";
    if ($debugging["sql_enable"]) {
        $debugging["ausgabe"] .= "sql: " . $sql . $debugging["char"];
    }
    $result = $db->query($sql);
    $data = $db->fetch_array($result, 1);
    $test = content_split_all($data["content"]);
    $mutate["H"] = array("H");
    #$mutate["B"] = array("");
    $mutate["P"] = array("P");
    $pdf = new PDFlib();
    $pdf->begin_document("", "lang=de tagged=true");
    $pdf->set_info("Creator", "hello.php");
    $pdf->set_info("Author", "STI");
    $pdf->set_info("Title", "Hello world (PHP)!");
    $pdf->set_parameter("autospace", "true");
    $doc = $pdf->begin_item("Document", "Title=Buffy");
    $pdf->begin_page_ext(0, 0, "width=a4.width height=a4.height");
    $font = $pdf->load_font("Helvetica", "unicode", "");
    $pdf->setfont($font, 10);
    $fontname = $pdf->get_parameter("fontname", 0);
    $count = 0;
    $i = 0;
    foreach ($tag_sort as $key => $value) {
        if (array_key_exists($value["para"][0], $mutate)) {
            if ($value["start"] > $count) {
Example #9
0
<?php

$p = new PDFlib();
$p->begin_document(null, null);
$p->set_info('Creator', 'test-pdf.php');
$p->set_info('Author', 'entropy.ch');
$p->set_info('Title', 'PDFlib Test');
$p->begin_page_ext(595, 842, "");
$font = $p->load_font("Helvetica-Bold", "winansi", "");
$p->setfont($font, 24.0);
$p->set_text_pos(50, 700);
$p->show("Hello world!");
$p->continue_text("(says PHP)");
$p->end_page_ext("");
$p->end_document("");
$buf = $p->get_buffer();
$len = strlen($buf);
header("Content-type: application/pdf");
header("Content-Length: {$len}");
header("Content-Disposition: inline; filename=hello.pdf");
print $buf;
$p->delete();
/*



PDF_set_info($p, "Creator", "hello.php");
PDF_set_info($p, "Author", "Rainer Schaaf");
PDF_set_info($p, "Title", "Hello world (PHP)!");

PDF_begin_page_ext($p, 595, 842, "");
    $_REQUEST['spreadlimit'] = '0';
}
if (!isset($_REQUEST['charspacing'])) {
    $_REQUEST['charspacing'] = '100';
}
if (!isset($_REQUEST['nowrap'])) {
    $_REQUEST['nowrap'] = false;
}
$_REQUEST['maxspacing'] = (int) $_REQUEST['maxspacing'] . '%';
$_REQUEST['minspacing'] = (int) $_REQUEST['minspacing'] . '%';
$_REQUEST['nofitlimit'] = (int) $_REQUEST['nofitlimit'] . '%';
$_REQUEST['shrinklimit'] = (int) $_REQUEST['shrinklimit'] . '%';
$_REQUEST['charspacing'] = (int) $_REQUEST['charspacing'] . '%';
$_REQUEST['text'] = str_replace('-', chr(173), $_REQUEST['text']);
try {
    $p = new PDFlib();
    /* open new PDF file; insert a file name to create the PDF on disk */
    if ($p->begin_document('', '') == 0) {
        die("Error: " . $p->get_errmsg());
    }
    $p->begin_page_ext(1100, 600, '');
    $tfcreate_options = array('fontname=Helvetica', 'fontsize=' . $_REQUEST['fontsize'], 'encoding=winansi');
    $tfcreate_options[] = 'alignment=' . $_REQUEST['alignment'];
    $tfcreate_options[] = 'adjustmethod=' . $_REQUEST['adjustmethod'];
    $tfcreate_options[] = 'maxspacing=' . $_REQUEST['maxspacing'];
    $tfcreate_options[] = 'minspacing=' . $_REQUEST['minspacing'];
    $tfcreate_options[] = 'nofitlimit=' . $_REQUEST['nofitlimit'];
    $tfcreate_options[] = 'shrinklimit=' . $_REQUEST['shrinklimit'];
    $tfcreate_options[] = 'spreadlimit=' . $_REQUEST['spreadlimit'];
    $tfcreate_options[] = 'charspacing=' . $_REQUEST['charspacing'];
    $tffit_options = array('showborder=true');
 public function customerTransactionsPdf(Request $request, $id)
 {
     $transactionRepository = $this->getTransactionRepository();
     $customerRepository = $this->getCustomerRepository();
     $transactions = $transactionRepository->getCustomerTransactions($id);
     $customer = $customerRepository->getCustomerById($id);
     if (is_null($customer)) {
         return JsonErrorResponse::fromKey(JsonErrorResponse::INVALID_CUSTOMER_ID);
     }
     //add customer data
     foreach ($transactions as $trans) {
         $trans->from_customer = $customerRepository->getCustomerById($trans->from_id);
         $trans->to_customer = $customerRepository->getCustomerById($trans->to_id);
     }
     function wrapWithWhitespace($str, $length)
     {
         $neededPadding = $length - strlen($str);
         $front = floor($neededPadding / 2) > 0 ? floor($neededPadding / 2) : 0;
         $back = ceil($neededPadding / 2) > 0 ? ceil($neededPadding / 2) : 0;
         $str = str_repeat(" ", $front) . $str . str_repeat(" ", $back);
         return substr($str, 0, $length);
     }
     try {
         $p = new \PDFlib();
         if ($p->begin_document("", "") == 0) {
             die("Error: " . $p->get_errmsg());
         }
         $p->set_info("Creator", "SitzBank");
         $p->set_info("Author", "SitzBank App");
         $p->set_info("Title", "Transactions for {$customer->firstname} {$customer->lastname}");
         $p->set_parameter("textformat", "utf8");
         $p->begin_page_ext(595, 842, "");
         $font = $p->load_font("Helvetica-Bold", "winansi", "");
         $p->setfont($font, 18.0);
         $p->set_text_pos(25, 780);
         $p->show("Transactions for {$customer->firstname} {$customer->lastname}");
         $font = $p->load_font("Courier", "winansi", "");
         $p->setfont($font, 9.0);
         $p->set_text_pos(20, 750);
         $p->show(str_repeat("-", 100));
         $header = array('Time', 'From', 'To', 'Amount', 'Status');
         $header = array_map(function ($str) {
             return wrapWithWhitespace($str, 19);
         }, $header);
         $p->continue_text(implode('|', $header));
         foreach ($transactions as $trans) {
             $p->continue_text(str_repeat("-", 100));
             $row = array($trans->timestamp, $trans->from_customer->firstname . ' ' . $trans->from_customer->lastname, $trans->to_customer->firstname . ' ' . $trans->to_customer->lastname, $trans->amount, $trans->status);
             $row = array_map(function ($str) {
                 return wrapWithWhitespace($str, 19);
             }, $row);
             $p->continue_text(implode('|', $row));
             $p->continue_text("Description: {$trans->description}");
         }
         $p->continue_text(str_repeat("=", 100));
         $p->continue_text(str_repeat(" ", 100));
         $p->setfont($font, 12.0);
         $p->continue_text("Balance: " . $customerRepository->getCustomerBalance($customer->id));
         $p->end_page_ext("");
         $p->end_document("");
         $buf = $p->get_buffer();
         $len = strlen($buf);
     } catch (\Exception $e) {
         return JsonErrorResponse::fromKey(JsonErrorResponse::UNEXPECTED_ERROR);
     }
     header("Content-type: application/pdf");
     header("Content-Length: {$len}");
     header("Content-Disposition: inline; filename=transactions.pdf");
     return $buf;
 }
Example #12
0
 public function render()
 {
     if (!$this->ops_form) {
         return "No form to render";
     }
     $vn_margin_left_px = $this->getFormSetting('marginLeft');
     $vn_margin_top_px = $this->getFormSetting('marginTop');
     $vn_margin_right_px = $this->getFormSetting('marginRight');
     $vn_margin_bottom_px = $this->getFormSetting('marginBottom');
     $vn_page_width_px = $this->getFormSetting('pageWidth');
     $vn_page_height_px = $this->getFormSetting('pageHeight');
     $vn_subform_width_px = $this->getFormSetting('subFormWidth');
     $vn_subform_height_px = $this->getFormSetting('subFormHeight');
     $vn_subform_hgutter_px = $this->getFormSetting('horizontalGutter');
     $vn_subform_vgutter_px = $this->getFormSetting('verticalGutter');
     $vb_subform_use_border = (bool) $this->getFormSetting('useBorder');
     $vn_subform_border_dash = (int) $this->getFormSetting('borderDash');
     $this->opa_images = array();
     // cache of images loaded into new PDF
     $this->opa_fonts = array();
     // cache of fonts used in new PDF
     if ($this->getPDFLibrary() == __PDF_LIBRARY_ZEND__) {
         $o_pdf = new Zend_Pdf();
         $o_pdf->pages[] = $o_pdf->newPage($vn_page_width_px, $vn_page_height_px);
     } else {
         $o_pdf = new PDFlib();
         $o_pdf->set_parameter("errorpolicy", "return");
         $o_pdf->begin_document("", "openmode=none");
         $o_pdf->begin_page_ext($vn_page_width_px, $vn_page_height_px, "");
     }
     $this->setFont($o_pdf, "Helvetica", 12);
     // default
     // Render page elements
     foreach ($this->opa_form_page_elements as $vs_name => $vo_element) {
         $vo_element->render($o_pdf);
     }
     // Render sub-forms
     //
     $this->renderPageElements($o_pdf, 0);
     $vn_x = $vn_margin_left_px;
     $vn_y = $vn_page_height_px - $vn_margin_top_px;
     $vn_num_subforms = sizeof($this->opo_subforms);
     if ($this->opa_starting_subform > 0) {
         for ($vn_i = 0; $vn_i < $this->opa_starting_subform; $vn_i++) {
             $vn_x += $vn_subform_vgutter_px + $vn_subform_width_px;
             if ($vn_x + $vn_subform_width_px > $vn_page_width_px) {
                 $vn_x = $vn_margin_left_px;
                 $vn_y -= $vn_subform_hgutter_px + $vn_subform_height_px;
                 if ($vn_y - $vn_subform_height_px < $vn_margin_bottom_px && $vn_i < $vn_num_subforms - 1) {
                     # need new page!
                     $vn_x = $vn_margin_left_px;
                     $vn_y = $vn_page_height_px - $vn_margin_top_px;
                 }
             }
         }
     }
     $vn_cur_page = 0;
     for ($vn_i = 0; $vn_i < $vn_num_subforms; $vn_i++) {
         $o_subform = $this->opo_subforms[$vn_i];
         $o_subform->setOutline($vb_subform_use_border ? 1 : 0, $vn_subform_border_dash);
         $o_subform->render($o_pdf, $vn_x, $vn_y);
         $vn_x += $vn_subform_vgutter_px + $vn_subform_width_px;
         if ($vn_x + $vn_subform_width_px > $vn_page_width_px) {
             $vn_x = $vn_margin_left_px;
             $vn_y -= $vn_subform_hgutter_px + $vn_subform_height_px;
             if ($vn_y - $vn_subform_height_px < $vn_margin_bottom_px && $vn_i < $vn_num_subforms - 1) {
                 # need new page!
                 $vn_cur_page++;
                 if ($this->getPDFLibrary() == __PDF_LIBRARY_ZEND__) {
                     $o_pdf->pages[] = $o_pdf->newPage($vn_page_width_px, $vn_page_height_px);
                 } else {
                     $o_pdf->end_page_ext("");
                     $o_pdf->begin_page_ext($vn_page_width_px, $vn_page_height_px, "");
                 }
                 $this->setFont($o_pdf, "Helvetica", 12);
                 // default
                 $this->renderPageElements($o_pdf, $vn_cur_page);
                 $vn_x = $vn_margin_left_px;
                 $vn_y = $vn_page_height_px - $vn_margin_top_px;
             }
         }
     }
     if ($this->getPDFLibrary() == __PDF_LIBRARY_ZEND__) {
         return $o_pdf->render();
     } else {
         $o_pdf->end_page_ext("");
         foreach ($this->opa_images as $vs_path => $vn_image_ref) {
             $o_pdf->close_image($vn_image_ref);
         }
         $o_pdf->end_document("");
         return $o_pdf->get_buffer();
     }
 }
Example #13
0
/**
 * This function creates a PDF with a title, an image and a comment.
 *
 * @param $page_width  	(The page width in dpi. (inches x 72) )
 * @param $page_height  (The page height in dpi. (inches x 72) )
 * @param $title		(The title to insert in the pdf)
 * @param $comments		(The comments to insert in the pdf)
 * @param $mapImageUrl 	(The url to the image to insert in the pdf)
 */
function createPDF($page_width, $page_height, $title, $comments, $mapImageUrl)
{
    $p = new PDFlib();
    /*  open new PDF file; insert a file name to create the PDF on disk */
    if ($p->begin_document($mapImageUrl . ".pdf", "") == 0) {
        die("Error: " . $p->get_errmsg());
    }
    // These lines should set the PDF properties, but it does not seem to work.
    $p->set_info("Creator", "Vigilance");
    $p->set_info("Author", "Vigilance");
    $p->set_info("Title", $title);
    // Create a new PDF page.
    $p->begin_page_ext($page_width, $page_height, "");
    // Loads the Helvetica font.
    $font = $p->load_font("Helvetica", "winansi", "");
    $p->setfont($font, 20.0);
    // Displays the title as set by the user
    // On ne peut pas dire a pdflib de centrer le texte sur la ligne... donc $page_width / 2 - 20;
    $p->set_text_pos($page_width / 2 - 20, $page_height - 30);
    $p->show($title);
    // Adds the image to the PDF.
    $image = $p->load_image("auto", $mapImageUrl, "");
    $p->fit_image($image, 30, 80, "");
    $p->close_image($image);
    // Adds the comments to the PDF.
    $p->set_text_pos(10, 60);
    $p->setfont($font, 12.0);
    $p->continue_text($comments);
    // Ends the page and the document.
    $p->end_page_ext("");
    $p->end_document("");
}
Example #14
0
<?php

try {
    $p = new PDFlib();
    /* öffnet eine neue PDF-Datei; fügen Sie einen Dateinamen ein,
       um das PDF auf der Platte zu speichern */
    if ($p->begin_document("", "") == 0) {
        die("Error: " . $p->get_errmsg());
    }
    $p->set_info("Creator", "hallo.php");
    $p->set_info("Author", "Rainer Schaaf");
    $p->set_info("Title", "Hallo Welt (PHP)!");
    $p->begin_page_ext(595, 842, "");
    $font = $p->load_font("Helvetica-Bold", "winansi", "");
    $p->setfont($font, 24.0);
    $p->set_text_pos(50, 700);
    $p->show("Hallo Welt!");
    $p->continue_text("(sagt PHP)");
    $p->end_page_ext("");
    $p->end_document("");
    $buf = $p->get_buffer();
    $len = strlen($buf);
    header("Content-type: application/pdf");
    header("Content-Length: {$len}");
    header("Content-Disposition: inline; filename=hallo.pdf");
    print $buf;
} catch (PDFlibException $e) {
    die("Eine PDFlib-Exception ist aufgetreten im hallo-Schnipsel:\n" . "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n");
} catch (Exception $e) {
    die($e);
}
 /**
  * Returns the CFD as PDF
  *
  * @param array $data the CFD array
  * @param boolean $print_headers if set true, it prints the PDF directly
  * @return mixed
  */
 public static function getPDF(array &$data, $print_headers = false)
 {
     try {
         $p = new PDFlib();
         $p->set_parameter("errorpolicy", "return");
         if ($p->begin_document("", "") == 0) {
             die("Error: " . $p->get_errmsg());
         }
         $p->set_info("Creator", "SimpleCFD.php");
         $p->set_info("Author", self::encText($data['Emisor']['nombre']));
         $p->set_info("Title", "Factura No. " . $data['folio']);
         $p->set_info("Subject", "Factura emitada a " . self::encText($data['Receptor']['nombre']) . " el " . $data['fecha']);
         // set letter size
         $p->begin_page_ext(612, 792, "");
         $font = $p->load_font("Helvetica-Bold", "iso8859-1", "");
         $p->setfont($font, 12);
         $p->fit_textline("Factura", 30, 750, "fontsize=16 position=left");
         // Serie
         if (isset($data['serie'])) {
             $p->fit_textline("Serie: ", 120, 765, "fontsize=8 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={25 10}");
             $p->fit_textline($data['serie'], 145, 765, "fontsize=8 " . "position={bottom left} boxsize={60 10}");
         }
         // Folio
         $p->fit_textline("Folio: ", 120, 750, "fontsize=8 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={25 10}");
         $p->fit_textline($data['folio'], 145, 750, "fontsize=8 " . "position={bottom left} boxsize={90 10}");
         // AnoAprobacion
         $p->fit_textline(self::encText("Año de Aprobación: "), 250, 765, "fontsize=8 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={80 10}");
         $p->fit_textline($data['anoAprobacion'], 330, 765, "fontsize=8 " . "position={bottom left} boxsize={20 10}");
         // NoAprobacion
         $p->fit_textline(self::encText("Número de Aprobación: "), 250, 750, "fontsize=8 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={95 10}");
         $p->fit_textline($data['noAprobacion'], 345, 750, "fontsize=8 " . "position={bottom left} boxsize={65 10}");
         // Fecha
         $p->fit_textline("Fecha:", 425, 750, "fontsize=8 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={30 10}");
         $p->fit_textline($data['fecha'], 455, 750, "fontsize=8 " . "position={bottom left} boxsize={80 10}");
         // line
         $p->moveto(30, 740);
         $p->lineto(580, 740);
         $p->stroke();
         $p->setlinewidth(0.5);
         // Emisor
         $p->fit_textline("Emisor", 30, 720, "fontsize=10 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={200 20}");
         $p->fit_textline(self::encText($data['Emisor']['nombre']), 30, 695, "fontsize=18 " . "position={bottom left} boxsize={270 20}");
         $p->fit_textline("RFC: " . $data['Emisor']['rfc'], 30, 675, "fontsize=14 " . "position={bottom left} boxsize={270 15}");
         $domicilio = self::encText($data['DomicilioFiscal']['calle']) . " No. " . $data['DomicilioFiscal']['noExterior'];
         $domicilio .= isset($data['DomicilioFiscal']['noInterior']) ? " - " . $data['DomicilioFiscal']['noInterior'] : '';
         $p->fit_textline(self::encText($domicilio), 30, 660, "fontsize=12 " . "position={bottom left} boxsize={270 10}");
         unset($domicilio);
         $p->fit_textline(self::encText($data['DomicilioFiscal']['colonia']), 30, 645, "fontsize=12 " . "position={bottom left} boxsize={270 10}");
         $p->fit_textline(self::encText($data['DomicilioFiscal']['municipio']), 30, 630, "fontsize=12 " . "position={bottom left} boxsize={270 10}");
         $p->fit_textline("C.P. " . $data['DomicilioFiscal']['codigoPostal'], 30, 615, "fontsize=12 " . "position={bottom left} boxsize={270 10}");
         $p->fit_textline(self::encText($data['DomicilioFiscal']['estado']), 30, 600, "fontsize=12 " . "position={bottom left} boxsize={270 10}");
         // Receptor
         $p->fit_textline("Receptor", 380, 720, "fontsize=10 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom right} boxsize={200 20}");
         $p->fit_textline(self::encText($data['Receptor']['nombre']), 310, 695, "fontsize=18 " . "position={bottom right} boxsize={270 20}");
         $p->fit_textline("RFC: " . $data['Receptor']['rfc'], 310, 675, "fontsize=14 " . "position={bottom right} boxsize={270 15}");
         $domicilio = self::encText($data['Domicilio']['calle']) . " No. " . $data['Domicilio']['noExterior'];
         $domicilio .= isset($data['Domicilio']['noInterior']) ? " - " . $data['Domicilio']['noInterior'] : '';
         $p->fit_textline($domicilio, 310, 660, "fontsize=12 " . "position={bottom right} boxsize={270 10}");
         unset($domicilio);
         $p->fit_textline(self::encText($data['Domicilio']['colonia']), 310, 645, "fontsize=12 " . "position={bottom right} boxsize={270 10}");
         $p->fit_textline(self::encText($data['Domicilio']['municipio']), 310, 630, "fontsize=12 " . "position={bottom right} boxsize={270 10}");
         $p->fit_textline("C.P. " . $data['Domicilio']['codigoPostal'], 310, 615, "fontsize=12 " . "position={bottom right} boxsize={270 10}");
         $p->fit_textline(self::encText($data['Domicilio']['estado']), 310, 600, "fontsize=12 " . "position={bottom right} boxsize={270 10}");
         // line
         $p->moveto(30, 585);
         $p->lineto(580, 585);
         $p->stroke();
         // Concepto
         // Cantidad
         $p->fit_textline("Cantidad", 30, 565, "fontsize=11 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={50 10}");
         // Descripcion
         $p->fit_textline(self::encText("Descripción"), 100, 565, "fontsize=11 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={65 10}");
         // Precio
         $p->fit_textline("Precio", 483, 565, "fontsize=11 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={35 10}");
         // Importe
         $p->fit_textline("Importe", 540, 565, "fontsize=11 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={40 10}");
         // line
         $p->moveto(30, 555);
         $p->lineto(580, 555);
         $p->stroke();
         $count = count($data['Concepto']);
         static $pos = 552;
         for ($i = 0; $i < $count; ++$i) {
             $pos -= 20;
             // Cantidad
             $p->fit_textline($data['Concepto'][$i]['cantidad'], 30, $pos, "fontsize=9 " . "position={bottom left} boxsize={145 10}");
             // Descripcion
             $p->fit_textline($data['Concepto'][$i]['descripcion'], 100, $pos, "fontsize=9 " . "position={bottom left} boxsize={145 10}");
             // Valor unitario
             $p->fit_textline($data['Concepto'][$i]['valorUnitario'], 483, $pos, "fontsize=9 " . "position={bottom left} boxsize={145 10}");
             // Importe
             $p->fit_textline($data['Concepto'][$i]['importe'], 435, $pos, "fontsize=9 " . "position={bottom right} boxsize={145 10}");
         }
         // line cantidad
         $p->moveto(90, 580);
         $p->lineto(90, $pos - 10);
         $p->stroke();
         // line descripcion
         $p->moveto(470, 580);
         $p->lineto(470, $pos - 10);
         $p->stroke();
         // line
         $p->moveto(30, $pos - 20);
         $p->lineto(580, $pos - 20);
         $p->stroke();
         // Subtotal
         $pos -= 40;
         $p->fit_textline("SubTotal", 375, $pos, "fontsize=9 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom right} boxsize={145 10}");
         $p->fit_textline($data['subTotal'], 435, $pos, "fontsize=9 " . "position={bottom right} boxsize={145 10}");
         // Traslado
         if (isset($data['Traslado'])) {
             $count = count($data['Traslado']);
             for ($i = 0; $i < $count; ++$i) {
                 $pos -= 20;
                 $p->fit_textline($data['Traslado'][$i]['impuesto'], 375, $pos, "fontsize=9 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom right} boxsize={145 10}");
                 $p->fit_textline(" (Tasa: " . $data['Traslado'][$i]['tasa'] . "%)", 357, $pos + 1, "fontsize=6 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom right} boxsize={145 10}");
                 $p->fit_textline($data['Traslado'][$i]['importe'], 435, $pos, "fontsize=9 " . "position={bottom right} boxsize={145 10}");
             }
         }
         // Retencion
         if (isset($data['Retencion'])) {
             $count = count($data['Retencion']);
             for ($i = 0; $i < $count; ++$i) {
                 $pos -= 20;
                 $p->fit_textline(self::encText("Retención ") . $data['Retencion'][$i]['impuesto'], 375, $pos, "fontsize=9 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom right} boxsize={145 10}");
                 $p->fit_textline($data['Retencion'][$i]['importe'], 435, $pos, "fontsize=9 " . "position={bottom right} boxsize={145 10}");
             }
         }
         // Total
         $pos -= 20;
         $p->fit_textline("Total", 375, $pos, "fontsize=9 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom right} boxsize={145 10}");
         $p->fit_textline($data['total'], 435, $pos, "fontsize=9 " . "position={bottom right} boxsize={145 10}");
         // line importe
         $pos -= 10;
         $p->moveto(530, 580);
         $p->lineto(530, $pos);
         $p->stroke();
         // line
         $pos -= 10;
         $p->moveto(30, $pos);
         $p->lineto(580, $pos);
         $p->stroke();
         // noCertificado
         $pos -= 20;
         $p->fit_textline(self::encText("Número de Serie del Certificado:"), 30, $pos, "fontsize=9 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={145 10}");
         $p->fit_textline(self::encText($data['noCertificado']), 175, $pos, "fontsize=9 position={bottom left} boxsize={100 10}");
         // cadenaOriginal
         $p->fit_textline("Cadena original:", 30, $pos - 20, "fontsize=9 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={75 10}");
         $cad = explode(":::", wordwrap(self::encText($data['cadenaOriginal']), 150, ":::", true));
         $count = count($cad);
         $position_cad = $pos - 20;
         for ($i = 0; $i < $count; ++$i) {
             $position_cad -= 10;
             $p->fit_textline($cad[$i], 30, $position_cad, "fontsize=7 position={bottom left} boxsize={550 10}");
         }
         unset($count);
         // sello
         $position_cer = $position_cad - 20;
         $p->fit_textline("Sello Digital:", 30, $position_cer, "fontsize=9 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={60 10}");
         $cer = explode(":::", wordwrap($data['sello'], 115, ":::", true));
         $count = count($cer);
         $position = $position_cer;
         for ($i = 0; $i < $count; ++$i) {
             $position -= 10;
             $p->fit_textline(self::encText($cer[$i]), 30, $position, "fontsize=7 position={bottom left} boxsize={550 10}");
         }
         unset($count);
         unset($cer);
         // note CFD
         $p->fit_textline(self::encText("Este documento es una impresión de un " . "Comprobante Fiscal Digital "), 150, $position - 30, "fontsize=10 " . "position={bottom left} boxsize={320 10}");
         $p->end_page_ext("");
         $p->end_document("");
         $buf = $p->get_buffer();
         unset($p);
         if ($print_headers) {
             $len = strlen($buf);
             header("Content-type: application/pdf");
             header("Content-Length: {$len}");
             header("Content-Disposition: inline; filename=hello.pdf");
             echo $buf;
             exit;
         }
         return $buf;
     } catch (PDFlibException $e) {
         die("PDFlib exception occurred in Factura:\n" . "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n");
     } catch (Exception $e) {
         die($e);
     }
 }
Example #16
0
 static function &pdflib($fileName, $searchPath, &$values, $numPages = 1, $echo = true, $output = 'College_Match_App', $creator = 'CiviCRM', $author = 'http://www.civicrm.org/', $title = '2006 College Match Scholarship Application')
 {
     try {
         $pdf = new PDFlib();
         $pdf->set_parameter("compatibility", "1.6");
         $pdf->set_parameter("licensefile", "/home/paras/bin/license/pdflib.txt");
         if ($pdf->begin_document('', '') == 0) {
             CRM_Core_Error::statusBounce("PDFlib Error: " . $pdf->get_errmsg());
         }
         $config =& CRM_Core_Config::singleton();
         $pdf->set_parameter('resourcefile', $config->templateDir . '/Quest/pdf/pdflib.upr');
         $pdf->set_parameter('textformat', 'utf8');
         /* Set the search path for fonts and PDF files */
         $pdf->set_parameter('SearchPath', $searchPath);
         /* This line is required to avoid problems on Japanese systems */
         $pdf->set_parameter('hypertextencoding', 'winansi');
         $pdf->set_info('Creator', $creator);
         $pdf->set_info('Author', $author);
         $pdf->set_info('Title', $title);
         $blockContainer = $pdf->open_pdi($fileName, '', 0);
         if ($blockContainer == 0) {
             CRM_Core_Error::statusBounce('PDFlib Error: ' . $pdf->get_errmsg());
         }
         for ($i = 1; $i <= $numPages; $i++) {
             $page = $pdf->open_pdi_page($blockContainer, $i, '');
             if ($page == 0) {
                 CRM_Core_Error::statusBounce('PDFlib Error: ' . $pdf->get_errmsg());
             }
             $pdf->begin_page_ext(20, 20, '');
             /* dummy page size */
             /* This will adjust the page size to the block container's size. */
             $pdf->fit_pdi_page($page, 0, 0, 'adjustpage');
             $status = array();
             /* Fill all text blocks with dynamic data */
             foreach ($values as $key => $value) {
                 if (is_array($value)) {
                     continue;
                 }
                 // pdflib does like the forward slash character, hence convert
                 $value = str_replace('/', '_', $value);
                 $res = $pdf->fill_textblock($page, $key, $value, 'embedding encoding=winansi');
                 /**
                                     if ( $res == 0 ) {
                                         CRM_Core_Error::debug( "$key, $value: $res", $pdf->get_errmsg( ) );
                                     } else {
                                         CRM_Core_Error::debug( "SUCCESS: $key, $value", null );
                                     }
                                     **/
             }
             $pdf->end_page_ext('');
             $pdf->close_pdi_page($page);
         }
         $pdf->end_document('');
         $pdf->close_pdi($blockContainer);
         $buf = $pdf->get_buffer();
         $len = strlen($buf);
         if ($echo) {
             header('Content-type: application/pdf');
             header("Content-Length: {$len}");
             header("Content-Disposition: inline; filename={$output}.pdf");
             echo $buf;
             exit;
         } else {
             return $buf;
         }
     } catch (PDFlibException $excp) {
         CRM_Core_Error::statusBounce('PDFlib Error: Exception' . "[" . $excp->get_errnum() . "] " . $excp->get_apiname() . ": " . $excp->get_errmsg());
     } catch (Exception $excp) {
         CRM_Core_Error::statusBounce("PDFlib Error: " . $excp->get_errmsg());
     }
 }
Example #17
0
 function generate_document()
 {
     $settings = Settings::get($this->user['database'])->toArray();
     if (!isset($_POST['link'])) {
         die;
     }
     $host = "http://" . $settings['aws_host_url'] . '/';
     if (substr($_POST['link'], 0, 5) == 'EZPRO') {
         $prefix = "EZPRO";
     } else {
         $prefix = "DTMS";
     }
     // Instantiate S3 Client
     $S3Client = S3Client::factory(array('key' => $settings['aws_access_key_id'], 'secret' => $settings['aws_secret_access_key']));
     switch ($prefix) {
         case "EZPRO":
             $year = substr($_POST['link'], 5, 4);
             $month = substr($_POST['link'], 9, 2);
             $search = "EZPRO" . $year . $month;
             $result = $S3Client->listObjects(array('Bucket' => $settings['aws_bucket'], 'MaxKeys' => 1, 'Prefix' => "EZPRO/POD/" . $year . "/" . $month . str_replace($search, '/', $_POST['link'])));
             break;
         default:
             $year = substr($_POST['link'], 5, 4);
             $month = substr($_POST['link'], 10, 2);
             $search = "DTMS_" . $year . "_" . $month . "_";
             $result = $S3Client->listObjects(array('Bucket' => $settings['aws_bucket'], 'MaxKeys' => 1, 'Prefix' => "DTMS/" . $year . "/" . $month . str_replace($search, '/', $_POST['link']) . "."));
             break;
     }
     if (isset($result['Contents'])) {
         $link = $host . $result['Contents'][0]['Key'];
     } else {
         die;
     }
     echo $link;
     $data = file_get_contents($link);
     $pdf = new PDFlib();
     $pdf->begin_document("", "");
     for ($frame = 1;; $frame++) {
         $pdf->create_pvf("/tracking/pvf/image", $data, "");
         $bol = $pdf->load_image("auto", "/tracking/pvf/image", "page=" . $frame);
         if ($bol == 0) {
             break;
         }
         $imagewidth = $pdf->get_value("imagewidth", $bol) * 72 / $pdf->get_value("resx", $bol);
         $imageheight = $pdf->get_value("imageheight", $bol) * 72 / $pdf->get_value("resy", $bol);
         $pdf->begin_page_ext($imagewidth, $imageheight, "");
         $pdf->fit_image($bol, 0, 0, "");
         $pdf->end_page_ext("");
         $pdf->delete_pvf("/tracking/pvf/image");
     }
     $pdf->end_document("");
     $buf = $pdf->get_buffer();
     print $buf;
 }