29 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonstickergenerator.class.php';
37 private $_style1d = array(
46 'fgcolor' => array(0, 0, 0),
49 'font' =>
'helvetica',
55 private $_style2d = array(
59 'fgcolor' => array(0, 0, 0),
65 private $_align2d =
'N';
82 private function writeBarcode(&$pdf, $code, $encoding, $is2d, $x, $y, $w, $h)
85 $pdf->write2DBarcode($code, $encoding, $x, $y, $w, $h, $this->_style2d, $this->_align2d);
87 $pdf->write1DBarcode($code, $encoding, $x, $y, $w, $h, $this->_xres, $this->_style1d);
101 global $mysoc, $conf;
103 $textleft = $param[
'textleft'];
104 $header = $param[
'textheader'];
105 $footer = $param[
'textfooter'];
106 $textright = $param[
'textright'];
107 $code = $param[
'code'];
108 $encoding = $param[
'encoding'];
109 $is2d = $param[
'is2d'];
114 if (($this->_COUNTX == 0) && ($this->_COUNTY == 0) and (!$this->_First == 1)) {
118 $_PosX = $this->_Margin_Left + ($this->_COUNTX * ($this->_Width + $this->_X_Space));
119 $_PosY = $this->_Margin_Top + ($this->_COUNTY * ($this->_Height + $this->_Y_Space));
122 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
123 if (!is_readable($logo))
126 if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small))
128 $logo = $conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small;
129 } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.
'/logos/'.$mysoc->logo))
131 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
141 $pdf->SetXY($_PosX + $xleft, $_PosY + 1);
142 $pdf->Cell($this->_Width - 2 * $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($header), 0, 1,
'C');
145 $ytop += (empty($header) ? 0 : (1 + $this->_Line_Height));
148 $pageMargins = $pdf->getMargins();
149 $maxwidthtouse = round($this->_Width - 2 * $xleft);
150 $maxheighttouse = round($this->_Height - 2 * $ytop);
151 $maxheighttouse -= (empty($footer) ? 0 : (1 + $this->_Line_Height));
152 $defaultratio = ($maxwidthtouse / $maxheighttouse);
153 $widthtouse = $maxwidthtouse;
154 $heighttouse = $maxheighttouse;
155 $logoHeight = $heighttouse;
156 $logoWidth = $widthtouse;
161 if ($textright ==
'')
164 if ($textleft ==
'%LOGO%' && $logo) $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, 0, $logoHeight);
165 elseif ($code && !empty($encoding))
167 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
169 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
170 $pdf->MultiCell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
172 } elseif ($textleft !=
'' && $textright !=
'')
174 $logoHeight = $heighttouse / 2;
175 $logoWidth = $widthtouse / 2;
176 if (($textleft ==
'%LOGO%' || $textleft ==
'%PHOTO%' || $textleft ==
'%BARCODE%') && !strstr($textright,
'%'))
178 if ($textleft ==
'%LOGO%' && $logo) $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, $logoWidth, 0);
179 elseif ($code && !empty($encoding))
181 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft, $_PosY + $ytop, $widthtouse / 2, $heighttouse);
183 $pdf->SetXY($_PosX + ($widthtouse / 2), $_PosY + $ytop);
184 $pdf->MultiCell($widthtouse / 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
185 } elseif (($textright ==
'%LOGO%' || $textright ==
'%PHOTO%' || $textright ==
'%BARCODE%') && !strstr($textleft,
'%'))
187 if ($textright ==
'%LOGO%' && $logo) $pdf->Image($logo, $_PosX + ($widthtouse / 2), $_PosY + $ytop, $logoWidth, 0);
188 elseif ($code && !empty($encoding))
190 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + ($widthtouse / 2), $_PosY + $ytop, $widthtouse / 2, $heighttouse);
192 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
193 $pdf->MultiCell($widthtouse / 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
194 } elseif ($textleft ==
'%LOGO%')
196 if ($logo) $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, 0, $logoHeight);
197 if ($code && !empty($encoding))
199 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft + $logoWidth + 1, $_PosY + $ytop, $widthtouse - $logoWidth - 1, $heighttouse);
201 $pdf->SetXY($_PosX + $xleft + $logoWidth + 1, $_PosY + $ytop);
202 $pdf->MultiCell($widthtouse - $logoWidth - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
204 } elseif ($textright ==
'%LOGO%')
206 if ($logo) $pdf->Image($logo, $_PosX + $xleft + $widthtouse - $logoWidth + 1, $_PosY + $ytop, 0, $logoHeight);
207 if ($code && !empty($encoding))
209 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft, $_PosY + $ytop, $widthtouse - $logoWidth - 1, $heighttouse);
211 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
212 $pdf->MultiCell($widthtouse - $logoWidth - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
216 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
217 $pdf->MultiCell(round($this->_Width / 2), $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
218 $pdf->SetXY($_PosX + round($this->_Width / 2), $_PosY + $ytop);
219 $pdf->MultiCell(round($this->_Width / 2) - 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
224 if ($textright ==
'%LOGO%' && $logo) $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, 0, $logoHeight);
225 elseif ($code && !empty($encoding))
227 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
229 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
230 $pdf->MultiCell($this->_Width - $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
237 $pdf->SetXY($_PosX, $_PosY + $this->_Height - $this->_Line_Height - 1);
238 $pdf->Cell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($footer), 0, 1,
'C');
244 if ($this->_COUNTY == $this->_Y_Number) {
250 if ($this->_COUNTX == $this->_X_Number) {
271 public function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir =
'', $filename =
'tmp_address_sheet.pdf')
274 global $user, $conf, $langs, $mysoc, $_Avery_Labels;
276 $this->
code = $srctemplatepath;
277 $this->Tformat = $_Avery_Labels[$this->code];
278 if (empty($this->Tformat)) {
dol_print_error(
'',
'ErrorBadTypeForCard'.$this->
code); exit; }
281 if ($this->Tformat[
'paper-size'] !=
'custom') {
282 $this->format = $this->Tformat[
'paper-size'];
285 $resolution = array($this->Tformat[
'custom_x'], $this->Tformat[
'custom_y']);
286 $this->format = $resolution;
289 if (!is_object($outputlangs)) $outputlangs = $langs;
291 if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output =
'ISO-8859-1';
294 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"admin"));
296 $title = $outputlangs->transnoentities(
'Labels');
297 $keywords = $title.
" ".$outputlangs->convToOutputCharset($mysoc->name);
299 $dir = (empty($outputdir) ? $conf->adherent->dir_temp : $outputdir);
300 $file = $dir.
"/".$filename;
302 if (!file_exists($dir))
306 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
311 $pdf =
pdf_getInstance($this->format, $this->Tformat[
'metric'], $this->Tformat[
'orientation']);
313 if (class_exists(
'TCPDF'))
315 $pdf->setPrintHeader(
false);
316 $pdf->setPrintFooter(
false);
320 $pdf->SetTitle($title);
321 $pdf->SetSubject($title);
322 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
323 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
324 $pdf->SetKeyWords($keywords);
325 if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(
false);
327 $pdf->SetMargins(0, 0);
328 $pdf->SetAutoPageBreak(
false);
330 $this->_Metric_Doc = $this->Tformat[
'metric'];
334 if ($posX > 0) $posX--;
else $posX = 0;
335 if ($posY > 0) $posY--;
else $posY = 0;
336 $this->_COUNTX = $posX;
337 $this->_COUNTY = $posY;
346 foreach ($arrayofrecords as $val)
357 $pdf->Output($file,
'F');
359 if (!empty($conf->global->MAIN_UMASK))
360 @chmod($file, octdec($conf->global->MAIN_UMASK));
363 $this->result = array(
'fullpath'=>$file);
addSticker(&$pdf, $outputlangs, $param)
Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) ...
if(!empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'] country if(!empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'] typent code
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Class to generate stick sheet with format Avery or other personalised.
writeBarcode(&$pdf, $code, $encoding, $is2d, $x, $y, $w, $h)
write barcode to pdf
pdf_getInstance($format= '', $metric= 'mm', $pagetype= 'P')
Return a PDF instance object.
write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir= '', $filename= 'tmp_address_sheet.pdf')
Function to build PDF on disk, then output on HTTP strem.
_Set_Format(&$pdf, $format)
protected Set format
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Class to generate stick sheet with format Avery or other personalised.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)