--- /tmp/dsg/dolibarr/htdocs/core/modules/printsheet/doc/github_pdf_standardlabel.class.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/printsheet/doc/client_pdf_standardlabel.class.php @@ -36,23 +36,23 @@ /** * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) * - * @param TCPDF $pdf PDF reference + * @param PDF $pdf PDF reference * @param Translate $outputlangs Output langs * @param array $param Associative array containing label content and optional parameters * @return void */ - public function addSticker(&$pdf, $outputlangs, $param) - { + public function addSticker(&$pdf, $outputlangs, $param) + { // use this method in future refactoring } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) * - %LOGO% is replace with company logo * - %PHOTO% is replace with photo provided as parameter * - * @param TCPDF $pdf PDF reference + * @param PDF $pdf PDF reference * @param string $textleft Text left * @param string $header Header * @param string $footer Footer @@ -63,7 +63,7 @@ */ public function Add_PDF_label(&$pdf, $textleft, $header, $footer, $outputlangs, $textright = '', $photo = '') { - // phpcs:enable + // phpcs:enable global $mysoc, $conf, $langs; global $forceimgscalewidth, $forceimgscaleheight; @@ -86,7 +86,8 @@ if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small)) { $logo = $conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small; - } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) + } + elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) { $logo = $conf->mycompany->dir_output.'/logos/'.$mysoc->logo; } @@ -141,7 +142,8 @@ if ($tmp['height']) { $imgratio = $tmp['width'] / $tmp['height']; - if ($imgratio >= $defaultratio) { $widthtouse = $maxwidthtouse; $heighttouse = round($widthtouse / $imgratio); } else { $heightouse = $maxheighttouse; $widthtouse = round($heightouse * $imgratio); } + if ($imgratio >= $defaultratio) { $widthtouse = $maxwidthtouse; $heighttouse = round($widthtouse / $imgratio); } + else { $heightouse = $maxheighttouse; $widthtouse = round($heightouse * $imgratio); } } //var_dump($this->_Width.'x'.$this->_Height.' with border and scale '.$imgscale.' => max '.$maxwidthtouse.'x'.$maxheighttouse.' => We use '.$widthtouse.'x'.$heighttouse);exit; @@ -151,11 +153,13 @@ // Output left area if ($textleft == '%LOGO%' && $logo) $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse); elseif ($textleft == '%PHOTO%' && $photo) $pdf->Image($photo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse); - else { + else + { $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop); $pdf->MultiCell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0, 'L'); } - } elseif ($textleft != '' && $textright != '') // + } + elseif ($textleft != '' && $textright != '') // { if ($textleft == '%LOGO%' || $textleft == '%PHOTO%') { @@ -163,25 +167,29 @@ elseif ($textleft == '%PHOTO%' && $photo) $pdf->Image($photo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse); $pdf->SetXY($_PosX + $xleft + $widthtouse + 1, $_PosY + $ytop); $pdf->MultiCell($this->_Width - $xleft - $xleft - $widthtouse - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0, 'R'); - } elseif ($textright == '%LOGO%' || $textright == '%PHOTO%') + } + elseif ($textright == '%LOGO%' || $textright == '%PHOTO%') { if ($textright == '%LOGO%' && $logo) $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse); elseif ($textright == '%PHOTO%' && $photo) $pdf->Image($photo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse); $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop); $pdf->MultiCell($this->_Width - $widthtouse - $xleft - $xleft - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0, 'L'); - } else // text on halft left and text on half right + } + else // text on halft left and text on half right { $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop); $pdf->MultiCell(round($this->_Width / 2), $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0, 'L'); $pdf->SetXY($_PosX + round($this->_Width / 2), $_PosY + $ytop); $pdf->MultiCell(round($this->_Width / 2) - 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0, 'R'); } - } else // Only a right part + } + else // Only a right part { // Output right area if ($textright == '%LOGO%' && $logo) $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse); elseif ($textright == '%PHOTO%' && $photo) $pdf->Image($photo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse); - else { + else + { $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop); $pdf->MultiCell($this->_Width - $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0, 'R'); } @@ -219,7 +227,7 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Function to build PDF on disk, then output on HTTP strem. * @@ -232,21 +240,21 @@ */ public function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir = '', $filename = 'tmp_address_sheet.pdf') { - // phpcs:enable + // phpcs:enable global $user, $conf, $langs, $mysoc, $_Avery_Labels; $this->code = $srctemplatepath; $this->Tformat = $_Avery_Labels[$this->code]; if (empty($this->Tformat)) { dol_print_error('', 'ErrorBadTypeForCard'.$this->code); exit; } $this->type = 'pdf'; - // standard format or custom - if ($this->Tformat['paper-size'] != 'custom') { - $this->format = $this->Tformat['paper-size']; - } else { - //custom - $resolution = array($this->Tformat['custom_x'], $this->Tformat['custom_y']); - $this->format = $resolution; - } + // standard format or custom + if ($this->Tformat['paper-size'] != 'custom') { + $this->format = $this->Tformat['paper-size']; + } else { + //custom + $resolution = array($this->Tformat['custom_x'], $this->Tformat['custom_y']); + $this->format = $resolution; + } if (!is_object($outputlangs)) $outputlangs = $langs; // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO @@ -321,6 +329,24 @@ if (!empty($conf->global->MAIN_UMASK)) @chmod($file, octdec($conf->global->MAIN_UMASK)); + // Output to http stream + clearstatcache(); + + $attachment = true; + if (!empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment = false; + $type = dol_mimetype($filename); + + //if ($encoding) header('Content-Encoding: '.$encoding); + if ($type) header('Content-Type: '.$type); + if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"'); + else header('Content-Disposition: inline; filename="'.$filename.'"'); + + // Ajout directives pour resoudre bug IE + header('Cache-Control: Public, must-revalidate'); + header('Pragma: public'); + + readfile($file); + $this->result = array('fullpath'=>$file); return 1; --- /tmp/dsg/dolibarr/htdocs/core/modules/printsheet/doc/github_pdf_tcpdflabel.class.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/printsheet/doc/client_pdf_tcpdflabel.class.php @@ -69,7 +69,7 @@ /** * write barcode to pdf * - * @param TCPDF $pdf PDF reference + * @param PDF $pdf PDF reference * @param string $code code to print * @param string $encoding type of barcode * @param boolean $is2d true if 2d barcode @@ -91,7 +91,7 @@ /** * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) * - * @param TCPDF $pdf PDF reference + * @param PDF $pdf PDF reference * @param Translate $outputlangs Output langs * @param array $param Associative array containing label content and optional parameters * @return void @@ -126,7 +126,8 @@ if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small)) { $logo = $conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small; - } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) + } + elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) { $logo = $conf->mycompany->dir_output.'/logos/'.$mysoc->logo; } @@ -165,11 +166,14 @@ elseif ($code && !empty($encoding)) { $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse); - } else { + } + else + { $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop); $pdf->MultiCell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0, 'L'); } - } elseif ($textleft != '' && $textright != '') // left and right part + } + elseif ($textleft != '' && $textright != '') // left and right part { $logoHeight = $heighttouse / 2; $logoWidth = $widthtouse / 2; @@ -182,7 +186,8 @@ } $pdf->SetXY($_PosX + ($widthtouse / 2), $_PosY + $ytop); $pdf->MultiCell($widthtouse / 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0, 'R'); - } elseif (($textright == '%LOGO%' || $textright == '%PHOTO%' || $textright == '%BARCODE%') && !strstr($textleft, '%')) // right part logo/barcode left part text + } + elseif (($textright == '%LOGO%' || $textright == '%PHOTO%' || $textright == '%BARCODE%') && !strstr($textleft, '%')) // right part logo/barcode left part text { if ($textright == '%LOGO%' && $logo) $pdf->Image($logo, $_PosX + ($widthtouse / 2), $_PosY + $ytop, $logoWidth, 0); elseif ($code && !empty($encoding)) @@ -191,7 +196,8 @@ } $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop); $pdf->MultiCell($widthtouse / 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0, 'L'); - } elseif ($textleft == '%LOGO%') // left part logo right part text/barcode + } + elseif ($textleft == '%LOGO%') // left part logo right part text/barcode { if ($logo) $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, 0, $logoHeight); if ($code && !empty($encoding)) @@ -201,7 +207,8 @@ $pdf->SetXY($_PosX + $xleft + $logoWidth + 1, $_PosY + $ytop); $pdf->MultiCell($widthtouse - $logoWidth - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0, 'R'); } - } elseif ($textright == '%LOGO%') // right part logo left part text/barcode + } + elseif ($textright == '%LOGO%') // right part logo left part text/barcode { if ($logo) $pdf->Image($logo, $_PosX + $xleft + $widthtouse - $logoWidth + 1, $_PosY + $ytop, 0, $logoHeight); if ($code && !empty($encoding)) @@ -211,21 +218,25 @@ $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop); $pdf->MultiCell($widthtouse - $logoWidth - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0, 'L'); } - } else // text on halft left and text on half right + } + else // text on halft left and text on half right { $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop); $pdf->MultiCell(round($this->_Width / 2), $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0, 'L'); $pdf->SetXY($_PosX + round($this->_Width / 2), $_PosY + $ytop); $pdf->MultiCell(round($this->_Width / 2) - 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0, 'R'); } - } else // Only a right part + } + else // Only a right part { // Output right area if ($textright == '%LOGO%' && $logo) $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, 0, $logoHeight); elseif ($code && !empty($encoding)) { $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse); - } else { + } + else + { $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop); $pdf->MultiCell($this->_Width - $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0, 'R'); } @@ -257,7 +268,7 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Function to build PDF on disk, then output on HTTP strem. * @@ -270,21 +281,21 @@ */ public function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir = '', $filename = 'tmp_address_sheet.pdf') { - // phpcs:enable + // phpcs:enable global $user, $conf, $langs, $mysoc, $_Avery_Labels; $this->code = $srctemplatepath; $this->Tformat = $_Avery_Labels[$this->code]; if (empty($this->Tformat)) { dol_print_error('', 'ErrorBadTypeForCard'.$this->code); exit; } $this->type = 'pdf'; - // standard format or custom - if ($this->Tformat['paper-size'] != 'custom') { - $this->format = $this->Tformat['paper-size']; - } else { - //custom - $resolution = array($this->Tformat['custom_x'], $this->Tformat['custom_y']); - $this->format = $resolution; - } + // standard format or custom + if ($this->Tformat['paper-size'] != 'custom') { + $this->format = $this->Tformat['paper-size']; + } else { + //custom + $resolution = array($this->Tformat['custom_x'], $this->Tformat['custom_y']); + $this->format = $resolution; + } if (!is_object($outputlangs)) $outputlangs = $langs; // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO @@ -359,6 +370,23 @@ if (!empty($conf->global->MAIN_UMASK)) @chmod($file, octdec($conf->global->MAIN_UMASK)); + // Output to http stream + clearstatcache(); + + $attachment = true; + if (!empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment = false; + $type = dol_mimetype($filename); + + //if ($encoding) header('Content-Encoding: '.$encoding); + if ($type) header('Content-Type: '.$type); + if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"'); + else header('Content-Disposition: inline; filename="'.$filename.'"'); + + // Ajout directives pour resoudre bug IE + header('Cache-Control: Public, must-revalidate'); + header('Pragma: public'); + + readfile($file); $this->result = array('fullpath'=>$file);