function generatePDF($action = 'return') { if (!in_array($action, ['return', 'dump'])) { throw $this->exception('Please provide action as result or dump'); } $pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('xEpan ERP'); $pdf->SetTitle($this['type'] . ' ' . $this['document_no']); $pdf->SetSubject($this['type'] . ' ' . $this['document_no']); $pdf->SetKeywords($this['type'] . ' ' . $this['document_no']); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set font $pdf->SetFont('dejavusans', '', 10); //remove header or footer hr lines $pdf->SetPrintHeader(false); $pdf->SetPrintFooter(false); // add a page $pdf->AddPage(); if ($org = $this->ref('contact_id')->get('organization')) { $this['contact'] = $org; $this['contact_id'] = ''; } // getting layouts from config $layout_m = $this->add('xepan\\base\\Model_ConfigJsonModel', ['fields' => ['master' => 'xepan\\base\\RichText', 'detail' => 'xepan\\base\\RichText'], 'config_key' => strtoupper($this['type']) . '_LAYOUT', 'application' => 'commerce']); $layout_m->tryLoadAny(); $info_config = $layout_m['master']; $info_layout = $this->add('GiTemplate'); $info_layout->loadTemplateFromString($info_config); $detail_config = $layout_m['detail']; $detail_layout = $this->add('GiTemplate'); $detail_layout->loadTemplateFromString($detail_config); $new = $this->add('xepan\\commerce\\Model_QSP_Master'); $new->addHook('afterLoad', function ($m) { $m['round_amount'] = abs($m['round_amount']); }); $new->load($this->id); $view = $this->app->add('xepan\\commerce\\View_QSP', ['qsp_model' => $new, 'master_template' => $info_layout, 'detail_template' => $detail_layout, 'action' => 'pdf']); // $view = $this->owner->add('xepan\commerce\View_QSP',['qsp_model'=>$this]); if ($bar_code = $this->getBarCode()) { $barcodeobj = new \TCPDFBarcode($bar_code, 'C128'); // $barcode_html = $barcodeobj->getBarcodePNG(2, 30, 'black'); $barcode_html = $barcodeobj->getBarcodePngData(1, 20, array(0, 128, 0)); $info_layout->trySetHtml('dispatch_barcode', '<img src="data:image/png;base64, ' . base64_encode($barcode_html) . '"/>'); } $html = $view->getHTML(); // echo "string".$html; // echo $html; // exit; // output the HTML content $pdf->writeHTML($html, false, false, true, false, ''); // set default form properties $pdf->setFormDefaultProp(array('lineWidth' => 1, 'borderStyle' => 'solid', 'fillColor' => array(255, 255, 200), 'strokeColor' => array(255, 128, 128))); // reset pointer to the last page $pdf->lastPage(); //Close and output PDF document switch ($action) { case 'return': return $pdf->Output(null, 'S'); break; case 'dump': return $pdf->Output(null, 'I'); exit; break; } }
/** * Save an image file on disk (with no output) * * @param string $code Value to encode * @param string $encoding Mode of encoding * @param string $readable Code can be read * @param integer $scale Scale (not used with this engine) * @param integer $nooutputiferror No output if error (not used with this engine) * @return int <0 if KO, >0 if OK */ function writeBarCode($code, $encoding, $readable = 'Y', $scale = 1, $nooutputiferror = 0) { global $conf, $_GET; dol_mkdir($conf->barcode->dir_temp); $file = $conf->barcode->dir_temp . '/barcode_' . $code . '_' . $encoding . '.png'; $tcpdfEncoding = $this->getTcpdfEncodingType($encoding); if (empty($tcpdfEncoding)) { return -1; } $color = array(0, 0, 0); $_GET["code"] = $code; $_GET["type"] = $encoding; $_GET["height"] = $height; $_GET["readable"] = $readable; if ($code) { // Load the tcpdf barcode class if ($this->is2d) { $height = 1; $width = 1; require_once TCPDF_PATH . 'tcpdf_barcodes_2d.php'; $barcodeobj = new TCPDF2DBarcode($code, $tcpdfEncoding); } else { $height = 50; $width = 1; require_once TCPDF_PATH . 'tcpdf_barcodes_1d.php'; $barcodeobj = new TCPDFBarcode($code, $tcpdfEncoding); } dol_syslog("writeBarCode::TCPDF.getBarcodePngData"); if ($imageData = $barcodeobj->getBarcodePngData($width, $height, $color)) { if (function_exists('imagecreate')) { $imageData = imagecreatefromstring($imageData); } if (imagepng($imageData, $file)) { return 1; } else { return -3; } } else { return -4; } } else { return -2; } }