115 global $mysoc,
$conf;
117 $textleft = $param[
'textleft'];
118 $header = $param[
'textheader'];
119 $footer = $param[
'textfooter'];
120 $textright = $param[
'textright'];
121 $code = $param[
'code'];
122 $encoding = $param[
'encoding'];
123 $is2d = $param[
'is2d'];
128 if (($this->_COUNTX == 0) && ($this->_COUNTY == 0) and (!$this->_First == 1)) {
132 $_PosX = $this->_Margin_Left + ($this->_COUNTX * ($this->_Width + $this->_X_Space));
133 $_PosY = $this->_Margin_Top + ($this->_COUNTY * ($this->_Height + $this->_Y_Space));
136 $logo =
$conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
137 if (!is_readable($logo)) {
139 if (!empty($mysoc->logo_small) && is_readable(
$conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small)) {
140 $logo =
$conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small;
141 } elseif (!empty($mysoc->logo) && is_readable(
$conf->mycompany->dir_output.
'/logos/'.$mysoc->logo)) {
142 $logo =
$conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
151 $pdf->SetXY($_PosX + $xleft, $_PosY + 1);
152 $pdf->Cell(2 * strlen($header), $this->_Line_Height, $outputlangs->convToOutputCharset($header), 0, 1,
'C');
155 $ytop += (empty($header) ? 0 : (1 + $this->_Line_Height));
158 $pageMargins = $pdf->getMargins();
159 $maxwidthtouse = round($this->_Width - 2 * $xleft);
160 $maxheighttouse = round($this->_Height - 2 * $ytop);
161 $maxheighttouse -= (empty($footer) ? 0 : (1 + $this->_Line_Height));
162 $defaultratio = ($maxwidthtouse / $maxheighttouse);
163 $widthtouse = $maxwidthtouse;
164 $heighttouse = $maxheighttouse;
165 $logoHeight = $heighttouse;
166 $logoWidth = $widthtouse;
171 if ($textright ==
'') {
173 if ($textleft ==
'%LOGO%' && $logo) {
174 $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, 0, $logoHeight);
175 } elseif ($code && !empty($encoding)) {
176 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
178 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
179 $pdf->MultiCell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
181 } elseif ($textleft !=
'' && $textright !=
'') {
182 $logoHeight = $heighttouse / 2;
183 $logoWidth = $widthtouse / 2;
184 if (($textleft ==
'%LOGO%' || $textleft ==
'%PHOTO%' || $textleft ==
'%BARCODE%') && !strstr($textright,
'%')) {
185 if ($textleft ==
'%LOGO%' && $logo) {
186 $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, $logoWidth, 0);
187 } elseif ($code && !empty($encoding)) {
188 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft, $_PosY + $ytop, $widthtouse / 2, $heighttouse);
190 $pdf->SetXY($_PosX + ($widthtouse / 2), $_PosY + $ytop);
191 $pdf->MultiCell($widthtouse / 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
192 } elseif (($textright ==
'%LOGO%' || $textright ==
'%PHOTO%' || $textright ==
'%BARCODE%') && !strstr($textleft,
'%')) {
193 if ($textright ==
'%LOGO%' && $logo) {
194 $pdf->Image($logo, $_PosX + ($widthtouse / 2), $_PosY + $ytop, $logoWidth, 0);
195 } elseif ($code && !empty($encoding)) {
196 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + ($widthtouse / 2), $_PosY + $ytop, $widthtouse / 2, $heighttouse);
198 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
199 $pdf->MultiCell($widthtouse / 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
200 } elseif ($textleft ==
'%LOGO%') {
202 $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, 0, $logoHeight);
204 if ($code && !empty($encoding)) {
205 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft + $logoWidth + 1, $_PosY + $ytop, $widthtouse - $logoWidth - 1, $heighttouse);
207 $pdf->SetXY($_PosX + $xleft + $logoWidth + 1, $_PosY + $ytop);
208 $pdf->MultiCell($widthtouse - $logoWidth - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
210 } elseif ($textright ==
'%LOGO%') {
212 $pdf->Image($logo, $_PosX + $xleft + $widthtouse - $logoWidth + 1, $_PosY + $ytop, 0, $logoHeight);
214 if ($code && !empty($encoding)) {
215 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft, $_PosY + $ytop, $widthtouse - $logoWidth - 1, $heighttouse);
217 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
218 $pdf->MultiCell($widthtouse - $logoWidth - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
221 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
222 $pdf->MultiCell(round($this->_Width / 2), $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
223 $pdf->SetXY($_PosX + round($this->_Width / 2), $_PosY + $ytop);
224 $pdf->MultiCell(round($this->_Width / 2) - 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
228 if ($textright ==
'%LOGO%' && $logo) {
229 $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, 0, $logoHeight);
230 } elseif ($code && !empty($encoding)) {
231 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
233 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
234 $pdf->MultiCell($this->_Width - $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
240 $pdf->SetXY($_PosX, $_PosY + $this->_Height - $this->_Line_Height - 1);
241 $pdf->Cell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($footer), 0, 1,
'C');
247 if ($this->_COUNTY == $this->_Y_Number) {
253 if ($this->_COUNTX == $this->_X_Number) {
274 public function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir =
'', $filename =
'tmp_address_sheet.pdf')
277 global $user,
$conf, $langs, $mysoc, $_Avery_Labels;
279 $this->code = $srctemplatepath;
280 $this->Tformat = $_Avery_Labels[$this->code];
281 if (empty($this->Tformat)) {
287 $paper_size = $this->Tformat[
'paper-size'];
288 if (!is_string($paper_size) || $paper_size !=
'custom') {
289 $this->format = $paper_size;
292 $resolution = array($this->Tformat[
'custom_x'], $this->Tformat[
'custom_y']);
293 $this->format = $resolution;
296 if (!is_object($outputlangs)) {
297 $outputlangs = $langs;
301 $outputlangs->charset_output =
'ISO-8859-1';
305 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"admin"));
307 $title = $outputlangs->transnoentities(
'Labels');
308 $keywords = $title.
" ".$outputlangs->convToOutputCharset($mysoc->name);
310 $dir = (empty($outputdir) ?
$conf->adherent->dir_temp : $outputdir);
311 $file = $dir.
"/".$filename;
313 if (!file_exists($dir)) {
315 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
320 $pdf =
pdf_getInstance($this->format, $this->Tformat[
'metric'], $this->Tformat[
'orientation']);
322 if (class_exists(
'TCPDF')) {
323 $pdf->setPrintHeader(
false);
324 $pdf->setPrintFooter(
false);
328 $pdf->SetTitle($title);
329 $pdf->SetSubject($title);
330 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
331 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
332 $pdf->SetKeyWords($keywords);
334 $pdf->SetCompression(
false);
337 $pdf->SetMargins(0, 0);
338 $pdf->setAutoPageBreak(
false);
340 $this->_Metric_Doc = $this->Tformat[
'metric'];
354 $this->_COUNTX = $posX;
355 $this->_COUNTY = $posY;
364 foreach ($arrayofrecords as $val) {
374 $pdf->Output($file,
'F');
378 $this->result = array(
'fullpath' => $file);