29 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonstickergenerator.class.php';
64 public function Add_PDF_label(&$pdf, $textleft, $header, $footer, $outputlangs, $textright =
'', $photo =
'')
67 global $mysoc, $conf, $langs;
68 global $forceimgscalewidth, $forceimgscaleheight;
70 $imgscalewidth = (empty($forceimgscalewidth) ? 0.3 : $forceimgscalewidth);
71 $imgscaleheight = (empty($forceimgscaleheight) ? 0.5 : $forceimgscaleheight);
74 if (($this->_COUNTX == 0) && ($this->_COUNTY == 0) and (!$this->_First == 1)) {
78 $_PosX = $this->_Margin_Left + ($this->_COUNTX * ($this->_Width + $this->_X_Space));
79 $_PosY = $this->_Margin_Top + ($this->_COUNTY * ($this->_Height + $this->_Y_Space));
82 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
83 if (!is_readable($logo))
86 if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small))
88 $logo = $conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small;
89 } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.
'/logos/'.$mysoc->logo))
91 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
98 if (!is_readable($photo)) $photo =
'';
102 $backgroundimage =
'';
105 if ($this->
code ==
"CARD")
107 $this->Tformat = $this->_Avery_Labels[
"CARD"];
109 $this->
_Croix($pdf, $_PosX, $_PosY, $_PosX + $this->_Width, $_PosY + $this->_Height, 0.1, 10);
113 if ($backgroundimage)
115 $pdf->image($backgroundimage, $_PosX, $_PosY, $this->_Width, $this->_Height);
118 $xleft = 2; $ytop = 2;
123 if ($this->
code ==
"CARD")
125 $pdf->SetDrawColor(128, 128, 128);
126 $pdf->Line($_PosX, $_PosY + $this->_Line_Height + 1, $_PosX + $this->_Width, $_PosY + $this->_Line_Height + 1);
127 $pdf->SetDrawColor(0, 0, 0);
129 $pdf->SetXY($_PosX + $xleft, $_PosY + 1);
130 $pdf->Cell($this->_Width - 2 * $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($header), 0, 1,
'C');
134 $ytop += (empty($header) ? 0 : (1 + $this->_Line_Height));
137 $maxwidthtouse = round(($this->_Width - 2 * $xleft) * $imgscalewidth); $maxheighttouse = round(($this->_Height - 2 * $ytop) * $imgscaleheight);
138 $defaultratio = ($maxwidthtouse / $maxheighttouse);
139 $widthtouse = $maxwidthtouse; $heighttouse = 0;
143 $imgratio = $tmp[
'width'] / $tmp[
'height'];
144 if ($imgratio >= $defaultratio) { $widthtouse = $maxwidthtouse; $heighttouse = round($widthtouse / $imgratio); }
else { $heightouse = $maxheighttouse; $widthtouse = round($heightouse * $imgratio); }
149 if ($textright ==
'')
152 if ($textleft ==
'%LOGO%' && $logo) $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
153 elseif ($textleft ==
'%PHOTO%' && $photo) $pdf->Image($photo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
155 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
156 $pdf->MultiCell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
158 } elseif ($textleft !=
'' && $textright !=
'')
160 if ($textleft ==
'%LOGO%' || $textleft ==
'%PHOTO%')
162 if ($textleft ==
'%LOGO%' && $logo) $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
163 elseif ($textleft ==
'%PHOTO%' && $photo) $pdf->Image($photo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
164 $pdf->SetXY($_PosX + $xleft + $widthtouse + 1, $_PosY + $ytop);
165 $pdf->MultiCell($this->_Width - $xleft - $xleft - $widthtouse - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
166 } elseif ($textright ==
'%LOGO%' || $textright ==
'%PHOTO%')
168 if ($textright ==
'%LOGO%' && $logo) $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
169 elseif ($textright ==
'%PHOTO%' && $photo) $pdf->Image($photo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
170 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
171 $pdf->MultiCell($this->_Width - $widthtouse - $xleft - $xleft - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
174 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
175 $pdf->MultiCell(round($this->_Width / 2), $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
176 $pdf->SetXY($_PosX + round($this->_Width / 2), $_PosY + $ytop);
177 $pdf->MultiCell(round($this->_Width / 2) - 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
182 if ($textright ==
'%LOGO%' && $logo) $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
183 elseif ($textright ==
'%PHOTO%' && $photo) $pdf->Image($photo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
185 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
186 $pdf->MultiCell($this->_Width - $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
193 if ($this->
code ==
"CARD")
195 $pdf->SetDrawColor(128, 128, 128);
196 $pdf->Line($_PosX, $_PosY + $this->_Height - $this->_Line_Height - 2, $_PosX + $this->_Width, $_PosY + $this->_Height - $this->_Line_Height - 2);
197 $pdf->SetDrawColor(0, 0, 0);
199 $pdf->SetXY($_PosX, $_PosY + $this->_Height - $this->_Line_Height - 1);
200 $pdf->Cell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($footer), 0, 1,
'C');
206 if ($this->_COUNTY == $this->_Y_Number) {
212 if ($this->_COUNTX == $this->_X_Number) {
233 public function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir =
'', $filename =
'tmp_address_sheet.pdf')
236 global $user, $conf, $langs, $mysoc, $_Avery_Labels;
238 $this->
code = $srctemplatepath;
239 $this->Tformat = $_Avery_Labels[$this->code];
240 if (empty($this->Tformat)) {
dol_print_error(
'',
'ErrorBadTypeForCard'.$this->
code); exit; }
243 if ($this->Tformat[
'paper-size'] !=
'custom') {
244 $this->format = $this->Tformat[
'paper-size'];
247 $resolution = array($this->Tformat[
'custom_x'], $this->Tformat[
'custom_y']);
248 $this->format = $resolution;
251 if (!is_object($outputlangs)) $outputlangs = $langs;
253 if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output =
'ISO-8859-1';
256 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"admin"));
258 $title = $outputlangs->transnoentities(
'Labels');
259 $keywords = $title.
" ".$outputlangs->convToOutputCharset($mysoc->name);
261 $dir = (empty($outputdir) ? $conf->adherent->dir_temp : $outputdir);
262 $file = $dir.
"/".$filename;
264 if (!file_exists($dir))
268 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
273 $pdf =
pdf_getInstance($this->format, $this->Tformat[
'metric'], $this->Tformat[
'orientation']);
275 if (class_exists(
'TCPDF'))
277 $pdf->setPrintHeader(
false);
278 $pdf->setPrintFooter(
false);
282 $pdf->SetTitle($title);
283 $pdf->SetSubject($title);
284 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
285 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
286 $pdf->SetKeyWords($keywords);
287 if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(
false);
289 $pdf->SetMargins(0, 0);
290 $pdf->SetAutoPageBreak(
false);
292 $this->_Metric_Doc = $this->Tformat[
'metric'];
296 if ($posX > 0) $posX--;
else $posX = 0;
297 if ($posY > 0) $posY--;
else $posY = 0;
298 $this->_COUNTX = $posX;
299 $this->_COUNTY = $posY;
308 foreach ($arrayofrecords as $val)
311 $this->
Add_PDF_label($pdf, $val[
'textleft'], $val[
'textheader'], $val[
'textfooter'], $langs, $val[
'textright'], $val[
'photo']);
319 $pdf->Output($file,
'F');
321 if (!empty($conf->global->MAIN_UMASK))
322 @chmod($file, octdec($conf->global->MAIN_UMASK));
324 $this->result = array(
'fullpath'=>$file);
_Croix(&$pdf, $x1=0, $y1=0, $x2=210, $y2=297, $epaisseur=1, $taille=4)
protected Function realisant une croix aux 4 coins des cartes
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
dol_getImageSize($file, $url=false)
Return size of image file on disk (Supported extensions are gif, jpg, png and bmp) ...
Class to generate stick sheet with format Avery or other personalised.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Class to generate stick sheet with format Avery or other personalised.
addSticker(&$pdf, $outputlangs, $param)
Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) ...
Add_PDF_label(&$pdf, $textleft, $header, $footer, $outputlangs, $textright= '', $photo= '')
Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) ...
pdf_getInstance($format= '', $metric= 'mm', $pagetype= 'P')
Return a PDF instance object.
_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...
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)
write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir= '', $filename= 'tmp_address_sheet.pdf')
Function to build PDF on disk, then output on HTTP strem.