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)) {
125 if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small)) {
126 $logo = $conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small;
127 } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.
'/logos/'.$mysoc->logo)) {
128 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
137 $pdf->SetXY($_PosX + $xleft, $_PosY + 1);
138 $pdf->Cell(2 * strlen($header), $this->_Line_Height, $outputlangs->convToOutputCharset($header), 0, 1,
'C');
141 $ytop += (empty($header) ? 0 : (1 + $this->_Line_Height));
144 $pageMargins = $pdf->getMargins();
145 $maxwidthtouse = round($this->_Width - 2 * $xleft);
146 $maxheighttouse = round($this->_Height - 2 * $ytop);
147 $maxheighttouse -= (empty($footer) ? 0 : (1 + $this->_Line_Height));
148 $defaultratio = ($maxwidthtouse / $maxheighttouse);
149 $widthtouse = $maxwidthtouse;
150 $heighttouse = $maxheighttouse;
151 $logoHeight = $heighttouse;
152 $logoWidth = $widthtouse;
157 if ($textright ==
'') {
159 if ($textleft ==
'%LOGO%' && $logo) {
160 $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, 0, $logoHeight);
161 } elseif ($code && !empty($encoding)) {
162 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
164 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
165 $pdf->MultiCell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
167 } elseif ($textleft !=
'' && $textright !=
'') {
168 $logoHeight = $heighttouse / 2;
169 $logoWidth = $widthtouse / 2;
170 if (($textleft ==
'%LOGO%' || $textleft ==
'%PHOTO%' || $textleft ==
'%BARCODE%') && !strstr($textright,
'%')) {
171 if ($textleft ==
'%LOGO%' && $logo) {
172 $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, $logoWidth, 0);
173 } elseif ($code && !empty($encoding)) {
174 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft, $_PosY + $ytop, $widthtouse / 2, $heighttouse);
176 $pdf->SetXY($_PosX + ($widthtouse / 2), $_PosY + $ytop);
177 $pdf->MultiCell($widthtouse / 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
178 } elseif (($textright ==
'%LOGO%' || $textright ==
'%PHOTO%' || $textright ==
'%BARCODE%') && !strstr($textleft,
'%')) {
179 if ($textright ==
'%LOGO%' && $logo) {
180 $pdf->Image($logo, $_PosX + ($widthtouse / 2), $_PosY + $ytop, $logoWidth, 0);
181 } elseif ($code && !empty($encoding)) {
182 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + ($widthtouse / 2), $_PosY + $ytop, $widthtouse / 2, $heighttouse);
184 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
185 $pdf->MultiCell($widthtouse / 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
186 } elseif ($textleft ==
'%LOGO%') {
188 $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, 0, $logoHeight);
190 if ($code && !empty($encoding)) {
191 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft + $logoWidth + 1, $_PosY + $ytop, $widthtouse - $logoWidth - 1, $heighttouse);
193 $pdf->SetXY($_PosX + $xleft + $logoWidth + 1, $_PosY + $ytop);
194 $pdf->MultiCell($widthtouse - $logoWidth - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
196 } elseif ($textright ==
'%LOGO%') {
198 $pdf->Image($logo, $_PosX + $xleft + $widthtouse - $logoWidth + 1, $_PosY + $ytop, 0, $logoHeight);
200 if ($code && !empty($encoding)) {
201 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft, $_PosY + $ytop, $widthtouse - $logoWidth - 1, $heighttouse);
203 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
204 $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');
216 if ($textright ==
'%LOGO%' && $logo) {
217 $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, 0, $logoHeight);
218 } elseif ($code && !empty($encoding)) {
219 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
221 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
222 $pdf->MultiCell($this->_Width - $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
228 $pdf->SetXY($_PosX, $_PosY + $this->_Height - $this->_Line_Height - 1);
229 $pdf->Cell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($footer), 0, 1,
'C');
235 if ($this->_COUNTY == $this->_Y_Number) {
241 if ($this->_COUNTX == $this->_X_Number) {
262 public function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir =
'', $filename =
'tmp_address_sheet.pdf')
265 global $user, $conf, $langs, $mysoc, $_Avery_Labels;
267 $this->code = $srctemplatepath;
268 $this->Tformat = $_Avery_Labels[$this->code];
269 if (empty($this->Tformat)) {
275 if ($this->Tformat[
'paper-size'] !=
'custom') {
276 $this->format = $this->Tformat[
'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;
287 if (!empty($conf->global->MAIN_USE_FPDF)) {
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);