102 global $mysoc, $conf;
104 $textleft = $param[
'textleft'];
105 $header = $param[
'textheader'];
106 $footer = $param[
'textfooter'];
107 $textright = $param[
'textright'];
108 $code = $param[
'code'];
109 $encoding = $param[
'encoding'];
110 $is2d = $param[
'is2d'];
115 if (($this->_COUNTX == 0) && ($this->_COUNTY == 0) and (!$this->_First == 1)) {
119 $_PosX = $this->_Margin_Left + ($this->_COUNTX * ($this->_Width + $this->_X_Space));
120 $_PosY = $this->_Margin_Top + ($this->_COUNTY * ($this->_Height + $this->_Y_Space));
123 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
124 if (!is_readable($logo)) {
126 if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small)) {
127 $logo = $conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small;
128 } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.
'/logos/'.$mysoc->logo)) {
129 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
138 $pdf->SetXY($_PosX + $xleft, $_PosY + 1);
139 $pdf->Cell(2 * strlen($header), $this->_Line_Height, $outputlangs->convToOutputCharset($header), 0, 1,
'C');
142 $ytop += (empty($header) ? 0 : (1 + $this->_Line_Height));
145 $pageMargins = $pdf->getMargins();
146 $maxwidthtouse = round($this->_Width - 2 * $xleft);
147 $maxheighttouse = round($this->_Height - 2 * $ytop);
148 $maxheighttouse -= (empty($footer) ? 0 : (1 + $this->_Line_Height));
149 $defaultratio = ($maxwidthtouse / $maxheighttouse);
150 $widthtouse = $maxwidthtouse;
151 $heighttouse = $maxheighttouse;
152 $logoHeight = $heighttouse;
153 $logoWidth = $widthtouse;
158 if ($textright ==
'') {
160 if ($textleft ==
'%LOGO%' && $logo) {
161 $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, 0, $logoHeight);
162 } elseif ($code && !empty($encoding)) {
163 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
165 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
166 $pdf->MultiCell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
168 } elseif ($textleft !=
'' && $textright !=
'') {
169 $logoHeight = $heighttouse / 2;
170 $logoWidth = $widthtouse / 2;
171 if (($textleft ==
'%LOGO%' || $textleft ==
'%PHOTO%' || $textleft ==
'%BARCODE%') && !strstr($textright,
'%')) {
172 if ($textleft ==
'%LOGO%' && $logo) {
173 $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, $logoWidth, 0);
174 } elseif ($code && !empty($encoding)) {
175 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft, $_PosY + $ytop, $widthtouse / 2, $heighttouse);
177 $pdf->SetXY($_PosX + ($widthtouse / 2), $_PosY + $ytop);
178 $pdf->MultiCell($widthtouse / 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
179 } elseif (($textright ==
'%LOGO%' || $textright ==
'%PHOTO%' || $textright ==
'%BARCODE%') && !strstr($textleft,
'%')) {
180 if ($textright ==
'%LOGO%' && $logo) {
181 $pdf->Image($logo, $_PosX + ($widthtouse / 2), $_PosY + $ytop, $logoWidth, 0);
182 } elseif ($code && !empty($encoding)) {
183 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + ($widthtouse / 2), $_PosY + $ytop, $widthtouse / 2, $heighttouse);
185 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
186 $pdf->MultiCell($widthtouse / 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
187 } elseif ($textleft ==
'%LOGO%') {
189 $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, 0, $logoHeight);
191 if ($code && !empty($encoding)) {
192 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft + $logoWidth + 1, $_PosY + $ytop, $widthtouse - $logoWidth - 1, $heighttouse);
194 $pdf->SetXY($_PosX + $xleft + $logoWidth + 1, $_PosY + $ytop);
195 $pdf->MultiCell($widthtouse - $logoWidth - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
197 } elseif ($textright ==
'%LOGO%') {
199 $pdf->Image($logo, $_PosX + $xleft + $widthtouse - $logoWidth + 1, $_PosY + $ytop, 0, $logoHeight);
201 if ($code && !empty($encoding)) {
202 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft, $_PosY + $ytop, $widthtouse - $logoWidth - 1, $heighttouse);
204 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
205 $pdf->MultiCell($widthtouse - $logoWidth - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
208 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
209 $pdf->MultiCell(round($this->_Width / 2), $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
210 $pdf->SetXY($_PosX + round($this->_Width / 2), $_PosY + $ytop);
211 $pdf->MultiCell(round($this->_Width / 2) - 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
215 if ($textright ==
'%LOGO%' && $logo) {
216 $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, 0, $logoHeight);
217 } elseif ($code && !empty($encoding)) {
218 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
220 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
221 $pdf->MultiCell($this->_Width - $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
227 $pdf->SetXY($_PosX, $_PosY + $this->_Height - $this->_Line_Height - 1);
228 $pdf->Cell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($footer), 0, 1,
'C');
234 if ($this->_COUNTY == $this->_Y_Number) {
240 if ($this->_COUNTX == $this->_X_Number) {
261 public function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir =
'', $filename =
'tmp_address_sheet.pdf')
264 global $user, $conf, $langs, $mysoc, $_Avery_Labels;
266 $this->code = $srctemplatepath;
267 $this->Tformat = $_Avery_Labels[$this->code];
268 if (empty($this->Tformat)) {
274 $paper_size = $this->Tformat[
'paper-size'];
275 if (!is_string($paper_size) || $paper_size !=
'custom') {
276 $this->format = $paper_size;
279 $resolution = array($this->Tformat[
'custom_x'], $this->Tformat[
'custom_y']);
280 $this->format = $resolution;
283 if (!is_object($outputlangs)) {
284 $outputlangs = $langs;
288 $outputlangs->charset_output =
'ISO-8859-1';
292 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"admin"));
294 $title = $outputlangs->transnoentities(
'Labels');
295 $keywords = $title.
" ".$outputlangs->convToOutputCharset($mysoc->name);
297 $dir = (empty($outputdir) ? $conf->adherent->dir_temp : $outputdir);
298 $file = $dir.
"/".$filename;
300 if (!file_exists($dir)) {
302 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
307 $pdf =
pdf_getInstance($this->format, $this->Tformat[
'metric'], $this->Tformat[
'orientation']);
309 if (class_exists(
'TCPDF')) {
310 $pdf->setPrintHeader(
false);
311 $pdf->setPrintFooter(
false);
315 $pdf->SetTitle($title);
316 $pdf->SetSubject($title);
317 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
318 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
319 $pdf->SetKeyWords($keywords);
321 $pdf->SetCompression(
false);
324 $pdf->SetMargins(0, 0);
325 $pdf->SetAutoPageBreak(
false);
327 $this->_Metric_Doc = $this->Tformat[
'metric'];
341 $this->_COUNTX = $posX;
342 $this->_COUNTY = $posY;
351 foreach ($arrayofrecords as $val) {
361 $pdf->Output($file,
'F');
365 $this->result = array(
'fullpath' => $file);