Beispiel #1
1
 protected function qrcode()
 {
     $qr = new \QRcode($this->entity->getUrl(), 'L');
     $qr->disableBorder();
     $w = 17;
     $x = $this->xPos + self::$WIDTH - 1 - $w;
     $y = $this->yPos + self::$HEIGHT - 3 - $w;
     $qr->displayFPDF($this->pdf, $x, $y, $w);
 }
Beispiel #2
0
<?php

exit;
$msg = isset($_GET['msg']) ? $_GET['msg'] : '';
if (!$msg) {
    $msg = "Le site du spipu\r\nhttp://spipu.net/";
}
$err = isset($_GET['err']) ? $_GET['err'] : '';
if (!in_array($err, array('L', 'M', 'Q', 'H'))) {
    $err = 'L';
}
require_once 'qrcode.class.php';
$qrcode = new QRcode(utf8_encode($msg), $err);
$qrcode->disableBorder();
$qrcode->displayPNG(200);
Beispiel #3
0
        /**
         * balise : QRCODE
         * mode : OUVERTURE
         * 
         * @param	array	paramètres de l'élément de parsing
         * @return	null
         */
        function o_QRCODE($param)
        {
            if ($this->testIsDeprecated && (isset($param['size']) || isset($param['noborder']))) {
                HTML2PDF::makeError(9, __FILE__, __LINE__, array('QRCODE', 'size, noborder'));
            }
            $msg = '
<h1>QRCODE Tag</h1>
<pre>
	<b>ATTENTION :</b> 
		Vous devez télécharger la librairie "QR-code generator >=0.99" (sous licence LGPL)
 		a cette adresse : <a href="http://prgm.spipu.net/php_qrcode" target="_blank">http://prgm.spipu.net/php_qrcode</a>
 		et mettre tout son contenu dans ce repertoire : ' . str_replace('\\', '/', dirname(__FILE__)) . '/qrcode
 		
 	<b>WARNING:</b> 
 		You have to download the librairy "QR-code generator >=0.99" (under LGPL licence)
 		at this url : <a href="http://prgm.spipu.net/php_qrcode" target="_blank">http://prgm.spipu.net/php_qrcode</a>
 		and to put all his contents in this folder ' . str_replace('\\', '/', dirname(__FILE__)) . '/qrcode
 </pre>';
            $file_class = dirname(__FILE__) . '/qrcode/qrcode.class.php';
            if (!is_file($file_class)) {
                echo $msg;
                exit;
            }
            require_once $file_class;
            if (__CLASS_QRCODE__ < '0.99') {
                echo $msg;
                exit;
            }
            if ($this->DEBUG_actif) {
                $this->DEBUG_add('QRCODE', true);
            }
            if (!isset($param['value'])) {
                $param['value'] = '';
            }
            if (!isset($param['ec'])) {
                $param['ec'] = 'H';
            }
            if (!isset($param['style']['color'])) {
                $param['style']['color'] = '#000000';
            }
            if (!isset($param['style']['background-color'])) {
                $param['style']['background-color'] = '#FFFFFF';
            }
            if (isset($param['style']['border'])) {
                $borders = $param['style']['border'] != 'none';
                unset($param['style']['border']);
            } else {
                $borders = true;
            }
            if ($param['value'] === '') {
                return true;
            }
            if (!in_array($param['ec'], array('L', 'M', 'Q', 'H'))) {
                $param['ec'] = 'H';
            }
            $this->style->save();
            $this->style->analyse('qrcode', $param);
            $this->style->setPosition();
            $this->style->FontSet();
            $x = $this->pdf->getX();
            $y = $this->pdf->getY();
            $w = $this->style->value['width'];
            $h = $this->style->value['height'];
            $size = max($w, $h);
            if (!$size) {
                $size = $this->style->ConvertToMM('50mm');
            }
            $color = $this->style->value['color'];
            if (count($color) == 4) {
                $color = array(0, 0, 0);
            }
            $color[0] = floor($color[0] * 255.0);
            $color[1] = floor($color[1] * 255.0);
            $color[2] = floor($color[2] * 255.0);
            $background = $this->style->value['background']['color'];
            if (count($background) == 4) {
                $background = array(0, 0, 0);
            }
            $background[0] = floor($background[0] * 255.0);
            $background[1] = floor($background[1] * 255.0);
            $background[2] = floor($background[2] * 255.0);
            if (!$this->sub_part && !$this->isSubPart) {
                $qrcode = new QRcode($param['value'], $param['ec']);
                if (!$borders) {
                    $qrcode->disableBorder();
                }
                $qrcode->displayFPDF($this->pdf, $x, $y, $size, $background, $color);
                unset($qrcode);
            }
            // position maximale globale
            $this->maxX = max($this->maxX, $x + $size);
            $this->maxY = max($this->maxY, $y + $size);
            $this->maxH = max($this->maxH, $size);
            $this->pdf->setX($x + $size);
            $this->style->load();
            $this->style->FontSet();
            return true;
        }
 /**
  * Generate and save or stream a PDF file for this product voucher
  *
  * @since 1.0
  * @param string $path optional absolute path to the voucher directory, if
  *        not supplied the PDF will be streamed as a downloadable file (used
  *        for admin previewing of the PDF)
  *
  * @return mixed nothing if a $path is supplied, otherwise a PDF download
  * @throws Exception if the voucher image is not available
  */
 public function generate_pdf($path = '')
 {
     // include the pdf library
     define('FPDF_FONTPATH', wc_pdf_product_vouchers()->get_plugin_path() . '/lib/fpdf/font');
     require_once wc_pdf_product_vouchers()->get_plugin_path() . '/lib/fpdf/fpdf.php';
     $upload_dir = wp_upload_dir();
     $image = wp_get_attachment_metadata($this->get_image_id());
     // make sure the image hasn't been deleted through the media editor
     if (!$image) {
         throw new Exception(__("Voucher image not found", WC_PDF_Product_Vouchers::TEXT_DOMAIN));
     }
     // make sure the file exists and is readable
     if (!is_readable($upload_dir['basedir'] . '/' . $image['file'])) {
         throw new Exception(sprintf(__("Voucher image file missing or not readable: %s", WC_PDF_Product_Vouchers::TEXT_DOMAIN), $upload_dir['basedir'] . '/' . $image['file']));
     }
     // determine orientation: landscape or portrait
     if ($image['width'] > $image['height']) {
         $orientation = 'L';
     } else {
         $orientation = "P";
     }
     // get the width and height in points
     $width_pt = $this->convert_pixels_to_points($image['width']);
     $height_pt = $this->convert_pixels_to_points($image['height']);
     // Create the pdf
     // When writing text to a Cell, the text is vertically-aligned in the middle
     $fpdf = new FPDF($orientation, 'pt', array($width_pt, $height_pt));
     $fpdf->AddPage();
     $fpdf->SetAutoPageBreak(false);
     // set the voucher image
     $fpdf->Image($upload_dir['basedir'] . '/' . $image['file'], 0, 0, $width_pt, $height_pt);
     // this is useful for displaying the text cell borders when debugging the PDF layout,
     //  though keep in mind that we translate the box position to align the text to bottom
     //  edge of what the user selected, so if you want to see the originally selected box,
     //  display that prior to the translation
     $show_border = 0;
     foreach ($this->voucher_fields as $field_name => $field) {
         switch ($field_name) {
             case 'message':
                 // voucher message text, this is multi-line, so it's handled specially
                 $this->textarea_field($fpdf, 'message', $this->get_message(), $show_border, isset($field['text_align']) && $field['text_align'] ? $field['text_align'] : $this->voucher_text_align);
                 break;
             case 'product_name':
                 // product name (allow optional wrapping)
                 if (apply_filters('wc_pdf_product_vouchers_product_name_multi_line', false, $this)) {
                     $this->textarea_field($fpdf, 'product_name', strtoupper($this->get_product_name()), $show_border, isset($field['text_align']) && $field['text_align'] ? $field['text_align'] : $this->voucher_text_align);
                 } else {
                     $this->text_field($fpdf, 'product_name', strtoupper($this->get_product_name()), $show_border, isset($field['text_align']) && $field['text_align'] ? $field['text_align'] : $this->voucher_text_align);
                 }
                 break;
             case 'product_sku':
                 // product sku
                 $this->text_field($fpdf, 'product_sku', $this->get_product_sku(), $show_border, isset($field['text_align']) && $field['text_align'] ? $field['text_align'] : $this->voucher_text_align);
                 break;
             case 'recipient_name':
                 // recepient name
                 $this->text_field($fpdf, 'recipient_name', $this->get_recipient_name(), $show_border, isset($field['text_align']) && $field['text_align'] ? $field['text_align'] : $this->voucher_text_align);
                 break;
             case 'recipient_email':
                 // recepient email
                 $this->text_field($fpdf, 'recipient_email', $this->get_recipient_email(), $show_border, isset($field['text_align']) && $field['text_align'] ? $field['text_align'] : $this->voucher_text_align);
                 break;
             case 'expiration_date':
                 // expiry date
                 $this->text_field($fpdf, 'expiration_date', $this->get_formatted_expiration_date(), $show_border, isset($field['text_align']) && $field['text_align'] ? $field['text_align'] : $this->voucher_text_align);
                 break;
             case 'voucher_number':
                 // voucher number
                 $this->text_field($fpdf, 'voucher_number', $this->get_voucher_number(), $show_border, isset($field['text_align']) && $field['text_align'] ? $field['text_align'] : $this->voucher_text_align);
                 break;
             case 'voucher_product_price':
                 // voucher number
                 $this->text_field($fpdf, 'voucher_product_price', $this->wc_price($this->get_product_price()), $show_border, isset($field['text_align']) && $field['text_align'] ? $field['text_align'] : $this->voucher_text_align);
                 break;
             case 'qr-code':
             case 'qrcode':
             case 'qr':
                 // Voucher QR-code
                 require_once wc_pdf_product_vouchers()->get_plugin_path() . '/lib/fpdf/qrcode/qrcode.class.php';
                 $qrcode = new QRcode(str_replace("{X}", $this->get_voucher_number(), $this->voucher_fields[strtolower($this->{$field_name})]["label"]), 'L');
                 // error level : L, M, Q, H
                 $qrcode->disableBorder();
                 //header("Content-type: text/plain");
                 //print_r($this->voucher_fields[strtolower($this->$field_name)]["position"]["color"]);
                 //exit();
                 //$qrcode->displayPNG();
                 //exit();
                 $qrcode->displayFPDF($fpdf, $this->voucher_fields[strtolower($this->{$field_name})]["position"]["x"], $this->voucher_fields[strtolower($this->{$field_name})]["position"]["y"], $this->voucher_fields[strtolower($this->{$field_name})]["position"]["width"], $this->voucher_fields[strtolower($this->{$field_name})]["position"]["background"], $this->voucher_fields[strtolower($this->{$field_name})]["position"]["color"]);
                 break;
             default:
                 //header("Content-type: text/plain");
                 //print $this->$field_name . ":\n";
                 //print_r($this->voucher_fields);
                 //print "\n\n";
                 //exit();
                 // TODO: allowing custom fields in this manner could lead to name clashes if they use a reserved field name.  have to deal with that later
                 if (isset($field['multiline']) && $field['multiline']) {
                     $this->textarea_field($fpdf, $field_name, apply_filters('wc_pdf_product_vouchers_voucher_field_value', $this->voucher_fields[strtolower($this->{$field_name})]["label"], $this, $field_name, $field), $show_border, isset($field['text_align']) ? $field['text_align'] : $this->voucher_text_align);
                 } else {
                     $this->text_field($fpdf, $field_name, apply_filters('wc_pdf_product_vouchers_voucher_field_value', $this->voucher_fields[strtolower($this->{$field_name})]["label"], $this, $field_name, $field), $show_border, isset($field['text_align']) ? $field['text_align'] : $this->voucher_text_align);
                 }
                 break;
         }
     }
     // has additional pages?
     foreach ($this->additional_image_ids as $additional_image_id) {
         $fpdf->AddPage();
         $additional_image = wp_get_attachment_metadata($additional_image_id);
         $fpdf->Image($upload_dir['basedir'] . '/' . $additional_image['file'], 0, 0, $this->convert_pixels_to_points($additional_image['width'] < $image['width'] ? $additional_image['width'] : $image['width']), $this->convert_pixels_to_points($additional_image['height'] < $image['height'] ? $additional_image['height'] : $image['height']));
     }
     if ($path) {
         // save the pdf as a file
         $fpdf->Output($this->get_voucher_full_filename($path), 'F');
     } else {
         // download file
         $fpdf->Output('voucher-preview-' . $this->id . '.pdf', 'I');
     }
 }
Beispiel #5
0
 /**
  * balise : QRCODE
  * mode : OUVERTURE
  * 
  * @param	array	paramètres de l'élément de parsing
  * @return	null
  */
 protected function o_QRCODE($param)
 {
     if ($this->DEBUG_actif) {
         $this->DEBUG_add('QRCODE', true);
     }
     if (!isset($param['value'])) {
         $param['value'] = '';
     }
     if (!isset($param['ec'])) {
         $param['ec'] = 'H';
     }
     if (!isset($param['size'])) {
         $param['size'] = '0.6mm';
     }
     if (!isset($param['style']['color'])) {
         $param['style']['color'] = '#000000';
     }
     if (!isset($param['style']['background-color'])) {
         $param['style']['background-color'] = '#FFFFFF';
     }
     if ($param['value'] === '') {
         return true;
     }
     $noborder = isset($param['noborder']);
     $this->style->save();
     $this->style->analyse('qrcode', $param);
     $this->style->setPosition();
     $this->style->FontSet();
     $x = $this->pdf->getX();
     $y = $this->pdf->getY();
     $s = $this->style->ConvertToMM($param['size']);
     $ec = $param['ec'];
     if (!in_array($ec, array('L', 'M', 'Q', 'H'))) {
         $ec = 'H';
     }
     require_once dirname(__FILE__) . '/qrcode/qrcode.class.php';
     $qrcode = new QRcode($param['value'], $ec);
     if ($noborder) {
         $qrcode->disableBorder();
     }
     if (!$this->sub_part && !$this->isSubPart) {
         $qrcode->displayTCPDF($this->pdf, $x, $y, $s, $this->style->value['background']['color'], $this->style->value['color']);
     }
     $size = $s * $qrcode->getQrSize();
     unset($qrcode);
     // position maximale globale
     $this->maxX = max($this->maxX, $x + $size);
     $this->maxY = max($this->maxY, $y + $size);
     $this->maxH = max($this->maxH, $size);
     $this->pdf->setX($x + $size);
     $this->style->load();
     $this->style->FontSet();
     return true;
 }