64 public function Add_PDF_label(&$pdf, $textleft, $header, $footer, $outputlangs, $textright =
'', $photo =
'')
67 global $mysoc, $conf, $langs;
68 global $forceimgscalewidth, $forceimgscaleheight;
70 $imgscalewidth = (empty($forceimgscalewidth) ? 0.3 : $forceimgscalewidth);
71 $imgscaleheight = (empty($forceimgscaleheight) ? 0.5 : $forceimgscaleheight);
74 if (($this->_COUNTX == 0) && ($this->_COUNTY == 0) and (!$this->_First == 1)) {
78 $_PosX = $this->_Margin_Left + ($this->_COUNTX * ($this->_Width + $this->_X_Space));
79 $_PosY = $this->_Margin_Top + ($this->_COUNTY * ($this->_Height + $this->_Y_Space));
82 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
83 if (!is_readable($logo)) {
85 if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small)) {
86 $logo = $conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small;
87 } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.
'/logos/'.$mysoc->logo)) {
88 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
94 if (!is_readable($photo)) {
100 $backgroundimage =
'';
103 if ($this->code ==
"CARD") {
104 $this->Tformat = $this->_Avery_Labels[
"CARD"];
106 $this->
_Croix($pdf, $_PosX, $_PosY, $_PosX + $this->_Width, $_PosY + $this->_Height, 0.1, 10);
110 if ($backgroundimage) {
111 $pdf->image($backgroundimage, $_PosX, $_PosY, $this->_Width, $this->_Height);
119 if ($this->code ==
"CARD") {
120 $pdf->SetDrawColor(128, 128, 128);
121 $pdf->Line($_PosX, $_PosY + $this->_Line_Height + 1, $_PosX + $this->_Width, $_PosY + $this->_Line_Height + 1);
122 $pdf->SetDrawColor(0, 0, 0);
124 $pdf->SetXY($_PosX + $xleft, $_PosY + 1);
125 $pdf->Cell($this->_Width - 2 * $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($header), 0, 1,
'C');
129 $ytop += (empty($header) ? 0 : (1 + $this->_Line_Height));
132 $maxwidthtouse = round(($this->_Width - 2 * $xleft) * $imgscalewidth);
133 $maxheighttouse = round(($this->_Height - 2 * $ytop) * $imgscaleheight);
134 $defaultratio = ($maxwidthtouse / $maxheighttouse);
135 $widthtouse = $maxwidthtouse;
138 if (!empty($tmp[
'height'])) {
139 $imgratio = $tmp[
'width'] / $tmp[
'height'];
140 if ($imgratio >= $defaultratio) {
141 $widthtouse = $maxwidthtouse;
142 $heighttouse = round($widthtouse / $imgratio);
144 $heighttouse = $maxheighttouse;
145 $widthtouse = round($heighttouse * $imgratio);
151 if ($textright ==
'') {
153 if ($textleft ==
'%LOGO%' && $logo) {
154 $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
155 } elseif ($textleft ==
'%PHOTO%' && $photo) {
156 $pdf->Image($photo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
158 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
159 $pdf->MultiCell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
161 } elseif ($textleft !=
'' && $textright !=
'') {
162 if ($textleft ==
'%LOGO%' || $textleft ==
'%PHOTO%') {
163 if ($textleft ==
'%LOGO%' && $logo) {
164 $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
165 } elseif ($textleft ==
'%PHOTO%' && $photo) {
166 $pdf->Image($photo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
168 $pdf->SetXY($_PosX + $xleft + $widthtouse + 1, $_PosY + $ytop);
169 $pdf->MultiCell($this->_Width - $xleft - $xleft - $widthtouse - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
170 } elseif ($textright ==
'%LOGO%' || $textright ==
'%PHOTO%') {
171 if ($textright ==
'%LOGO%' && $logo) {
172 $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
173 } elseif ($textright ==
'%PHOTO%' && $photo) {
174 $pdf->Image($photo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
176 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
177 $pdf->MultiCell($this->_Width - $widthtouse - $xleft - $xleft - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
179 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
180 $pdf->MultiCell(round($this->_Width / 2), $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
181 $pdf->SetXY($_PosX + round($this->_Width / 2), $_PosY + $ytop);
182 $pdf->MultiCell(round($this->_Width / 2) - 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
186 if ($textright ==
'%LOGO%' && $logo) {
187 $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
188 } elseif ($textright ==
'%PHOTO%' && $photo) {
189 $pdf->Image($photo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
191 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
192 $pdf->MultiCell($this->_Width - $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
198 if ($this->code ==
"CARD") {
199 $pdf->SetDrawColor(128, 128, 128);
200 $pdf->Line($_PosX, $_PosY + $this->_Height - $this->_Line_Height - 2, $_PosX + $this->_Width, $_PosY + $this->_Height - $this->_Line_Height - 2);
201 $pdf->SetDrawColor(0, 0, 0);
203 $pdf->SetXY($_PosX, $_PosY + $this->_Height - $this->_Line_Height - 1);
204 $pdf->Cell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($footer), 0, 1,
'C');
210 if ($this->_COUNTY == $this->_Y_Number) {
216 if ($this->_COUNTX == $this->_X_Number) {
237 public function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir =
'', $filename =
'tmp_address_sheet.pdf')
240 global $user, $conf, $langs, $mysoc, $_Avery_Labels;
242 $this->code = $srctemplatepath;
243 $this->Tformat = $_Avery_Labels[$this->code];
244 if (empty($this->Tformat)) {
250 if ($this->Tformat[
'paper-size'] !=
'custom') {
251 $this->format = $this->Tformat[
'paper-size'];
254 $resolution = array($this->Tformat[
'custom_x'], $this->Tformat[
'custom_y']);
255 $this->format = $resolution;
258 if (!is_object($outputlangs)) {
259 $outputlangs = $langs;
263 $outputlangs->charset_output =
'ISO-8859-1';
267 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"admin"));
269 $title = $outputlangs->transnoentities(
'Labels');
270 $keywords = $title.
" ".$outputlangs->convToOutputCharset($mysoc->name);
272 $dir = (empty($outputdir) ? $conf->adherent->dir_temp : $outputdir);
273 $file = $dir.
"/".$filename;
275 if (!file_exists($dir)) {
277 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
282 $pdf =
pdf_getInstance($this->format, $this->Tformat[
'metric'], $this->Tformat[
'orientation']);
284 if (class_exists(
'TCPDF')) {
285 $pdf->setPrintHeader(
false);
286 $pdf->setPrintFooter(
false);
290 $pdf->SetTitle($title);
291 $pdf->SetSubject($title);
292 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
293 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
294 $pdf->SetKeyWords($keywords);
296 $pdf->SetCompression(
false);
299 $pdf->SetMargins(0, 0);
300 $pdf->SetAutoPageBreak(
false);
302 $this->_Metric_Doc = $this->Tformat[
'metric'];
316 $this->_COUNTX = $posX;
317 $this->_COUNTY = $posY;
326 foreach ($arrayofrecords as $val) {
328 $this->
Add_PDF_label($pdf, $val[
'textleft'], $val[
'textheader'], $val[
'textfooter'], $langs, $val[
'textright'], $val[
'photo']);
336 $pdf->Output($file,
'F');
340 $this->result = array(
'fullpath'=>$file);