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');
180 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
181 $pdf->MultiCell(round($this->_Width / 2), $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
182 $pdf->SetXY($_PosX + round($this->_Width / 2), $_PosY + $ytop);
183 $pdf->MultiCell(round($this->_Width / 2) - 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
188 if ($textright ==
'%LOGO%' && $logo) {
189 $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
190 } elseif ($textright ==
'%PHOTO%' && $photo) {
191 $pdf->Image($photo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
193 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
194 $pdf->MultiCell($this->_Width - $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
200 if ($this->code ==
"CARD") {
201 $pdf->SetDrawColor(128, 128, 128);
202 $pdf->Line($_PosX, $_PosY + $this->_Height - $this->_Line_Height - 2, $_PosX + $this->_Width, $_PosY + $this->_Height - $this->_Line_Height - 2);
203 $pdf->SetDrawColor(0, 0, 0);
205 $pdf->SetXY($_PosX, $_PosY + $this->_Height - $this->_Line_Height - 1);
206 $pdf->Cell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($footer), 0, 1,
'C');
212 if ($this->_COUNTY == $this->_Y_Number) {
218 if ($this->_COUNTX == $this->_X_Number) {
239 public function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir =
'', $filename =
'tmp_address_sheet.pdf')
242 global $user, $conf, $langs, $mysoc, $_Avery_Labels;
244 $this->code = $srctemplatepath;
245 $this->Tformat = $_Avery_Labels[$this->code];
246 if (empty($this->Tformat)) {
252 if ($this->Tformat[
'paper-size'] !=
'custom') {
253 $this->format = $this->Tformat[
'paper-size'];
256 $resolution = array($this->Tformat[
'custom_x'], $this->Tformat[
'custom_y']);
257 $this->format = $resolution;
260 if (!is_object($outputlangs)) {
261 $outputlangs = $langs;
264 if (!empty($conf->global->MAIN_USE_FPDF)) {
265 $outputlangs->charset_output =
'ISO-8859-1';
269 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"admin"));
271 $title = $outputlangs->transnoentities(
'Labels');
272 $keywords = $title.
" ".$outputlangs->convToOutputCharset($mysoc->name);
274 $dir = (empty($outputdir) ? $conf->adherent->dir_temp : $outputdir);
275 $file = $dir.
"/".$filename;
277 if (!file_exists($dir)) {
279 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
284 $pdf =
pdf_getInstance($this->format, $this->Tformat[
'metric'], $this->Tformat[
'orientation']);
286 if (class_exists(
'TCPDF')) {
287 $pdf->setPrintHeader(
false);
288 $pdf->setPrintFooter(
false);
292 $pdf->SetTitle($title);
293 $pdf->SetSubject($title);
294 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
295 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
296 $pdf->SetKeyWords($keywords);
298 $pdf->SetCompression(
false);
301 $pdf->SetMargins(0, 0);
302 $pdf->SetAutoPageBreak(
false);
304 $this->_Metric_Doc = $this->Tformat[
'metric'];
318 $this->_COUNTX = $posX;
319 $this->_COUNTY = $posY;
328 foreach ($arrayofrecords as $val) {
330 $this->
Add_PDF_label($pdf, $val[
'textleft'], $val[
'textheader'], $val[
'textfooter'], $langs, $val[
'textright'], $val[
'photo']);
338 $pdf->Output($file,
'F');
342 $this->result = array(
'fullpath'=>$file);