/** 
  * Get page width and height for a specific page type
  *
  * @param string $ps_size A valid page size (eg. A4, letter, legal)
  * @param string $ps_units Units to return measurements in (eg. mm, cm, in)
  * @param string $ps_orientation Orientation of page (eg. portrait, landscape)
  *
  * @return array Array with width and height keys
  */
 public static function getPageSize($ps_size, $ps_units = 'mm', $ps_orientation = 'portrait')
 {
     $ps_orientation = strtolower($ps_orientation);
     if (!PDFRenderer::isValidOrientation($ps_orientation)) {
         $ps_orientation = 'portrait';
     }
     $va_page_size = CPDF_Adapter::$PAPER_SIZES[$ps_size];
     $vn_page_width = caConvertMeasurement($va_page_size[2] - $va_page_size[0] . 'px', $ps_units);
     $vn_page_height = caConvertMeasurement($va_page_size[3] - $va_page_size[1] . 'px', $ps_units);
     return $ps_orientation == 'portrait' ? array('width' => $vn_page_width, 'height' => $vn_page_height) : array('width' => $vn_page_height, 'height' => $vn_page_width);
 }
Beispiel #2
0
 /**
  * Set page size and orientation
  *
  * @param string Page size (ex. A4, letter, legal)
  * @param string Page orientation (ex. portrait, landscape)
  *
  * @return bool True on success, false if parameters are invalid
  */
 public function setPage($ps_size, $ps_orientation, $ps_margin_top = 0, $ps_margin_right = 0, $ps_margin_bottom = 0, $ps_margin_left = 0)
 {
     if (!PDFRenderer::isValidPageSize($ps_size) || !PDFRenderer::isValidOrientation($ps_orientation)) {
         return false;
     }
     $this->ops_page_size = $ps_size;
     $this->ops_page_orientation = $ps_orientation;
     $this->ops_margin_top = caConvertMeasurement($ps_margin_top, 'mm') . 'mm';
     $this->ops_margin_right = caConvertMeasurement($ps_margin_right, 'mm') . 'mm';
     $this->ops_margin_bottom = caConvertMeasurement($ps_margin_bottom, 'mm') . 'mm';
     $this->ops_margin_left = caConvertMeasurement($ps_margin_left, 'mm') . 'mm';
     return true;
 }
 /**
  * Generates and outputs label-formatted PDF version of search results 
  */
 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"));
         $o_pdf = new PDFRenderer();
         $this->view->setVar('PDFRenderer', $vs_renderer = $o_pdf->getCurrentRendererCode());
         // render labels
         $vn_width = caConvertMeasurement(caGetOption('labelWidth', $va_template_info, null), 'mm');
         $vn_height = caConvertMeasurement(caGetOption('labelHeight', $va_template_info, null), 'mm');
         $vn_top_margin = caConvertMeasurement(caGetOption('marginTop', $va_template_info, null), 'mm');
         $vn_bottom_margin = caConvertMeasurement(caGetOption('marginBottom', $va_template_info, null), 'mm');
         $vn_left_margin = caConvertMeasurement(caGetOption('marginLeft', $va_template_info, null), 'mm');
         $vn_right_margin = caConvertMeasurement(caGetOption('marginRight', $va_template_info, null), 'mm');
         $vn_horizontal_gutter = caConvertMeasurement(caGetOption('horizontalGutter', $va_template_info, null), 'mm');
         $vn_vertical_gutter = caConvertMeasurement(caGetOption('verticalGutter', $va_template_info, null), 'mm');
         $va_page_size = PDFRenderer::getPageSize(caGetOption('pageSize', $va_template_info, 'letter'), 'mm', caGetOption('pageOrientation', $va_template_info, 'portrait'));
         $vn_page_width = $va_page_size['width'];
         $vn_page_height = $va_page_size['height'];
         $vn_label_count = 0;
         $vn_left = $vn_left_margin;
         $vn_top = $vn_top_margin;
         $this->view->setVar('pageWidth', "{$vn_page_width}mm");
         $this->view->setVar('pageHeight', "{$vn_page_height}mm");
         $this->view->setVar('marginTop', caGetOption('marginTop', $va_template_info, '0mm'));
         $this->view->setVar('marginRight', caGetOption('marginRight', $va_template_info, '0mm'));
         $this->view->setVar('marginBottom', caGetOption('marginBottom', $va_template_info, '0mm'));
         $this->view->setVar('marginLeft', caGetOption('marginLeft', $va_template_info, '0mm'));
         $vs_content = $this->render("pdfStart.php");
         $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();
         $vn_page_count = 0;
         while ($po_result->nextHit()) {
             $va_barcode_files_to_delete = array_merge($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}mm; height: {$vn_height}mm; left: {$vn_left}mm; top: {$vn_top}mm; overflow: hidden; padding: 0; margin: 0;\">";
             $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_count + 1) * $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;
                 switch ($vs_renderer) {
                     case 'PhantomJS':
                     case 'wkhtmltopdf':
                         // WebKit based renderers (PhantomJS, wkhtmltopdf) want things numbered relative to the top of the document (Eg. the upper left hand corner of the first page is 0,0, the second page is 0,792, Etc.)
                         $vn_page_count++;
                         $vn_top = $vn_page_count * $vn_page_height + $vn_top_margin;
                         break;
                     case 'domPDF':
                     default:
                         // domPDF wants things positioned in a per-page coordinate space (Eg. the upper left hand corner of each page is 0,0)
                         $vn_top = $vn_top_margin;
                         break;
                 }
             }
         }
         $vs_content .= $this->render("pdfEnd.php");
         $o_pdf->setPage(caGetOption('pageSize', $va_template_info, 'letter'), caGetOption('pageOrientation', $va_template_info, 'portrait'));
         $o_pdf->render($vs_content, array('stream' => true, 'filename' => caGetOption('filename', $va_template_info, 'labels.pdf')));
         $vb_printed_properly = true;
         foreach ($va_barcode_files_to_delete as $vs_tmp) {
             @unlink($vs_tmp);
             @unlink("{$vs_tmp}.png");
         }
     } catch (Exception $e) {
         foreach ($va_barcode_files_to_delete as $vs_tmp) {
             @unlink($vs_tmp);
             @unlink("{$vs_tmp}.png");
         }
         $vb_printed_properly = false;
         $this->postError(3100, _t("Could not generate PDF"), "BaseFindController->PrintSummary()");
     }
 }