Example #1
0
 public function generateHtml2pdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape = false, $aProperties = array())
 {
     // define("MAX_FREE_FRACTION", 1);
     define('PATH_OUTPUT_FILE_DIRECTORY', PATH_HTML . 'files/' . $_SESSION['APPLICATION'] . '/outdocs/');
     G::verifyPath(PATH_OUTPUT_FILE_DIRECTORY, true);
     require_once PATH_THIRDPARTY . 'html2pdf/html2pdf.class.php';
     // define Save file
     $sOutput = 2;
     $sOrientation = $sLandscape == false ? 'P' : 'L';
     $sLang = defined('SYS_LANG') ? SYS_LANG : 'en';
     $sMedia = $aProperties['media'];
     // margin define
     define("MINIMAL_MARGIN", 15);
     $marges = array(MINIMAL_MARGIN, MINIMAL_MARGIN, MINIMAL_MARGIN, MINIMAL_MARGIN);
     if (isset($aProperties['margins'])) {
         // Default marges (left, top, right, bottom)
         $margins = $aProperties['margins'];
         $margins['left'] = $margins['left'] > 0 ? $margins['left'] : MINIMAL_MARGIN;
         $margins['top'] = $margins['top'] > 0 ? $margins['top'] : MINIMAL_MARGIN;
         $margins['right'] = $margins['right'] > 0 ? $margins['right'] : MINIMAL_MARGIN;
         $margins['bottom'] = $margins['bottom'] > 0 ? $margins['bottom'] : MINIMAL_MARGIN;
         $marges = array($margins['left'], $margins['top'], $margins['right'], $margins['bottom']);
     }
     $html2pdf = new HTML2PDF($sOrientation, $sMedia, $sLang, true, 'UTF-8', $marges);
     $html2pdf->pdf->SetAuthor($aFields['USR_USERNAME']);
     $html2pdf->pdf->SetTitle('Processmaker');
     $html2pdf->pdf->SetSubject($sFilename);
     $html2pdf->pdf->SetCompression(true);
     //$html2pdf->pdf->SetKeywords('HTML2PDF, TCPDF, processmaker');
     if (isset($aProperties['pdfSecurity'])) {
         $pdfSecurity = $aProperties['pdfSecurity'];
         $userPass = G::decrypt($pdfSecurity['openPassword'], $sUID);
         $ownerPass = $pdfSecurity['ownerPassword'] != '' ? G::decrypt($pdfSecurity['ownerPassword'], $sUID) : null;
         $permissions = explode("|", $pdfSecurity['permissions']);
         $html2pdf->pdf->SetProtection($permissions, $userPass, $ownerPass);
     }
     $html2pdf->setTestTdInOnePage(false);
     $html2pdf->setTestIsImage(false);
     $html2pdf->setTestIsDeprecated(false);
     $html2pdf->writeHTML($html2pdf->getHtmlFromPage($sContent));
     switch ($sOutput) {
         case 0:
             // Vrew browser
             $html2pdf->Output($sPath . $sFilename . '.pdf', 'I');
             break;
         case 1:
             // Donwnload
             $html2pdf->Output($sPath . $sFilename . '.pdf', 'D');
             break;
         case 2:
             // Save file
             $html2pdf->Output($sPath . $sFilename . '.pdf', 'F');
             break;
     }
     copy($sPath . $sFilename . '.html', PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.html');
     copy(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.pdf', $sPath . $sFilename . '.pdf');
     unlink(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.pdf');
     unlink(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.html');
 }
Example #2
0
 /**
  * création d'un sous HTML2PDF pour la gestion des tableaux imbriqués
  *
  * @param	HTML2PDF	futur sous HTML2PDF passé en référence pour création
  * @param	integer		marge eventuelle de l'objet si simulation d'un TD
  * @return	null
  */
 function createSubHTML(&$sub_html, $cellmargin = 0)
 {
     // calcul de la largueur
     if ($this->style->value['width']) {
         $marge = $cellmargin * 2;
         $marge += $this->style->value['padding']['l'] + $this->style->value['padding']['r'];
         $marge += $this->style->value['border']['l']['width'] + $this->style->value['border']['r']['width'];
         $marge = $this->pdf->getW() - $this->style->value['width'] + $marge;
     } else {
         $marge = $this->margeLeft + $this->margeRight;
     }
     //clonage
     $sub_html = new HTML2PDF($this->sens, $this->format, $this->langue, array($this->defaultLeft, $this->defaultTop, $this->defaultRight, $this->defaultBottom));
     $sub_html->setIsSubPart();
     $sub_html->setEncoding($this->encoding);
     $sub_html->setTestTdInOnePage($this->testTDin1page);
     $sub_html->setTestIsImage($this->testIsImage);
     $sub_html->setTestIsDeprecated($this->testIsDeprecated);
     $sub_html->setDefaultFont($this->defaultFont);
     $sub_html->style->css = $this->style->css;
     $sub_html->style->css_keys = $this->style->css_keys;
     $sub_html->pdf->cloneFontFrom($this->pdf);
     $sub_html->style->table = $this->style->table;
     $sub_html->style->value = $this->style->value;
     $sub_html->style->setOnlyLeft();
     $sub_html->setNewPage($this->format, $this->sens);
     $sub_html->initSubHtml($marge, $this->page, $this->defLIST);
     // initialisation des positions et autre
     $sub_html->maxX = 0;
     $sub_html->maxY = 0;
     $sub_html->maxH = 0;
     $sub_html->pdf->setXY(0, 0);
 }