예제 #1
0
 /**
  * Generates and outputs label-formatted PDF version of search results using DOMPDF
  */
 protected function _genLabels($po_result, $ps_label_code, $ps_output_filename, $ps_title = null)
 {
     if ((bool) $this->request->config->get('use_legacy_print_labels_generator')) {
         return $this->_genLabelsLegacy($po_result, $ps_label_code, $ps_output_filename, $ps_title);
     }
     $vs_border = (bool) $this->request->config->get('add_print_label_borders') ? "border: 1px dotted #000000; " : "";
     //
     // PDF output
     //
     $va_template_info = caGetPrintTemplateDetails('labels', substr($ps_label_code, 5));
     if (!is_array($va_template_info)) {
         $this->postError(3110, _t("Could not find view for PDF"), "BaseFindController->_genPDF()");
         return;
     }
     try {
         $this->view->setVar('title', $ps_title);
         $this->view->setVar('base_path', $vs_base_path = pathinfo($va_template_info['path'], PATHINFO_DIRNAME));
         $this->view->addViewPath(array($vs_base_path, "{$vs_base_path}/local"));
         $vs_content = $this->render("pdfStart.php");
         // render labels
         $vn_width = caConvertMeasurementToPoints(caGetOption('labelWidth', $va_template_info, null));
         $vn_height = caConvertMeasurementToPoints(caGetOption('labelHeight', $va_template_info, null));
         $vn_top_margin = caConvertMeasurementToPoints(caGetOption('marginTop', $va_template_info, null));
         $vn_bottom_margin = caConvertMeasurementToPoints(caGetOption('marginBottom', $va_template_info, null));
         $vn_left_margin = caConvertMeasurementToPoints(caGetOption('marginLeft', $va_template_info, null));
         $vn_right_margin = caConvertMeasurementToPoints(caGetOption('marginRight', $va_template_info, null));
         $vn_horizontal_gutter = caConvertMeasurementToPoints(caGetOption('horizontalGutter', $va_template_info, null));
         $vn_vertical_gutter = caConvertMeasurementToPoints(caGetOption('verticalGutter', $va_template_info, null));
         $va_page_size = CPDF_Adapter::$PAPER_SIZES[caGetOption('pageSize', $va_template_info, null)];
         $vn_page_width = $va_page_size[2] - $va_page_size[0];
         $vn_page_height = $va_page_size[3] - $va_page_size[1];
         $vn_label_count = 0;
         $vn_left = $vn_left_margin;
         $vn_top = $vn_top_margin;
         $va_defined_vars = array_keys($this->view->getAllVars());
         // get list defined vars (we don't want to copy over them)
         $va_tag_list = $this->getTagListForView($va_template_info['path']);
         // get list of tags in view
         $va_barcode_files_to_delete = array();
         while ($po_result->nextHit()) {
             $va_barcode_files_to_delete += caDoPrintViewTagSubstitution($this->view, $po_result, $va_template_info['path'], array('checkAccess' => $this->opa_access_values));
             $vs_content .= "<div style=\"{$vs_border} position: absolute; width: {$vn_width}px; height: {$vn_height}px; left: {$vn_left}px; top: {$vn_top}px; overflow: hidden;\">";
             $vs_content .= $this->render($va_template_info['path']);
             $vs_content .= "</div>\n";
             $vn_label_count++;
             $vn_left += $vn_vertical_gutter + $vn_width;
             if ($vn_left + $vn_width > $vn_page_width) {
                 $vn_left = $vn_left_margin;
                 $vn_top += $vn_horizontal_gutter + $vn_height;
             }
             if ($vn_top + $vn_height > $vn_page_height) {
                 // next page
                 if ($vn_label_count < $po_result->numHits()) {
                     $vs_content .= "<div class=\"pageBreak\">&nbsp;</div>\n";
                 }
                 $vn_left = $vn_left_margin;
                 $vn_top = $vn_top_margin;
             }
         }
         $vs_content .= $this->render("pdfEnd.php");
         $o_dompdf = new DOMPDF();
         $o_dompdf->load_html($vs_content);
         $o_dompdf->set_paper(caGetOption('pageSize', $va_template_info, 'letter'), caGetOption('pageOrientation', $va_template_info, 'portrait'));
         $o_dompdf->set_base_path(caGetPrintTemplateDirectoryPath('labels'));
         $o_dompdf->render();
         $o_dompdf->stream(caGetOption('filename', $va_template_info, 'labels.pdf'));
         $vb_printed_properly = true;
         foreach ($va_barcode_files_to_delete as $vs_tmp) {
             @unlink($vs_tmp);
         }
     } catch (Exception $e) {
         foreach ($va_barcode_files_to_delete as $vs_tmp) {
             @unlink($vs_tmp);
         }
         $vb_printed_properly = false;
         $this->postError(3100, _t("Could not generate PDF"), "BaseFindController->PrintSummary()");
     }
 }
예제 #2
0
/**
 *
 */
function caGenerateBarcode($ps_value, $pa_options = null)
{
    $ps_barcode_type = caGetOption('type', $pa_options, 'code128', array('forceLowercase' => true));
    $pn_barcode_height = caConvertMeasurementToPoints(caGetOption('height', $pa_options, '9px'));
    $vs_tmp = null;
    switch ($ps_barcode_type) {
        case 'qr':
        case 'qrcode':
            $vs_tmp = tempnam(caGetTempDirPath(), 'caQRCode');
            $vs_tmp2 = tempnam(caGetTempDirPath(), 'caQRCodeResize');
            if (!defined('QR_LOG_DIR')) {
                define('QR_LOG_DIR', false);
            }
            if ($pn_barcode_height < 1 || $pn_barcode_height > 8) {
                $pn_barcode_height = 1;
            }
            QRcode::png($ps_value, "{$vs_tmp}.png", QR_ECLEVEL_H, $pn_barcode_height);
            return $vs_tmp;
            break;
        case 'code128':
        case 'code39':
        case 'ean13':
        case 'int25':
        case 'postnet':
        case 'upca':
            $o_barcode = new Barcode();
            $vs_tmp = tempnam(caGetTempDirPath(), 'caBarCode');
            if (!($va_dimensions = $o_barcode->draw($ps_value, "{$vs_tmp}.png", $ps_barcode_type, 'png', $pn_barcode_height))) {
                return null;
            }
            return $vs_tmp;
            break;
        default:
            // invalid barcode
            break;
    }
    return null;
}