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');
207 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
208 $pdf->MultiCell(round($this->_Width / 2), $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
209 $pdf->SetXY($_PosX + round($this->_Width / 2), $_PosY + $ytop);
210 $pdf->MultiCell(round($this->_Width / 2) - 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
214 if ($textright ==
'%LOGO%' && $logo) {
215 $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, 0, $logoHeight);
216 } elseif ($code && !empty($encoding)) {
217 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
219 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
220 $pdf->MultiCell($this->_Width - $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
226 $pdf->SetXY($_PosX, $_PosY + $this->_Height - $this->_Line_Height - 1);
227 $pdf->Cell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($footer), 0, 1,
'C');
233 if ($this->_COUNTY == $this->_Y_Number) {
239 if ($this->_COUNTX == $this->_X_Number) {
260 public function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir =
'', $filename =
'tmp_address_sheet.pdf')
263 global $user, $conf, $langs, $mysoc, $_Avery_Labels;
265 $this->code = $srctemplatepath;
266 $this->Tformat = $_Avery_Labels[$this->code];
267 if (empty($this->Tformat)) {
273 if ($this->Tformat[
'paper-size'] !=
'custom') {
274 $this->format = $this->Tformat[
'paper-size'];
277 $resolution = array($this->Tformat[
'custom_x'], $this->Tformat[
'custom_y']);
278 $this->format = $resolution;
281 if (!is_object($outputlangs)) {
282 $outputlangs = $langs;
286 $outputlangs->charset_output =
'ISO-8859-1';
290 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"admin"));
292 $title = $outputlangs->transnoentities(
'Labels');
293 $keywords = $title.
" ".$outputlangs->convToOutputCharset($mysoc->name);
295 $dir = (empty($outputdir) ? $conf->adherent->dir_temp : $outputdir);
296 $file = $dir.
"/".$filename;
298 if (!file_exists($dir)) {
300 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
305 $pdf =
pdf_getInstance($this->format, $this->Tformat[
'metric'], $this->Tformat[
'orientation']);
307 if (class_exists(
'TCPDF')) {
308 $pdf->setPrintHeader(
false);
309 $pdf->setPrintFooter(
false);
313 $pdf->SetTitle($title);
314 $pdf->SetSubject($title);
315 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
316 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
317 $pdf->SetKeyWords($keywords);
319 $pdf->SetCompression(
false);
322 $pdf->SetMargins(0, 0);
323 $pdf->SetAutoPageBreak(
false);
325 $this->_Metric_Doc = $this->Tformat[
'metric'];
339 $this->_COUNTX = $posX;
340 $this->_COUNTY = $posY;
349 foreach ($arrayofrecords as $val) {
359 $pdf->Output($file,
'F');
363 $this->result = array(
'fullpath'=>$file);