Example #1
0
 public function generateTcpdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape = false, $aProperties = array())
 {
     require_once PATH_THIRDPARTY . "tcpdf" . PATH_SEP . "config" . PATH_SEP . "lang" . PATH_SEP . "eng.php";
     require_once PATH_THIRDPARTY . "tcpdf" . PATH_SEP . "tcpdf.php";
     $nrt = array("\n", "\r", "\t");
     $nrthtml = array("(n /)", "(r /)", "(t /)");
     $strContentAux = str_replace($nrt, $nrthtml, $sContent);
     $sContent = null;
     while (preg_match("/^(.*)<font([^>]*)>(.*)\$/i", $strContentAux, $arrayMatch)) {
         $str = trim($arrayMatch[2]);
         $strAttribute = null;
         if (!empty($str)) {
             $strAux = $str;
             $str = null;
             while (preg_match("/^(.*)([\"'].*[\"'])(.*)\$/", $strAux, $arrayMatch2)) {
                 $strAux = $arrayMatch2[1];
                 $str = str_replace(" ", "__SPACE__", $arrayMatch2[2]) . $arrayMatch2[3] . $str;
             }
             $str = $strAux . $str;
             //Get attributes
             $strStyle = null;
             $array = explode(" ", $str);
             foreach ($array as $value) {
                 $arrayAux = explode("=", $value);
                 if (isset($arrayAux[1])) {
                     $a = trim($arrayAux[0]);
                     $v = trim(str_replace(array("__SPACE__", "\"", "'"), array(" ", null, null), $arrayAux[1]));
                     switch (strtolower($a)) {
                         case "color":
                             $strStyle = $strStyle . "color: {$v};";
                             break;
                         case "face":
                             $strStyle = $strStyle . "font-family: {$v};";
                             break;
                         case "size":
                             $arrayPt = array(0, 8, 10, 12, 14, 18, 24, 36);
                             $strStyle = $strStyle . "font-size: " . $arrayPt[intval($v)] . "pt;";
                             break;
                         case "style":
                             $strStyle = $strStyle . "{$v};";
                             break;
                         default:
                             $strAttribute = $strAttribute . " {$a}=\"{$v}\"";
                             break;
                     }
                 }
             }
             if ($strStyle != null) {
                 $strAttribute = $strAttribute . " style=\"{$strStyle}\"";
             }
         }
         $strContentAux = $arrayMatch[1];
         $sContent = "<span" . $strAttribute . ">" . $arrayMatch[3] . $sContent;
     }
     $sContent = $strContentAux . $sContent;
     $sContent = str_ireplace("</font>", "</span>", $sContent);
     $sContent = str_replace($nrthtml, $nrt, $sContent);
     // define Save file
     $sOutput = 2;
     $sOrientation = $sLandscape == false ? PDF_PAGE_ORIENTATION : 'L';
     $sMedia = isset($aProperties['media']) ? $aProperties['media'] : PDF_PAGE_FORMAT;
     $sLang = defined('SYS_LANG') ? SYS_LANG : 'en';
     // create new PDF document
     $pdf = new TCPDF($sOrientation, PDF_UNIT, $sMedia, true, 'UTF-8', false);
     // set document information
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor($aFields['USR_USERNAME']);
     $pdf->SetTitle('Processmaker');
     $pdf->SetSubject($sFilename);
     $pdf->SetCompression(true);
     $margins = $aProperties['margins'];
     $margins["left"] = $margins["left"] >= 0 ? $margins["left"] : PDF_MARGIN_LEFT;
     $margins["top"] = $margins["top"] >= 0 ? $margins["top"] : PDF_MARGIN_TOP;
     $margins["right"] = $margins["right"] >= 0 ? $margins["right"] : PDF_MARGIN_RIGHT;
     $margins["bottom"] = $margins["bottom"] >= 0 ? $margins["bottom"] : PDF_MARGIN_BOTTOM;
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->SetLeftMargin($margins['left']);
     $pdf->SetTopMargin($margins['top']);
     $pdf->SetRightMargin($margins['right']);
     $pdf->SetAutoPageBreak(true, $margins['bottom']);
     $oServerConf =& serverConf::getSingleton();
     // set some language dependent data:
     $lg = array();
     $lg['a_meta_charset'] = 'UTF-8';
     $lg['a_meta_dir'] = $oServerConf->isRtl($sLang) ? 'rtl' : 'ltr';
     $lg['a_meta_language'] = $sLang;
     $lg['w_page'] = 'page';
     //set some language-dependent strings
     $pdf->setLanguageArray($lg);
     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']);
         $pdf->SetProtection($permissions, $userPass, $ownerPass);
     }
     // ---------------------------------------------------------
     // set default font subsetting mode
     $pdf->setFontSubsetting(true);
     // Set font
     // dejavusans is a UTF-8 Unicode font, if you only need to
     // print standard ASCII chars, you can use core fonts like
     // helvetica or times to reduce file size.
     //$pdf->SetFont('dejavusans', '', 14, '', true);
     // Detect chinese, japanese, thai
     if (preg_match('/[\\x{30FF}\\x{3040}-\\x{309F}\\x{4E00}-\\x{9FFF}\\x{0E00}-\\x{0E7F}]/u', $sContent, $matches)) {
         $pdf->SetFont('kozminproregular');
     }
     // Add a page
     // This method has several options, check the source code documentation for more information.
     $pdf->AddPage();
     // set text shadow effect
     //$pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));
     // Print text using writeHTMLCell()
     // $pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
     if (mb_detect_encoding($sContent) == 'UTF-8') {
         $sContent = mb_convert_encoding($sContent, 'HTML-ENTITIES', 'UTF-8');
     }
     $doc = new DOMDocument('1.0', 'UTF-8');
     $doc->loadHtml($sContent);
     $pdf->writeHTML($doc->saveXML(), false, false, false, false, '');
     // ---------------------------------------------------------
     // Close and output PDF document
     // This method has several options, check the source code documentation for more information.
     //$pdf->Output('example_00.pdf', 'I');
     //$pdf->Output('/home/hector/processmaker/example_00.pdf', 'D');
     switch ($sOutput) {
         case 0:
             // Vrew browser
             $pdf->Output($sPath . $sFilename . '.pdf', 'I');
             break;
         case 1:
             // Donwnload
             $pdf->Output($sPath . $sFilename . '.pdf', 'D');
             break;
         case 2:
             // Save file
             $pdf->Output($sPath . $sFilename . '.pdf', 'F');
             break;
     }
 }
	- print-high : Print the document to a representation from which a faithful digital copy of the PDF content could be generated. When this is not set, printing is limited to a low-level representation of the appearance, possibly of degraded quality.
	- owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions.
 If you don't set any password, the document will open as usual.
 If you set a user password, the PDF viewer will ask for it before displaying the document.
 The master (owner) password, if different from the user one, can be used to get full document access.
 Possible encryption modes are:
 	0 = RSA 40 bit
 	1 = RSA 128 bit
 	2 = AES 128 bit
 	3 = AES 256 bit
 NOTES:
 - To create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
 - To export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
 - To convert pfx certificate to pem: openssl pkcs12 -in tcpdf.pfx -out tcpdf.crt -nodes
*/
$pdf->SetProtection($permissions = array('print', 'copy'), $user_pass = '', $owner_pass = null, $mode = 0, $pubkeys = null);
// Example with public-key
// To open the document you need to install the private key (tcpdf.p12) on the Acrobat Reader. The password is: 1234
//$pdf->SetProtection($permissions=array('print', 'copy'), $user_pass='', $owner_pass=null, $mode=1, $pubkeys=array(array('c' => 'file://../tcpdf.crt', 'p' => array('print'))));
// *********************************************************
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 016');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 016', PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(array('helvetica', '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(array('helvetica', '', PDF_FONT_SIZE_DATA));
Example #3
0
	- print-high : Print the document to a representation from which a faithful digital copy of the PDF content could be generated. When this is not set, printing is limited to a low-level representation of the appearance, possibly of degraded quality.
	- owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions.
 If you don't set any password, the document will open as usual.
 If you set a user password, the PDF viewer will ask for it before displaying the document.
 The master (owner) password, if different from the user one, can be used to get full document access.
 Possible encryption modes are:
 	0 = RSA 40 bit
 	1 = RSA 128 bit
 	2 = AES 128 bit
 	3 = AES 256 bit
 NOTES:
 - To create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
 - To export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
 - To convert pfx certificate to pem: openssl pkcs12 -in tcpdf.pfx -out tcpdf.crt -nodes
*/
$pdf->SetProtection(array('print', 'copy'), '', null, 0, null);
// Example with public-key
// To open the document you need to install the private key (tcpdf.p12) on the Acrobat Reader. The password is: 1234
//$pdf->SetProtection($permissions=array('print', 'copy'), $user_pass='', $owner_pass=null, $mode=1, $pubkeys=array(array('c' => 'file://../config/cert/tcpdf.crt', 'p' => array('print'))));
// *********************************************************
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 016');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 016', PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(array('helvetica', '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(array('helvetica', '', PDF_FONT_SIZE_DATA));
Example #4
0
/**
 *      Return a PDF instance object. We create a FPDI instance that instantiate TCPDF.
 *
 *      @param	string		$format         Array(width,height). Keep empty to use default setup.
 *      @param	string		$metric         Unit of format ('mm')
 *      @param  string		$pagetype       'P' or 'l'
 *      @return TPDF						PDF object
 */
function pdf_getInstance($format = '', $metric = 'mm', $pagetype = 'P')
{
    global $conf;
    // Define constant for TCPDF
    if (!defined('K_TCPDF_EXTERNAL_CONFIG')) {
        define('K_TCPDF_EXTERNAL_CONFIG', 1);
        // this avoid using tcpdf_config file
        define('K_PATH_CACHE', DOL_DATA_ROOT . '/admin/temp/');
        define('K_PATH_URL_CACHE', DOL_DATA_ROOT . '/admin/temp/');
        dol_mkdir(K_PATH_CACHE);
        define('K_BLANK_IMAGE', '_blank.png');
        define('PDF_PAGE_FORMAT', 'A4');
        define('PDF_PAGE_ORIENTATION', 'P');
        define('PDF_CREATOR', 'TCPDF');
        define('PDF_AUTHOR', 'TCPDF');
        define('PDF_HEADER_TITLE', 'TCPDF Example');
        define('PDF_HEADER_STRING', "by Dolibarr ERP CRM");
        define('PDF_UNIT', 'mm');
        define('PDF_MARGIN_HEADER', 5);
        define('PDF_MARGIN_FOOTER', 10);
        define('PDF_MARGIN_TOP', 27);
        define('PDF_MARGIN_BOTTOM', 25);
        define('PDF_MARGIN_LEFT', 15);
        define('PDF_MARGIN_RIGHT', 15);
        define('PDF_FONT_NAME_MAIN', 'helvetica');
        define('PDF_FONT_SIZE_MAIN', 10);
        define('PDF_FONT_NAME_DATA', 'helvetica');
        define('PDF_FONT_SIZE_DATA', 8);
        define('PDF_FONT_MONOSPACED', 'courier');
        define('PDF_IMAGE_SCALE_RATIO', 1.25);
        define('HEAD_MAGNIFICATION', 1.1);
        define('K_CELL_HEIGHT_RATIO', 1.25);
        define('K_TITLE_MAGNIFICATION', 1.3);
        define('K_SMALL_RATIO', 2 / 3);
        define('K_THAI_TOPCHARS', true);
        define('K_TCPDF_CALLS_IN_HTML', true);
        define('K_TCPDF_THROW_EXCEPTION_ERROR', false);
    }
    if (!empty($conf->global->MAIN_USE_FPDF) && !empty($conf->global->MAIN_DISABLE_FPDI)) {
        return "Error MAIN_USE_FPDF and MAIN_DISABLE_FPDI can't be set together";
    }
    // We use by default TCPDF else FPDF
    if (empty($conf->global->MAIN_USE_FPDF)) {
        require_once TCPDF_PATH . 'tcpdf.php';
    } else {
        require_once FPDF_PATH . 'fpdf.php';
    }
    // We need to instantiate tcpdi or fpdi object (instead of tcpdf) to use merging features. But we can disable it (this will break all merge features).
    if (empty($conf->global->MAIN_DISABLE_TCPDI)) {
        require_once TCPDI_PATH . 'tcpdi.php';
    } else {
        if (empty($conf->global->MAIN_DISABLE_FPDI)) {
            require_once FPDI_PATH . 'fpdi.php';
        }
    }
    //$arrayformat=pdf_getFormat();
    //$format=array($arrayformat['width'],$arrayformat['height']);
    //$metric=$arrayformat['unit'];
    // Protection and encryption of pdf
    if (empty($conf->global->MAIN_USE_FPDF) && !empty($conf->global->PDF_SECURITY_ENCRYPTION)) {
        /* Permission supported by TCPDF
        		- print : Print the document;
        		- modify : Modify the contents of the document by operations other than those controlled by 'fill-forms', 'extract' and 'assemble';
        		- copy : Copy or otherwise extract text and graphics from the document;
        		- annot-forms : Add or modify text annotations, fill in interactive form fields, and, if 'modify' is also set, create or modify interactive form fields (including signature fields);
        		- fill-forms : Fill in existing interactive form fields (including signature fields), even if 'annot-forms' is not specified;
        		- extract : Extract text and graphics (in support of accessibility to users with disabilities or for other purposes);
        		- assemble : Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if 'modify' is not set;
        		- print-high : Print the document to a representation from which a faithful digital copy of the PDF content could be generated. When this is not set, printing is limited to a low-level representation of the appearance, possibly of degraded quality.
        		- owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions.
        		*/
        if (class_exists('TCPDI')) {
            $pdf = new TCPDI($pagetype, $metric, $format);
        } else {
            if (class_exists('FPDI')) {
                $pdf = new FPDI($pagetype, $metric, $format);
            } else {
                $pdf = new TCPDF($pagetype, $metric, $format);
            }
        }
        // For TCPDF, we specify permission we want to block
        $pdfrights = array('modify', 'copy');
        $pdfuserpass = '';
        // Password for the end user
        $pdfownerpass = NULL;
        // Password of the owner, created randomly if not defined
        $pdf->SetProtection($pdfrights, $pdfuserpass, $pdfownerpass);
    } else {
        if (class_exists('TCPDI')) {
            $pdf = new TCPDI($pagetype, $metric, $format);
        } else {
            if (class_exists('FPDI')) {
                $pdf = new FPDI($pagetype, $metric, $format);
            } else {
                $pdf = new TCPDF($pagetype, $metric, $format);
            }
        }
    }
    // If we use FPDF class, we may need to add method writeHTMLCell
    if (!empty($conf->global->MAIN_USE_FPDF) && !method_exists($pdf, 'writeHTMLCell')) {
        // Declare here a class to overwrite FPDI to add method writeHTMLCell
        /**
         *	This class is an enhanced FPDI class that support method writeHTMLCell
         */
        class FPDI_DolExtended extends FPDI
        {
            /**
             * __call
             *
             * @param 	string	$method		Method
             * @param 	mixed	$args		Arguments
             * @return 	void
             */
            public function __call($method, $args)
            {
                if (isset($this->{$method})) {
                    $func = $this->{$method};
                    $func($args);
                }
            }
            /**
             * writeHTMLCell
             *
             * @param	int		$w				Width
             * @param 	int		$h				Height
             * @param 	int		$x				X
             * @param 	int		$y				Y
             * @param 	string	$html			Html
             * @param 	int		$border			Border
             * @param 	int		$ln				Ln
             * @param 	boolean	$fill			Fill
             * @param 	boolean	$reseth			Reseth
             * @param 	string	$align			Align
             * @param 	boolean	$autopadding	Autopadding
             * @return 	void
             */
            public function writeHTMLCell($w, $h, $x, $y, $html = '', $border = 0, $ln = 0, $fill = false, $reseth = true, $align = '', $autopadding = true)
            {
                $this->SetXY($x, $y);
                $val = str_replace('<br>', "\n", $html);
                //$val=dol_string_nohtmltag($val,false,'ISO-8859-1');
                $val = dol_string_nohtmltag($val, false, 'UTF-8');
                $this->MultiCell($w, $h, $val, $border, $align, $fill);
            }
        }
        $pdf2 = new FPDI_DolExtended($pagetype, $metric, $format);
        unset($pdf);
        $pdf = $pdf2;
    }
    return $pdf;
}
Example #5
0
 Possible encryption modes are:
     0 = RSA 40 bit
     1 = RSA 128 bit
     2 = AES 128 bit
     3 = AES 256 bit
 NOTES:
 - To create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
 - To export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
 - To convert pfx certificate to pem: openssl pkcs12 -in tcpdf.pfx -out tcpdf.crt -nodes
*/
$permissions = array('copy');
$user_pass = '******';
$owner_pass = null;
$mode = 0;
$pubkeys = null;
$pdf->SetProtection($permissions, $user_pass, $owner_pass, $mode, $pubkeys);
// Example with public-key
// To open the document you need to install the private key (tcpdf.p12) on the Acrobat Reader. The password is: 1234
//$pdf->SetProtection($permissions=array('print', 'copy'), $user_pass='', $owner_pass=null, $mode=1, $pubkeys=array(array('c' => 'file://../tcpdf.crt', 'p' => array('print'))));
// *********************************************************
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 016');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 016', PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(array('helvetica', '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(array('helvetica', '', PDF_FONT_SIZE_DATA));
Example #6
0
/**
 *      Return a PDF instance object. We create a FPDI instance that instanciate TCPDF.
 *
 *      @param	string		$format         Array(width,height). Keep empty to use default setup.
 *      @param	string		$metric         Unit of format ('mm')
 *      @param  string		$pagetype       'P' or 'l'
 *      @return TPDF							PDF object
 */
function pdf_getInstance($format = '', $metric = 'mm', $pagetype = 'P')
{
    global $conf;
    if (!empty($conf->global->MAIN_USE_FPDF) && !empty($conf->global->MAIN_DISABLE_FPDI)) {
        return "Error MAIN_USE_FPDF and MAIN_DISABLE_FPDI can't be set together";
    }
    // We use by default TCPDF
    if (empty($conf->global->MAIN_USE_FPDF)) {
        require_once TCPDF_PATH . 'tcpdf.php';
    }
    // We need to instantiate fpdi object (instead of tcpdf) to use merging features. But we can disable it.
    if (empty($conf->global->MAIN_DISABLE_FPDI)) {
        require_once FPDI_PATH . 'fpdi.php';
    }
    //$arrayformat=pdf_getFormat();
    //$format=array($arrayformat['width'],$arrayformat['height']);
    //$metric=$arrayformat['unit'];
    // Protection et encryption du pdf
    if (!empty($conf->global->PDF_SECURITY_ENCRYPTION)) {
        /* Permission supported by TCPDF
        		 - print : Print the document;
        		 - modify : Modify the contents of the document by operations other than those controlled by 'fill-forms', 'extract' and 'assemble';
        		 - copy : Copy or otherwise extract text and graphics from the document;
        		 - annot-forms : Add or modify text annotations, fill in interactive form fields, and, if 'modify' is also set, create or modify interactive form fields (including signature fields);
        		 - fill-forms : Fill in existing interactive form fields (including signature fields), even if 'annot-forms' is not specified;
        		 - extract : Extract text and graphics (in support of accessibility to users with disabilities or for other purposes);
        		 - assemble : Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if 'modify' is not set;
        		 - print-high : Print the document to a representation from which a faithful digital copy of the PDF content could be generated. When this is not set, printing is limited to a low-level representation of the appearance, possibly of degraded quality.
        		 - owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions.
        		 */
        if (!empty($conf->global->MAIN_USE_FPDF)) {
            require_once FPDI_PATH . 'fpdi_protection.php';
            $pdf = new FPDI_Protection($pagetype, $metric, $format);
            // For FPDF, we specify permission we want to open
            $pdfrights = array('print');
        } else {
            if (class_exists('FPDI')) {
                $pdf = new FPDI($pagetype, $metric, $format);
            } else {
                $pdf = new TCPDF($pagetype, $metric, $format);
            }
            // For TCPDF, we specify permission we want to block
            $pdfrights = array('modify', 'copy');
        }
        $pdfuserpass = '';
        // Mot de passe pour l'utilisateur final
        $pdfownerpass = NULL;
        // Mot de passe du proprietaire, cree aleatoirement si pas defini
        $pdf->SetProtection($pdfrights, $pdfuserpass, $pdfownerpass);
    } else {
        if (class_exists('FPDI')) {
            $pdf = new FPDI($pagetype, $metric, $format);
        } else {
            $pdf = new TCPDF($pagetype, $metric, $format);
        }
    }
    return $pdf;
}
Example #7
0
// Set PDF protection (RSA 40bit encryption)
/*
* The permission array is composed of values taken from the following ones:
* - copy: copy text and images to the clipboard
* - print: print the document
* - modify: modify it (except for annotations and forms)
* - annot-forms: add annotations and forms 
* If you don't set any password, the document will open as usual. 
* If you set a user password, the PDF viewer will ask for it before 
* displaying the document. The master password, if different from 
* the user one, can be used to get full access.
* Note: protecting a document requires to encrypt it, which increases the 
* processing time a lot. This can cause a PHP time-out in some cases, 
* especially if the document contains images or fonts.
*/
$pdf->SetProtection(array('print'));
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor("Nicola Asuni");
$pdf->SetTitle("TCPDF Example 016");
$pdf->SetSubject("TCPDF Tutorial");
$pdf->SetKeywords("TCPDF, PDF, example, test, guide");
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(array("helvetica", '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(array("helvetica", '', PDF_FONT_SIZE_DATA));
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
Example #8
0
	function execute(&$form, $action_id){
		$config =  $form->actions_config[$action_id];
		$config = new \GCore\Libs\Parameter($config);
		
		$content = $config->get('content', "");
		ob_start();
		eval('?>'.$content);
		$output = ob_get_clean();
		//if the content box was empty, display the form output
		if(empty($output)){
			$output = $form->form_output;
		}
		$output = \GCore\Libs\Str::replacer($output, $form->data);
		//begin tcpdf code
		require_once('tcpdf/config/lang/eng.php');
		require_once('tcpdf/tcpdf.php');
						
		// create new PDF document
		$pdf = new \TCPDF($config->get('pdf_page_orientation', 'P'), PDF_UNIT, $config->get('pdf_page_format', 'A4'), true, 'UTF-8', false);
		
		//set protection if enabled
		if((bool)$config->get('enable_protection', 0) === true){
			$owner_pass = ($config->get('owner_pass', "") ? $config->get('owner_pass', "") : null);
			$perms = (strlen($config->get('permissions', "")) > 0) ? explode(",", $config->get('permissions', "")) : array();
			$pdf->SetProtection($perms, $config->get('user_pass', ""), $owner_pass, $config->get('sec_mode', ""), $pubkeys=null);
		}

		// set document information
		$pdf->SetCreator(PDF_CREATOR);
		$pdf->SetAuthor($config->get('pdf_author', 'PDF Author.'));
		$pdf->SetTitle($config->get('pdf_title', 'PDF Title Goes Here.'));
		$pdf->SetSubject($config->get('pdf_subject', 'Powered by Chronoforms + TCPDF'));
		$pdf->SetKeywords($config->get('pdf_keywords', 'Chronoforms, PDF Plugin, TCPDF, PDF, '.$form->form['Form']['title']));
	
		// Willian	
		// set header data, font and margins
		if((bool)$config->get((bool)$config->get('pdf_header_show', 1))){
			if(strlen($config->get('pdf_title')) OR strlen($config->get('pdf_header'))){
                        	$pdf->SetHeaderData(false, 0, $config->get('pdf_title', 'PDF Title Goes Here.'), $config->get('pdf_header', 'Powered by Chronoforms + TCPDF'));
                	}
			$pdf->setHeaderFont(Array($config->get('pdf_header_font', 'helvetica'), '', (int)$config->get('pdf_header_font_size', 10)));
			$pdf->SetHeaderMargin($config->get('pdf_margin_header', 5));
			$pdf->setPrintHeader(true);
		} else {
			$pdf->setPrintHeader(false);
		}
		
		// set footer font and margins
		if((bool)$config->get((bool)$config->get('pdf_footer_show', 1))){
			$pdf->setFooterFont(Array($config->get('pdf_footer_font', 'helvetica'), '', (int)$config->get('pdf_footer_font_size', 8)));
			$pdf->SetFooterMargin($config->get('pdf_margin_footer', 10));
			$pdf->setPrintFooter(true);
		} else {
			$pdf->setPrintFooter(false);
		}

		// set default monospaced font
		$pdf->SetDefaultMonospacedFont($config->get('pdf_monospaced_font', 'courier'));

		//set margins
		$pdf->SetMargins($config->get('pdf_margin_left', 15), $config->get('pdf_margin_top', 27), $config->get('pdf_margin_right', 15));

		//set auto page breaks
		$pdf->SetAutoPageBreak(TRUE, $config->get('pdf_margin_bottom', 25));

		//set image scale factor
		$pdf->setImageScale($config->get('pdf_image_scale_ratio', 1.25));

		//set some language-dependent strings
		$pdf->setLanguageArray($l);

		// Willian
                // Mostrar/Esconder CabeƧalho
                $pdf->setPrintHeader((bool)$config->get('pdf_header_show', 1));
                // Mostrar/Esconder RodapƩ
                $pdf->setPrintHeader((bool)$config->get('pdf_footer_show', 1));
		
		// ---------------------------------------------------------

		// set font
		$pdf->SetFont($config->get('pdf_body_font', 'courier'), '', (int)$config->get('pdf_body_font_size', 14));

		// add a page
		$pdf->AddPage();
		// create some HTML content
		$css = "";
		
		$output = $css.$output;
		$html = $output;
		// output the HTML content
		$pdf->writeHTML($html, true, false, true, false, '');
		// reset pointer to the last page
		$pdf->lastPage();
		//Close and output PDF document
		if(isset($form->data['pdf_file_name']) && !empty($form->data['pdf_file_name'])){
			$PDF_file_name = $form->data['pdf_file_name'];
		}else{
			if(strlen(trim($config->get('pdf_file_name', ''))) > 0){
				$PDF_file_name = trim($config->get('pdf_file_name', ''))."_".date('YmdHis');
			}else{
				$PDF_file_name = $form->form['Form']['title']."_".date('YmdHis');
			}
		}
		$PDF_view = $config->get('pdf_view', 'I');
		if(($PDF_view == 'F') || ($PDF_view == 'FI') || ($PDF_view == 'FD')){
			jimport('joomla.utilities.error');
			jimport('joomla.filesystem.file');
			jimport('joomla.filesystem.folder');
			$upload_path = $config->get('pdf_save_path');
			if(!empty($upload_path)){
				$upload_path = str_replace(array("/", "\\"), DS, $upload_path);
				if(substr($upload_path, -1) == DS){
					$upload_path = substr_replace($upload_path, '', -1);
				}
				$upload_path = $upload_path.DS;
				$config->set('pdf_save_path', $upload_path);
			}else{
				$upload_path = \GCore\C::ext_path('chronoforms', 'front').'pdfs'.DS.$form->form['Form']['title'].DS;
			}
			//check the save files path is ok
			if(!file_exists($upload_path.DS.'index.html')){
				if(!\GCore\Libs\Folder::create($upload_path)){
					$form->errors[] = "Couldn't create upload directory: ".$upload_path;
					$this->events['fail'] = 1;
					return;
				}
				$dummy_c = '<html><body bgcolor="#ffffff"></body></html>';
				if(!\GCore\Libs\File::write($upload_path.DS.'index.html', $dummy_c)){
					$form->errors[] = "Couldn't create upload directory index file.";
					$this->events['fail'] = 1;
					return;
				}
			}
			
			$PDF_file_path = $upload_path.$PDF_file_name.".pdf";
			$pdf->Output($PDF_file_path, $PDF_view);
			
			//Try to generate an auto file link
			$site_link = \GCore\C::get('GCORE_FRONT_URL');
			if(substr($site_link, -1) == "/"){
				$site_link = substr_replace($site_link, '', -1);
			}
			
			if(strlen(trim($config->get('pdf_post_name', ''))) > 0){
				$form->files[trim($config->get('pdf_post_name', ''))] = array('name' => $PDF_file_name.".pdf", 'path' => $PDF_file_path, 'size' => 0);
				$form->files[trim($config->get('pdf_post_name', ''))]['link'] = str_replace(array(\GCore\C::get('GCORE_FRONT_PATH'), DS), array($site_link, "/"), $upload_path.$PDF_file_name.".pdf");
				$form->data[trim($config->get('pdf_post_name', ''))] = $PDF_file_name.".pdf";
				$form->debug[$action_id][self::$title][] = $PDF_file_path.' has been saved correctly.';
			}
		}else{
			$pdf->Output($PDF_file_name.".pdf", $PDF_view);
		}
		if($PDF_view != 'F'){
			@flush();
			@ob_flush();
			exit;
		}
	}
 public function generateTcpdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape = false, $aProperties = array())
 {
     require_once PATH_THIRDPARTY . 'tcpdf/config/lang/eng.php';
     require_once PATH_THIRDPARTY . 'tcpdf/tcpdf.php';
     // define Save file
     $sOutput = 2;
     $sOrientation = $sLandscape == false ? PDF_PAGE_ORIENTATION : 'L';
     $sMedia = isset($aProperties['media']) ? $aProperties['media'] : PDF_PAGE_FORMAT;
     $sLang = defined('SYS_LANG') ? SYS_LANG : 'en';
     // create new PDF document
     $pdf = new TCPDF($sOrientation, PDF_UNIT, $sMedia, true, 'UTF-8', false);
     // set document information
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor($aFields['USR_USERNAME']);
     $pdf->SetTitle('Processmaker');
     $pdf->SetSubject($sFilename);
     $margins = $aProperties['margins'];
     $margins['left'] = $margins['left'] > 0 ? $margins['left'] : PDF_MARGIN_LEFT;
     $margins['top'] = $margins['top'] > 0 ? $margins['top'] : PDF_MARGIN_TOP;
     $margins['right'] = $margins['right'] > 0 ? $margins['right'] : PDF_MARGIN_RIGHT;
     $margins['bottom'] = $margins['bottom'] > 0 ? $margins['bottom'] : PDF_MARGIN_BOTTOM;
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->SetLeftMargin($margins['left']);
     $pdf->SetTopMargin($margins['top']);
     $pdf->SetRightMargin($margins['right']);
     $pdf->SetAutoPageBreak(true, $margins['bottom']);
     $oServerConf =& serverConf::getSingleton();
     // set some language dependent data:
     $lg = array();
     $lg['a_meta_charset'] = 'UTF-8';
     $lg['a_meta_dir'] = $oServerConf->isRtl($sLang) ? 'rtl' : 'ltr';
     $lg['a_meta_language'] = $sLang;
     $lg['w_page'] = 'page';
     //set some language-dependent strings
     $pdf->setLanguageArray($lg);
     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']);
         $pdf->SetProtection($permissions, $userPass, $ownerPass);
     }
     // ---------------------------------------------------------
     // set default font subsetting mode
     $pdf->setFontSubsetting(true);
     // Set font
     // dejavusans is a UTF-8 Unicode font, if you only need to
     // print standard ASCII chars, you can use core fonts like
     // helvetica or times to reduce file size.
     $pdf->SetFont('dejavusans', '', 14, '', true);
     // Add a page
     // This method has several options, check the source code documentation for more information.
     $pdf->AddPage();
     // set text shadow effect
     //$pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));
     // Print text using writeHTMLCell()
     // $pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
     $pdf->writeHTML($sContent);
     // ---------------------------------------------------------
     // Close and output PDF document
     // This method has several options, check the source code documentation for more information.
     //$pdf->Output('example_00.pdf', 'I');
     //$pdf->Output('/home/hector/processmaker/example_00.pdf', 'D');
     switch ($sOutput) {
         case 0:
             // Vrew browser
             $pdf->Output($sPath . $sFilename . '.pdf', 'I');
             break;
         case 1:
             // Donwnload
             $pdf->Output($sPath . $sFilename . '.pdf', 'D');
             break;
         case 2:
             // Save file
             $pdf->Output($sPath . $sFilename . '.pdf', 'F');
             break;
     }
 }