Example #1
44
 public function testPdfOutput()
 {
     $this->markTestIncomplete('Transparency rendering on signature not working.');
     // create new PDF document
     $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     // set document information
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor('Nicola Asuni');
     $pdf->SetTitle('TCPDF Example 052');
     $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 . ' 052', PDF_HEADER_STRING);
     // set header and footer fonts
     $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
     $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
     // set default monospaced font
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     // set margins
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     // set auto page breaks
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     // set image scale factor
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     // set some language-dependent strings (optional)
     $pdf->setLanguageArray($this->langSettings);
     // ---------------------------------------------------------
     /*
     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
     */
     // set certificate file
     $certificate = 'file://tests/data/cert/tcpdf.crt';
     // set additional information
     $info = array('Name' => 'TCPDF', 'Location' => 'Office', 'Reason' => 'Testing TCPDF', 'ContactInfo' => 'http://www.tcpdf.org');
     // set document signature
     $pdf->setSignature($certificate, $certificate, 'tcpdfdemo', '', 2, $info);
     // set font
     $pdf->SetFont('helvetica', '', 12);
     // add a page
     $pdf->AddPage();
     // print a line of text
     $text = 'This is a <b color="#FF0000">digitally signed document</b> using the default (example) <b>tcpdf.crt</b> certificate.<br />To validate this signature you have to load the <b color="#006600">tcpdf.fdf</b> on the Arobat Reader to add the certificate to <i>List of Trusted Identities</i>.<br /><br />For more information check the source code of this example and the source code documentation for the <i>setSignature()</i> method.<br /><br /><a href="http://www.tcpdf.org">www.tcpdf.org</a>';
     $pdf->writeHTML($text, true, 0, true, 0);
     // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     // *** set signature appearance ***
     // create content for signature (image and/or text)
     $pdf->Image('tests/images/tcpdf_signature.png', 180, 60, 15, 15, 'PNG');
     // define active area for signature appearance
     $pdf->setSignatureAppearance(180, 60, 15, 15);
     // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     // *** set an empty signature appearance ***
     $pdf->addEmptySignatureAppearance(180, 80, 15, 15);
     $this->comparePdfs($pdf);
 }
Example #2
1
 public function &getTCPDF()
 {
     // Load PDF signing certificates
     if (!class_exists('AkeebasubsHelperCparams')) {
         require_once JPATH_ADMINISTRATOR . '/components/com_akeebasubs/helpers/cparams.php';
     }
     $certificateFile = AkeebasubsHelperCparams::getParam('invoice_certificatefile', 'certificate.cer');
     $secretKeyFile = AkeebasubsHelperCparams::getParam('invoice_secretkeyfile', 'secret.cer');
     $secretKeyPass = AkeebasubsHelperCparams::getParam('invoice_secretkeypass', '');
     $extraCertFile = AkeebasubsHelperCparams::getParam('invoice_extracert', 'extra.cer');
     $certificate = '';
     $secretkey = '';
     $extracerts = '';
     $path = JPATH_ADMINISTRATOR . '/components/com_akeebasubs/assets/tcpdf/certificates/';
     if (JFile::exists($path . $certificateFile)) {
         $certificate = JFile::read($path . $certificateFile);
     }
     if (!empty($certificate)) {
         if (JFile::exists($path . $secretKeyFile)) {
             $secretkey = JFile::read($path . $secretKeyFile);
         }
         if (empty($secretkey)) {
             $secretkey = $certificate;
         }
         if (JFile::exists($path . $extraCertFile)) {
             $extracerts = JFile::read($path . $extraCertFile);
         }
         if (empty($extracerts)) {
             $extracerts = '';
         }
     }
     // Set up TCPDF
     $jreg = JFactory::getConfig();
     $tmpdir = $jreg->get('tmp_path');
     $tmpdir = rtrim($tmpdir, '/' . DIRECTORY_SEPARATOR) . '/';
     $siteName = $jreg->get('sitename');
     $baseurl = JURI::base();
     $baseurl = rtrim($baseurl, '/');
     define('K_TCPDF_EXTERNAL_CONFIG', 1);
     define('K_PATH_MAIN', JPATH_BASE . '/');
     define('K_PATH_URL', $baseurl);
     define('K_PATH_FONTS', JPATH_ROOT . '/media/com_akeebasubs/tcpdf/fonts/');
     define('K_PATH_CACHE', $tmpdir);
     define('K_PATH_URL_CACHE', $tmpdir);
     define('K_PATH_IMAGES', JPATH_ROOT . '/media/com_akeebasubs/tcpdf/images/');
     define('K_BLANK_IMAGE', K_PATH_IMAGES . '_blank.png');
     define('PDF_PAGE_FORMAT', 'A4');
     define('PDF_PAGE_ORIENTATION', 'P');
     define('PDF_CREATOR', 'Akeeba Subscriptions');
     define('PDF_AUTHOR', $siteName);
     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', 'dejavusans');
     define('PDF_FONT_SIZE_MAIN', 8);
     define('PDF_FONT_NAME_DATA', 'dejavusans');
     define('PDF_FONT_SIZE_DATA', 8);
     define('PDF_FONT_MONOSPACED', 'dejavusansmono');
     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', false);
     require_once JPATH_ADMINISTRATOR . '/components/com_akeebasubs/assets/tcpdf/tcpdf.php';
     $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor(PDF_AUTHOR);
     $pdf->SetTitle('Invoice');
     $pdf->SetSubject('Invoice');
     $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
     $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     $pdf->setHeaderFont(array('dejavusans', '', 8, '', false));
     $pdf->setFooterFont(array('dejavusans', '', 8, '', false));
     $pdf->SetFont('dejavusans', '', 8, '', false);
     if (!empty($certificate)) {
         $pdf->setSignature($certificate, $secretkey, $secretKeyPass, $extracerts);
     }
     return $pdf;
 }
Example #3
1
<?php

require_once '../TCPDF/tcpdf.php';
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->AddPage();
// Set some content to print
$html = 'costam';
$certificate = 'file://' . __DIR__ . '/../rsa/cert.crt';
$privatekey = 'file://' . __DIR__ . '/../rsa/private.pem';
// Print text using writeHTMLCell()
$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
// set additional information
$info = array('Name' => 'Test', 'Location' => 'Infinite Loop 1, California, USA', 'Reason' => '', 'ContactInfo' => 'http://www.test.com');
// set document signature
$pdf->setSignature($certificate, $privatekey, 'VdcpDTWTc5Aehxgv2uL9haaFddDBhrc8uCMG3ykg', '', 1, $info);
$string = $pdf->Output('pdf.pdf', 'S');
$output = file_put_contents('pdf.pdf', $string);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
// ---------------------------------------------------------
/*
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
*/
// set certificate file
$certificate = 'file://../config/cert/tcpdf.crt';
// set additional information
$info = array('Name' => 'TCPDF', 'Location' => 'Office', 'Reason' => 'Testing TCPDF', 'ContactInfo' => 'http://www.tcpdf.org');
// set document signature
$pdf->setSignature($certificate, $certificate, 'tcpdfdemo', '', 2, $info);
// set font
$pdf->SetFont('helvetica', '', 12);
// add a page
$pdf->AddPage();
// print a line of text
$text = 'This is a <b color="#FF0000">digitally signed document</b> using the default (example) <b>tcpdf.crt</b> certificate.<br />To validate this signature you have to load the <b color="#006600">tcpdf.fdf</b> on the Arobat Reader to add the certificate to <i>List of Trusted Identities</i>.<br /><br />For more information check the source code of this example and the source code documentation for the <i>setSignature()</i> method.<br /><br /><a href="http://www.tcpdf.org">www.tcpdf.org</a>';
$pdf->writeHTML($text, true, 0, true, 0);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// *** set signature appearance ***
// create content for signature (image and/or text)
$pdf->Image('../images/tcpdf_signature.png', 180, 60, 15, 15, 'PNG');
// define active area for signature appearance
$pdf->setSignatureAppearance(180, 60, 15, 15);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// *** set an empty signature appearance ***