65 public function Add_PDF_label(&$pdf, $textleft, $header, $footer, $outputlangs, $textright =
'', $photo =
'')
68 global $mysoc,
$conf, $langs;
69 global $forceimgscalewidth, $forceimgscaleheight;
71 $imgscalewidth = (empty($forceimgscalewidth) ? 0.3 : $forceimgscalewidth);
72 $imgscaleheight = (empty($forceimgscaleheight) ? 0.5 : $forceimgscaleheight);
75 if (($this->_COUNTX == 0) && ($this->_COUNTY == 0) and (!$this->_First == 1)) {
79 $_PosX = $this->_Margin_Left + ($this->_COUNTX * ($this->_Width + $this->_X_Space));
80 $_PosY = $this->_Margin_Top + ($this->_COUNTY * ($this->_Height + $this->_Y_Space));
83 $logo =
$conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
84 if (!is_readable($logo)) {
86 if (!empty($mysoc->logo_small) && is_readable(
$conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small)) {
87 $logo =
$conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small;
88 } elseif (!empty($mysoc->logo) && is_readable(
$conf->mycompany->dir_output.
'/logos/'.$mysoc->logo)) {
89 $logo =
$conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
95 if (!is_readable($photo)) {
101 $backgroundimage =
'';
104 if ($this->code ==
"CARD") {
105 $this->Tformat = $this->_Avery_Labels[
"CARD"];
107 $this->
_Croix($pdf, $_PosX, $_PosY, $_PosX + $this->_Width, $_PosY + $this->_Height, 0.1, 10);
111 if ($backgroundimage) {
112 $pdf->image($backgroundimage, $_PosX, $_PosY, $this->_Width, $this->_Height);
120 if ($this->code ==
"CARD") {
121 $pdf->SetDrawColor(128, 128, 128);
122 $pdf->Line($_PosX, $_PosY + $this->_Line_Height + 1, $_PosX + $this->_Width, $_PosY + $this->_Line_Height + 1);
123 $pdf->SetDrawColor(0, 0, 0);
125 $pdf->SetXY($_PosX + $xleft, $_PosY + 1);
126 $pdf->Cell($this->_Width - 2 * $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($header), 0, 1,
'C');
130 $ytop += (empty($header) ? 0 : (1 + $this->_Line_Height));
133 $maxwidthtouse = round(($this->_Width - 2 * $xleft) * $imgscalewidth);
134 $maxheighttouse = round(($this->_Height - 2 * $ytop) * $imgscaleheight);
135 $defaultratio = ($maxwidthtouse / $maxheighttouse);
136 $widthtouse = $maxwidthtouse;
139 if (!empty($tmp[
'height'])) {
140 $imgratio = $tmp[
'width'] / $tmp[
'height'];
141 if ($imgratio >= $defaultratio) {
142 $widthtouse = $maxwidthtouse;
143 $heighttouse = round($widthtouse / $imgratio);
145 $heighttouse = $maxheighttouse;
146 $widthtouse = round($heighttouse * $imgratio);
152 if ($textright ==
'') {
154 if ($textleft ==
'%LOGO%' && $logo) {
155 $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
156 } elseif ($textleft ==
'%PHOTO%' && $photo) {
157 $pdf->Image($photo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
159 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
160 $pdf->MultiCell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
162 } elseif ($textleft !=
'' && $textright !=
'') {
163 if ($textleft ==
'%LOGO%' || $textleft ==
'%PHOTO%') {
164 if ($textleft ==
'%LOGO%' && $logo) {
165 $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
166 } elseif ($textleft ==
'%PHOTO%' && $photo) {
167 $pdf->Image($photo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
169 $pdf->SetXY($_PosX + $xleft + $widthtouse + 1, $_PosY + $ytop);
170 $pdf->MultiCell($this->_Width - $xleft - $xleft - $widthtouse - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
171 } elseif ($textright ==
'%LOGO%' || $textright ==
'%PHOTO%') {
172 if ($textright ==
'%LOGO%' && $logo) {
173 $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
174 } elseif ($textright ==
'%PHOTO%' && $photo) {
175 $pdf->Image($photo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
177 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
178 $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');
187 if ($textright ==
'%LOGO%' && $logo) {
188 $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
189 } elseif ($textright ==
'%PHOTO%' && $photo) {
190 $pdf->Image($photo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
192 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
193 $pdf->MultiCell($this->_Width - $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
199 if ($this->code ==
"CARD") {
200 $pdf->SetDrawColor(128, 128, 128);
201 $pdf->Line($_PosX, $_PosY + $this->_Height - $this->_Line_Height - 2, $_PosX + $this->_Width, $_PosY + $this->_Height - $this->_Line_Height - 2);
202 $pdf->SetDrawColor(0, 0, 0);
204 $pdf->SetXY($_PosX, $_PosY + $this->_Height - $this->_Line_Height - 1);
205 $pdf->Cell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($footer), 0, 1,
'C');
211 if ($this->_COUNTY == $this->_Y_Number) {
217 if ($this->_COUNTX == $this->_X_Number) {
238 public function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir =
'', $filename =
'tmp_address_sheet.pdf')
241 global $user,
$conf, $langs, $mysoc, $_Avery_Labels;
243 $this->code = $srctemplatepath;
244 $this->Tformat = $_Avery_Labels[$this->code];
245 if (empty($this->Tformat)) {
251 $paper_size = $this->Tformat[
'paper-size'];
252 if (!is_string($paper_size) || $paper_size !=
'custom') {
253 $this->format = $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;
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);