103 global $mysoc,
$conf;
105 $textleft = $param[
'textleft'];
106 $header = $param[
'textheader'];
107 $footer = $param[
'textfooter'];
108 $textright = $param[
'textright'];
109 $code = $param[
'code'];
110 $encoding = $param[
'encoding'];
111 $is2d = $param[
'is2d'];
116 if (($this->_COUNTX == 0) && ($this->_COUNTY == 0) and (!$this->_First == 1)) {
120 $_PosX = $this->_Margin_Left + ($this->_COUNTX * ($this->_Width + $this->_X_Space));
121 $_PosY = $this->_Margin_Top + ($this->_COUNTY * ($this->_Height + $this->_Y_Space));
124 $logo =
$conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
125 if (!is_readable($logo)) {
127 if (!empty($mysoc->logo_small) && is_readable(
$conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small)) {
128 $logo =
$conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small;
129 } elseif (!empty($mysoc->logo) && is_readable(
$conf->mycompany->dir_output.
'/logos/'.$mysoc->logo)) {
130 $logo =
$conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
139 $pdf->SetXY($_PosX + $xleft, $_PosY + 1);
140 $pdf->Cell(2 * strlen($header), $this->_Line_Height, $outputlangs->convToOutputCharset($header), 0, 1,
'C');
143 $ytop += (empty($header) ? 0 : (1 + $this->_Line_Height));
146 $pageMargins = $pdf->getMargins();
147 $maxwidthtouse = round($this->_Width - 2 * $xleft);
148 $maxheighttouse = round($this->_Height - 2 * $ytop);
149 $maxheighttouse -= (empty($footer) ? 0 : (1 + $this->_Line_Height));
150 $defaultratio = ($maxwidthtouse / $maxheighttouse);
151 $widthtouse = $maxwidthtouse;
152 $heighttouse = $maxheighttouse;
153 $logoHeight = $heighttouse;
154 $logoWidth = $widthtouse;
159 if ($textright ==
'') {
161 if ($textleft ==
'%LOGO%' && $logo) {
162 $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, 0, $logoHeight);
163 } elseif ($code && !empty($encoding)) {
164 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
166 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
167 $pdf->MultiCell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
169 } elseif ($textleft !=
'' && $textright !=
'') {
170 $logoHeight = $heighttouse / 2;
171 $logoWidth = $widthtouse / 2;
172 if (($textleft ==
'%LOGO%' || $textleft ==
'%PHOTO%' || $textleft ==
'%BARCODE%') && !strstr($textright,
'%')) {
173 if ($textleft ==
'%LOGO%' && $logo) {
174 $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, $logoWidth, 0);
175 } elseif ($code && !empty($encoding)) {
176 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft, $_PosY + $ytop, $widthtouse / 2, $heighttouse);
178 $pdf->SetXY($_PosX + ($widthtouse / 2), $_PosY + $ytop);
179 $pdf->MultiCell($widthtouse / 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
180 } elseif (($textright ==
'%LOGO%' || $textright ==
'%PHOTO%' || $textright ==
'%BARCODE%') && !strstr($textleft,
'%')) {
181 if ($textright ==
'%LOGO%' && $logo) {
182 $pdf->Image($logo, $_PosX + ($widthtouse / 2), $_PosY + $ytop, $logoWidth, 0);
183 } elseif ($code && !empty($encoding)) {
184 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + ($widthtouse / 2), $_PosY + $ytop, $widthtouse / 2, $heighttouse);
186 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
187 $pdf->MultiCell($widthtouse / 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
188 } elseif ($textleft ==
'%LOGO%') {
190 $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, 0, $logoHeight);
192 if ($code && !empty($encoding)) {
193 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft + $logoWidth + 1, $_PosY + $ytop, $widthtouse - $logoWidth - 1, $heighttouse);
195 $pdf->SetXY($_PosX + $xleft + $logoWidth + 1, $_PosY + $ytop);
196 $pdf->MultiCell($widthtouse - $logoWidth - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
198 } elseif ($textright ==
'%LOGO%') {
200 $pdf->Image($logo, $_PosX + $xleft + $widthtouse - $logoWidth + 1, $_PosY + $ytop, 0, $logoHeight);
202 if ($code && !empty($encoding)) {
203 $this->
writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft, $_PosY + $ytop, $widthtouse - $logoWidth - 1, $heighttouse);
205 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
206 $pdf->MultiCell($widthtouse - $logoWidth - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
209 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
210 $pdf->MultiCell(round($this->_Width / 2), $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
211 $pdf->SetXY($_PosX + round($this->_Width / 2), $_PosY + $ytop);
212 $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 $paper_size = $this->Tformat[
'paper-size'];
276 if (!is_string($paper_size) || $paper_size !=
'custom') {
277 $this->format = $paper_size;
280 $resolution = array($this->Tformat[
'custom_x'], $this->Tformat[
'custom_y']);
281 $this->format = $resolution;
284 if (!is_object($outputlangs)) {
285 $outputlangs = $langs;
289 $outputlangs->charset_output =
'ISO-8859-1';
293 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"admin"));
295 $title = $outputlangs->transnoentities(
'Labels');
296 $keywords = $title.
" ".$outputlangs->convToOutputCharset($mysoc->name);
298 $dir = (empty($outputdir) ?
$conf->adherent->dir_temp : $outputdir);
299 $file = $dir.
"/".$filename;
301 if (!file_exists($dir)) {
303 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
308 $pdf =
pdf_getInstance($this->format, $this->Tformat[
'metric'], $this->Tformat[
'orientation']);
310 if (class_exists(
'TCPDF')) {
311 $pdf->setPrintHeader(
false);
312 $pdf->setPrintFooter(
false);
316 $pdf->SetTitle($title);
317 $pdf->SetSubject($title);
318 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
319 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
320 $pdf->SetKeyWords($keywords);
322 $pdf->SetCompression(
false);
325 $pdf->SetMargins(0, 0);
326 $pdf->SetAutoPageBreak(
false);
328 $this->_Metric_Doc = $this->Tformat[
'metric'];
342 $this->_COUNTX = $posX;
343 $this->_COUNTY = $posY;
352 foreach ($arrayofrecords as $val) {
362 $pdf->Output($file,
'F');
366 $this->result = array(
'fullpath' => $file);