188 public function write_file($object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
191 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
194 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
196 if (!is_object($outputlangs)) {
197 $outputlangs = $langs;
201 $outputlangs->charset_output =
'ISO-8859-1';
205 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
207 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
208 global $outputlangsbis;
209 $outputlangsbis =
new Translate(
'', $conf);
210 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
211 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
214 $nblines = (is_array($object->lines) ? count($object->lines) : 0);
218 $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
222 $realpatharray = array();
278 if ($conf->recruitment->dir_output.
'/recruitmentjobposition') {
279 $object->fetch_thirdparty();
282 if ($object->specimen) {
283 $dir = $conf->recruitment->dir_output.
'/recruitmentjobposition';
284 $file = $dir.
"/SPECIMEN.pdf";
287 $dir = $conf->recruitment->dir_output.
'/recruitmentjobposition/'.$objectref;
288 $file = $dir.
"/".$objectref.
".pdf";
290 if (!file_exists($dir)) {
292 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
297 if (file_exists($dir)) {
299 $hookmanager->initHooks(array(
'pdfgeneration'));
300 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
301 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
304 $nblines = (is_array($object->lines) ? count($object->lines) : 0);
309 $pdf->SetAutoPageBreak(1, 0);
311 $heightforinfotot = 50;
312 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
313 $heightforfooter = $this->marge_basse + (!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22);
315 if (class_exists(
'TCPDF')) {
316 $pdf->setPrintHeader(
false);
317 $pdf->setPrintFooter(
false);
323 $logodir = $conf->mycompany->dir_output;
324 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
325 $logodir = $conf->mycompany->multidir_output[$object->entity];
327 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
328 $tplidx = $pdf->importPage(1);
333 $pdf->SetDrawColor(128, 128, 128);
335 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
336 $pdf->SetSubject($object->label);
337 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
338 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
339 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$object->label.
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
341 $pdf->SetCompression(
false);
345 $cert = empty($user->conf->CERTIFICATE_CRT) ?
'' : $user->conf->CERTIFICATE_CRT;
353 'Name' => $this->emetteur->name,
354 'Location' =>
getCountry($this->emetteur->country_code, 0),
355 'Reason' =>
'MYOBJECT',
356 'ContactInfo' => $this->emetteur->email
358 $pdf->setSignature($cert, $cert, $this->emetteur->name,
'', 2, $info);
361 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
365 if (!empty($tplidx)) {
366 $pdf->useTemplate($tplidx);
370 $top_shift = $this->
_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
371 $pdf->SetFont(
'',
'', $default_font_size - 1);
372 $pdf->MultiCell(0, 3,
'');
373 $pdf->SetTextColor(0, 0, 0);
375 $tab_top = 90 + $top_shift;
376 $tab_top_newpage = (!
getDolGlobalString(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
377 $tab_height = 130 - $top_shift;
378 $tab_height_newpage = 150;
380 $tab_height_newpage -= $top_shift;
383 $nexY = $tab_top - 1;
386 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
388 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
389 if (!empty($extranote)) {
393 $pagenb = $pdf->getPage();
397 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
398 $pageposbeforenote = $pagenb;
405 $pdf->startTransaction();
407 $pdf->SetFont(
'',
'', $default_font_size - 1);
408 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
410 $pageposafternote = $pdf->getPage();
411 $posyafter = $pdf->GetY();
413 if ($pageposafternote > $pageposbeforenote) {
414 $pdf->rollbackTransaction(
true);
417 while ($pagenb < $pageposafternote) {
420 if (!empty($tplidx)) {
421 $pdf->useTemplate($tplidx);
424 $this->
_pagehead($pdf, $object, 0, $outputlangs);
427 $pdf->setTopMargin($tab_top_newpage);
429 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
433 $pdf->setPage($pageposbeforenote);
434 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
435 $pdf->SetFont(
'',
'', $default_font_size - 1);
436 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
437 $pageposafternote = $pdf->getPage();
439 $posyafter = $pdf->GetY();
441 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
442 $pdf->AddPage(
'',
'',
true);
445 $pdf->setPage($pageposafternote);
446 $pdf->setTopMargin($tab_top_newpage);
448 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
454 $i = $pageposbeforenote;
455 while ($i < $pageposafternote) {
459 $pdf->SetDrawColor(128, 128, 128);
461 if ($i > $pageposbeforenote) {
462 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
463 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
465 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
466 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
470 $pdf->setPageOrientation(
'', 1, 0);
471 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
477 $pdf->setPage($pageposafternote);
478 if (!empty($tplidx)) {
479 $pdf->useTemplate($tplidx);
482 $this->
_pagehead($pdf, $object, 0, $outputlangs);
484 $height_note = $posyafter - $tab_top_newpage;
485 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
487 $pdf->commitTransaction();
488 $posyafter = $pdf->GetY();
489 $height_note = $posyafter - $tab_top;
490 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
492 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
494 $pdf->AddPage(
'',
'',
true);
497 $pdf->setPage($pageposafternote);
498 if (!empty($tplidx)) {
499 $pdf->useTemplate($tplidx);
502 $this->
_pagehead($pdf, $object, 0, $outputlangs);
505 $posyafter = $tab_top_newpage;
509 $tab_height = $tab_height - $height_note;
510 $tab_top = $posyafter + 6;
519 $pdf->startTransaction();
520 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
521 $pdf->rollbackTransaction(
true);
523 $nexY = $tab_top + $this->tabTitleHeight;
526 $pageposbeforeprintlines = $pdf->getPage();
527 $pagenb = $pageposbeforeprintlines;
528 for ($i = 0; $i < $nblines; $i++) {
530 $pdf->SetFont(
'',
'', $default_font_size - 1);
531 $pdf->SetTextColor(0, 0, 0);
534 $imglinesize = array();
535 if (!empty($realpatharray[$i])) {
539 $pdf->setTopMargin($tab_top_newpage);
540 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
541 $pageposbefore = $pdf->getPage();
543 $showpricebeforepagebreak = 1;
548 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
549 $pdf->AddPage(
'',
'',
true);
550 if (!empty($tplidx)) {
551 $pdf->useTemplate($tplidx);
553 $pdf->setPage($pageposbefore + 1);
555 $curY = $tab_top_newpage;
559 $showpricebeforepagebreak = 1;
561 $showpricebeforepagebreak = 0;
565 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
566 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
568 $posYAfterImage = $curY + $imglinesize[
'height'];
574 $pdf->startTransaction();
576 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
577 $pageposafter = $pdf->getPage();
579 if ($pageposafter > $pageposbefore) {
580 $pdf->rollbackTransaction(
true);
581 $pdf->setPageOrientation(
'', 1, $heightforfooter);
583 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
585 $pageposafter = $pdf->getPage();
586 $posyafter = $pdf->GetY();
589 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
590 if ($i == ($nblines - 1)) {
591 $pdf->AddPage(
'',
'',
true);
592 if (!empty($tplidx)) {
593 $pdf->useTemplate($tplidx);
595 $pdf->setPage($pageposafter + 1);
601 $showpricebeforepagebreak = 1;
603 $showpricebeforepagebreak = 0;
607 $pdf->commitTransaction();
611 $nexY = $pdf->GetY();
612 $pageposafter = $pdf->getPage();
613 $pdf->setPage($pageposbefore);
614 $pdf->setTopMargin($this->marge_haute);
615 $pdf->setPageOrientation(
'', 1, 0);
618 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
619 $pdf->setPage($pageposafter);
620 $curY = $tab_top_newpage;
623 $pdf->SetFont(
'',
'', $default_font_size - 1);
633 'outputlangs' => $outputlangs,
634 'hidedetails' => $hidedetails
636 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
641 while ($pagenb < $pageposafter) {
642 $pdf->setPage($pagenb);
643 if ($pagenb == $pageposbeforeprintlines) {
644 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
646 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
648 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
650 $pdf->setPage($pagenb);
651 $pdf->setPageOrientation(
'', 1, 0);
653 $this->
_pagehead($pdf, $object, 0, $outputlangs);
655 if (!empty($tplidx)) {
656 $pdf->useTemplate($tplidx);
660 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
661 if ($pagenb == $pageposafter) {
662 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
664 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
666 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
669 if (!empty($tplidx)) {
670 $pdf->useTemplate($tplidx);
674 $this->
_pagehead($pdf, $object, 0, $outputlangs);
680 if ($pagenb == $pageposbeforeprintlines) {
681 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code, $outputlangsbis);
682 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
684 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code, $outputlangsbis);
685 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
703 $this->
_pagefoot($pdf, $object, $outputlangs);
704 if (method_exists($pdf,
'AliasNbPages')) {
705 $pdf->AliasNbPages();
710 $pdf->Output($file,
'F');
713 $hookmanager->initHooks(array(
'pdfgeneration'));
714 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
716 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
718 $this->error = $hookmanager->error;
719 $this->errors = $hookmanager->errors;
724 $this->result = array(
'fullpath'=>$file);
728 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
732 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
815 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis =
null)
817 global $conf, $langs;
820 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
827 if ($object->statut == $object::STATUS_DRAFT &&
getDolGlobalString(
'RECRUITMENT_RECRUITMENTJOBPOSITION_DRAFT_WATERMARK')) {
828 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur,
'mm',
getDolGlobalString(
'RECRUITMENT_RECRUITMENTJOBPOSITION_DRAFT_WATERMARK'));
831 $pdf->SetTextColor(0, 0, 60);
832 $pdf->SetFont(
'',
'B', $default_font_size + 3);
836 $posy = $this->marge_haute;
837 $posx = $this->page_largeur - $this->marge_droite - $w;
839 $pdf->SetXY($this->marge_gauche, $posy);
843 if ($this->emetteur->logo) {
844 $logodir = $conf->mycompany->dir_output;
845 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
846 $logodir = $conf->mycompany->multidir_output[$object->entity];
849 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
851 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
853 if (is_readable($logo)) {
855 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
857 $pdf->SetTextColor(200, 0, 0);
858 $pdf->SetFont(
'',
'B', $default_font_size - 2);
859 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
860 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
863 $text = $this->emetteur->name;
864 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
868 $pdf->SetFont(
'',
'B', $default_font_size + 3);
869 $pdf->SetXY($posx, $posy);
870 $pdf->SetTextColor(0, 0, 60);
871 $title = $object->label;
876 $pdf->MultiCell($w, 3, $title,
'',
'R');
878 $pdf->SetFont(
'',
'B', $default_font_size);
881 $pdf->SetXY($posx, $posy);
882 $pdf->SetTextColor(0, 0, 60);
883 $textref = $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset($object->ref);
884 if ($object->statut == $object::STATUS_DRAFT) {
885 $pdf->SetTextColor(128, 0, 0);
886 $textref .=
' - '.$outputlangs->transnoentities(
"NotValidated");
888 $pdf->MultiCell($w, 4, $textref,
'',
'R');
891 $pdf->SetFont(
'',
'', $default_font_size - 2);
893 if ($object->ref_client) {
895 $pdf->SetXY($posx, $posy);
896 $pdf->SetTextColor(0, 0, 60);
897 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset($object->ref_client), 65),
'',
'R');
901 $object->fetch_projet();
902 if (!empty($object->project->ref)) {
904 $pdf->SetXY($posx, $posy);
905 $pdf->SetTextColor(0, 0, 60);
906 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->projet->title),
'',
'R');
911 $object->fetch_projet();
912 if (!empty($object->project->ref)) {
914 $pdf->SetXY($posx, $posy);
915 $pdf->SetTextColor(0, 0, 60);
916 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
921 $object->fetch_projet();
922 if (!empty($object->project->ref)) {
923 $outputlangs->load(
"projects");
925 $pdf->SetXY($posx, $posy);
926 $pdf->SetTextColor(0, 0, 60);
927 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
932 $pdf->SetXY($posx, $posy);
933 $pdf->SetTextColor(0, 0, 60);
935 $title = $outputlangs->transnoentities(
"Date");
937 $title .=
' - '.$outputlangsbis->transnoentities(
"Date");
939 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date_creation,
"day",
false, $outputlangs),
'',
'R');
941 if ($object->thirdparty->code_client) {
943 $pdf->SetXY($posx, $posy);
944 $pdf->SetTextColor(0, 0, 60);
945 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
952 $current_y = $pdf->getY();
953 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3,
'R', $default_font_size);
954 if ($current_y < $pdf->getY()) {
955 $top_shift = $pdf->getY() - $current_y;
960 $carac_emetteur =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
965 $posx = $this->marge_gauche;
967 $posx = $this->page_largeur - $this->marge_droite - 80;
975 $pdf->SetTextColor(0, 0, 0);
976 $pdf->SetFont(
'',
'', $default_font_size - 2);
977 $pdf->SetXY($posx, $posy - 5);
978 $pdf->MultiCell(66, 5, $outputlangs->transnoentities(
"BillFrom").
":", 0,
'L');
979 $pdf->SetXY($posx, $posy);
980 $pdf->SetFillColor(230, 230, 230);
981 $pdf->MultiCell($widthrecbox, $hautcadre,
"", 0,
'R', 1);
982 $pdf->SetTextColor(0, 0, 60);
985 $pdf->SetXY($posx + 2, $posy + 3);
986 $pdf->SetFont(
'',
'B', $default_font_size);
987 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
988 $posy = $pdf->getY();
991 $pdf->SetXY($posx + 2, $posy);
992 $pdf->SetFont(
'',
'', $default_font_size - 1);
993 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0,
'L');
997 $arrayidcontact = $object->getIdContact(
'external',
'BILLING');
998 if (count($arrayidcontact) > 0) {
1000 $result = $object->fetch_contact($arrayidcontact[0]);
1045 $pdf->SetTextColor(0, 0, 0);