diff --git a/CHANGELOG.TXT b/CHANGELOG.TXT index 423b606..a2dce13 100644 --- a/CHANGELOG.TXT +++ b/CHANGELOG.TXT @@ -1,3 +1,8 @@ +6.0.085 (2014-06-19) + - Some example images were replaced. + - A race condition bug was fixed. + - Bug item #938 "Hyphenation-dash extends outside of cell" was fixed. + 6.0.084 (2014-06-13) - A bug related to MultiCell fitcell feature was fixed. - Bug item #931 "Documentation error for setPageFormat()" was fixed. diff --git a/README.TXT b/README.TXT index 07192f8..109e2b4 100644 --- a/README.TXT +++ b/README.TXT @@ -8,8 +8,8 @@ http://sourceforge.net/donate/index.php?group_id=128076 ------------------------------------------------------------ Name: TCPDF -Version: 6.0.084 -Release date: 2014-06-13 +Version: 6.0.085 +Release date: 2014-06-19 Author: Nicola Asuni Copyright (c) 2002-2014: diff --git a/composer.json b/composer.json index 202b032..ab7ea23 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "tecnick.com/tcpdf", - "version": "6.0.084", + "version": "6.0.085", "homepage": "http://www.tcpdf.org/", "type": "library", "description": "TCPDF is a PHP class for generating PDF documents.", diff --git a/examples/example_006.php b/examples/example_006.php index c1557a4..481f70e 100644 --- a/examples/example_006.php +++ b/examples/example_006.php @@ -109,7 +109,7 @@ List example:
White cold drink
IMAGES
-test alt attributetest alt attributetest alt attribute +test alt attributetest alt attributetest alt attribute
'; // output the HTML content diff --git a/examples/example_032.php b/examples/example_032.php index 8f042d7..b38f5ae 100644 --- a/examples/example_032.php +++ b/examples/example_032.php @@ -2,7 +2,7 @@ //============================================================+ // File name : example_032.php // Begin : 2008-06-09 -// Last Update : 2013-05-14 +// Last Update : 2013-06-19 // // Description : Example 032 for TCPDF class // EPS/AI image @@ -71,17 +71,15 @@ $pdf->SetFont('helvetica', '', 12); $pdf->AddPage(); -$pdf->Write(0, 'Example of ImageEPS() method for AI and EPS images'); +$html = << +NOTE: Please use SVG format for a better vector support. +EOD; -$pdf->ImageEps($file='images/tiger.ai', $x=10, $y=50, $w=190, $h=190, $link='', $useBoundingBox=true, $align='', $palign='', $border=0, $fitonpage=false); +// Print text using writeHTMLCell() +$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); -$pdf->AddPage(); - -$pdf->ImageEps('images/bug.eps', 0, 25, 0, 240, "http://www.tcpdf.org", true, 'T', 'C'); - -$pdf->AddPage(); - -$pdf->ImageEps('images/pelican.ai', 15, 70, 180); +$pdf->ImageEps('images/tcpdf_box.ai', 10, 40, 150, '', 'http://www.tcpdf.org', true, '', '', 0, false); // --------------------------------------------------------- diff --git a/examples/example_039.php b/examples/example_039.php index 1784381..4a8775c 100644 --- a/examples/example_039.php +++ b/examples/example_039.php @@ -75,7 +75,7 @@ $pdf->SetFont('helvetica', 'B', 20); $pdf->Write(0, 'Example of HTML Justification', '', 0, 'L', true, 0, false, false, 0); // create some HTML content -$html = 'a abc abcdefghijkl (abcdef) abcdefg abcdefghi a ((abc)) abcd test alt attribute abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc \(abcd\) abcdef abcdefg abcdefghi a abc \\\(abcd\\\) abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg start a abc before yellow color after a abc abcd abcdef abcdefg abcdefghi a abc abcd end abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi
abcd abcdef abcdefg abcdefghi
abcd abcde abcdef
'; +$html = 'a abc abcdefghijkl (abcdef) abcdefg abcdefghi a ((abc)) abcd test alt attribute abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc \(abcd\) abcdef abcdefg abcdefghi a abc \\\(abcd\\\) abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg start a abc before yellow color after a abc abcd abcdef abcdefg abcdefghi a abc abcd end abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi
abcd abcdef abcdefg abcdefghi
abcd abcde abcdef
'; // set core font $pdf->SetFont('helvetica', '', 10); diff --git a/examples/images/alpha.png b/examples/images/alpha.png index 08daf2d..5447918 100644 Binary files a/examples/images/alpha.png and b/examples/images/alpha.png differ diff --git a/examples/images/image_with_alpha.png b/examples/images/image_with_alpha.png index 27df6af..3011618 100644 Binary files a/examples/images/image_with_alpha.png and b/examples/images/image_with_alpha.png differ diff --git a/examples/images/img.png b/examples/images/img.png index 1816e3f..9c1a075 100644 Binary files a/examples/images/img.png and b/examples/images/img.png differ diff --git a/examples/images/tcpdf_box.ai b/examples/images/tcpdf_box.ai new file mode 100644 index 0000000..0c14846 --- /dev/null +++ b/examples/images/tcpdf_box.ai @@ -0,0 +1,214 @@ +%!PS-Adobe-3.0 EPSF +%%Creator: Adobe Illustrator +%%BoundingBox: -7 0 487 327 +%%HiResBoundingBox: -6.66162 2.44007e-05 486.662 326.648 +%AI5_FileFormat 3 +%%EndComments +%%BeginProlog +%%EndProlog +%%BeginSetup +%%EndSetup +1 XR +%AI5_BeginLayer +1 1 1 1 0 0 -1 49 80 161 Lb +(New Layer) Ln +0.620000 0.580000 0.435000 0.996000 K +[] 0 d +1.402287 w +0 j +0 J +0.263000 0.290000 0.898000 0.263000 k +72.7885 255.643 m +277.08 286.778 L +425.478 260.993 L +408.269 190.301 L +113.504 181.247 L +113.504 181.247 72.9813 241.769 72.7885 255.643 C +b +0.620000 0.580000 0.435000 0.996000 K +1 j +0.094000 0.102000 0.369000 0.016000 k +423.247 259.914 m +240.217 207.097 L +240.635 0.701168 L +397.776 116.053 L +423.247 259.914 L +b +0.620000 0.580000 0.435000 0.996000 K +0.133000 0.141000 0.541000 0.035000 k +72.1745 254.207 m +240.217 207.097 L +240.561 0.783816 L +101.054 87.946 L +72.1745 254.207 L +b +0.047000 0.059000 0.184000 0.004000 k +423.247 259.914 m +308.187 51.1553 L +396.862 116.972 L +423.247 259.914 L +f +0.620000 0.580000 0.435000 0.996000 K +0 j +0.047000 0.059000 0.184000 0.004000 k +479.312 250.415 m +423.613 260.243 L +240.385 206.966 L +314.061 186.394 L +479.312 250.415 L +b +0.620000 0.580000 0.435000 0.996000 K +0.047000 0.059000 0.184000 0.004000 k +69.9121 254.273 m +237.965 207.131 L +163.618 164.537 L +0.687544 234.686 L +69.9121 254.273 L +b +0.620000 0.580000 0.435000 0.996000 K +0.047000 0.059000 0.184000 0.004000 k +242.971 319.299 m +275.613 286.233 L +72.5703 254.295 L +16.555 296.161 L +242.971 319.299 L +b +0.620000 0.580000 0.435000 0.996000 K +0.133000 0.141000 0.541000 0.035000 k +423.496 260.684 m +275.426 286.441 L +307.326 316.69 L +462.053 292.606 L +423.496 260.684 L +b +0.196000 0.227000 0.871000 0.106000 k +75.26 254.037 m +274.806 285.371 L +227.928 211.257 L +163.396 228.836 130.937 238.701 75.26 254.037 C +f +0.620000 0.580000 0.435000 0.996000 K +1 j +0.169000 0.314000 0.424000 0.094000 k +275.528 286.329 m +274.75 216.78 L +275.528 286.329 L +b +0.031000 0.949000 0.745000 0.729000 k +285.929 160.982 m +285.929 160.982 285.078 139.734 285.078 139.734 C +285.078 139.734 275.378 135.096 275.378 135.096 C +275.378 135.096 273.058 57.6061 273.058 57.6061 C +273.058 57.6061 257.133 47.3536 257.133 47.3536 C +257.133 47.3536 258.059 126.816 258.059 126.816 C +258.059 126.816 247.186 121.618 247.186 121.618 C +247.186 121.618 247.186 144.26 247.186 144.26 C +247.186 144.26 285.929 160.982 285.929 160.982 C +F +0.031000 0.949000 0.745000 0.729000 k +320.884 135.342 m +320.884 135.342 307.279 128.129 307.279 128.129 C +307.279 128.129 308.36 144.944 308.36 144.944 C +308.681 149.948 308.724 153.011 308.483 154.097 C +308.268 155.24 307.632 155.567 306.572 155.073 C +305.368 154.512 304.553 153.381 304.135 151.687 C +303.718 149.995 303.36 146.608 303.063 141.565 C +303.063 141.565 300.477 97.6864 300.477 97.6864 C +300.22 93.3298 300.208 90.6032 300.439 89.4791 C +300.668 88.3599 301.318 88.1316 302.385 88.7881 C +303.403 89.4149 304.103 90.4684 304.487 91.9528 C +304.894 93.4524 305.253 96.6211 305.567 101.497 C +305.567 101.497 306.297 112.86 306.297 112.86 C +306.297 112.86 319.718 120.438 319.718 120.438 C +319.718 120.438 319.446 116.964 319.446 116.964 C +318.734 107.862 317.873 101.293 316.856 97.1389 C +315.864 93.0164 314.026 88.8059 311.329 84.474 C +308.636 80.1307 305.421 76.743 301.646 74.2975 C +297.651 71.7096 294.365 70.7251 291.812 71.3887 C +289.213 72.064 287.545 74.2699 286.838 78.0362 C +286.121 81.8925 285.954 88.3297 286.349 97.4441 C +286.349 97.4441 287.575 125.751 287.575 125.751 C +287.89 133.007 288.277 138.586 288.737 142.421 C +289.202 146.323 290.251 150.369 291.883 154.544 C +293.54 158.732 295.716 162.4 298.394 165.529 C +301.078 168.689 304.052 170.959 307.296 172.342 C +311.621 174.188 315.02 174.154 317.521 172.296 C +319.974 170.473 321.427 167.541 321.911 163.514 C +322.39 159.578 322.275 153.119 321.579 144.225 C +321.579 144.225 320.884 135.342 320.884 135.342 C +F +0.031000 0.949000 0.745000 0.729000 k +*u +329.084 179.607 m +329.084 179.607 342.074 185.214 342.074 185.214 C +345.446 186.669 347.94 187.235 349.586 186.932 C +351.233 186.642 352.374 185.695 353.019 184.1 C +353.677 182.527 353.999 180.418 353.991 177.777 C +354.005 175.2 353.703 171.072 353.088 165.429 C +353.088 165.429 352.244 157.683 352.244 157.683 C +351.634 152.084 350.908 147.89 350.063 145.056 C +349.22 142.228 347.957 139.718 346.265 137.514 C +344.583 135.308 342.474 133.487 339.919 132.046 C +339.919 132.046 336.736 130.25 336.736 130.25 C +336.736 130.25 333.512 96.527 333.512 96.527 C +333.512 96.527 321.545 88.8222 321.545 88.8222 C +321.545 88.8222 329.084 179.607 329.084 179.607 C +F +340.42 168.795 m +340.42 168.795 338.184 145.407 338.184 145.407 C +338.526 145.552 338.82 145.69 339.068 145.822 C +340.172 146.404 340.98 147.319 341.498 148.568 C +342.038 149.863 342.473 152.174 342.805 155.518 C +342.805 155.518 343.55 163.014 343.55 163.014 C +343.863 166.167 343.82 168.111 343.416 168.832 C +343.011 169.557 342.015 169.547 340.42 168.795 C +F +*U +0.031000 0.949000 0.745000 0.729000 k +*u +359.204 192.607 m +359.204 192.607 367.556 196.212 367.556 196.212 C +372.753 198.454 376.114 199.414 377.734 199.14 C +379.351 198.877 380.446 197.777 381.03 195.854 C +381.608 193.948 381.815 191.642 381.655 188.934 C +381.502 186.28 380.88 180.934 379.804 172.981 C +379.804 172.981 375.968 144.653 375.968 144.653 C +375.021 137.654 374.236 132.926 373.604 130.399 C +372.993 127.921 372.216 125.786 371.268 123.986 C +370.323 122.215 369.243 120.698 368.023 119.43 C +366.801 118.187 365.012 116.807 362.638 115.279 C +362.638 115.279 349.593 106.88 349.593 106.88 C +349.593 106.88 359.204 192.607 359.204 192.607 C +F +368.395 181.985 m +368.395 181.985 361.644 126.918 361.644 126.918 C +363.113 127.815 364.084 128.947 364.566 130.32 C +365.053 131.727 365.629 135.077 366.301 140.416 C +366.301 140.416 370.368 172.752 370.368 172.752 C +370.86 176.666 371.12 179.163 371.145 180.223 C +371.168 181.285 371.006 181.972 370.654 182.282 C +370.306 182.629 369.555 182.531 368.395 181.985 C +F +*U +0.031000 0.949000 0.745000 0.729000 k +387.58 204.854 m +387.58 204.854 403.348 211.659 403.348 211.659 C +403.348 211.659 400.803 195.062 400.803 195.062 C +400.803 195.062 394.579 192.087 394.579 192.087 C +394.579 192.087 392.296 176.619 392.296 176.619 C +392.296 176.619 397.801 179.482 397.801 179.482 C +397.801 179.482 395.533 164.634 395.533 164.634 C +395.533 164.634 390.075 161.574 390.075 161.574 C +390.075 161.574 385.406 129.937 385.406 129.937 C +385.406 129.937 376.374 124.122 376.374 124.122 C +376.374 124.122 387.58 204.854 387.58 204.854 C +F +LB +%AI5_EndLayer-- +%AI5_BeginLayer +1 1 1 1 0 0 -1 49 80 161 Lb +(MasterLayer 1) Ln +LB +%AI5_EndLayer-- +%%Trailer +%%EOF diff --git a/examples/images/tcpdf_box.svg b/examples/images/tcpdf_box.svg new file mode 100644 index 0000000..8c29e64 --- /dev/null +++ b/examples/images/tcpdf_box.svg @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + diff --git a/include/tcpdf_static.php b/include/tcpdf_static.php index a4c5740..1a6d297 100644 --- a/include/tcpdf_static.php +++ b/include/tcpdf_static.php @@ -55,7 +55,7 @@ class TCPDF_STATIC { * Current TCPDF version. * @private static */ - private static $tcpdf_version = '6.0.084'; + private static $tcpdf_version = '6.0.085'; /** * String alias for total number of pages. diff --git a/tcpdf.php b/tcpdf.php index 80b584c..bac88c5 100644 --- a/tcpdf.php +++ b/tcpdf.php @@ -1,9 +1,9 @@ * @package com.tecnick.tcpdf * @author Nicola Asuni - * @version 6.0.084 + * @version 6.0.085 */ // TCPDF configuration @@ -128,7 +128,7 @@ require_once(dirname(__FILE__).'/include/tcpdf_static.php'); * TCPDF project (http://www.tcpdf.org) has been originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.
* @package com.tecnick.tcpdf * @brief PHP class for generating PDF documents without requiring external extensions. - * @version 6.0.084 + * @version 6.0.085 * @author Nicola Asuni - info@tecnick.com */ class TCPDF { @@ -1288,6 +1288,20 @@ class TCPDF { */ protected $empty_signature_appearance = array(); + /** + * Boolean flag to enable document timestamping with TSA. + * @protected + * @since 6.0.085 (2014-06-19) + */ + protected $tsa_timestamp = false; + + /** + * Timestamping data. + * @protected + * @since 6.0.085 (2014-06-19) + */ + protected $tsa_data = array(); + /** * Regular expression used to find blank characters (required for word-wrapping). * @protected @@ -1932,8 +1946,13 @@ class TCPDF { $this->bgcolor = array('R' => 255, 'G' => 255, 'B' => 255); $this->extgstates = array(); $this->setTextShadow(); - // user's rights + // signature $this->sign = false; + $this->tsa_timestamp = false; + $this->tsa_data = array(); + $this->signature_appearance = array('page' => 1, 'rect' => '0 0 0 0', 'name' => 'Signature'); + $this->empty_signature_appearance = array(); + // user's rights $this->ur['enabled'] = false; $this->ur['document'] = '/FullSave'; $this->ur['annots'] = '/Create/Delete/Modify/Copy/Import/Export'; @@ -1941,8 +1960,6 @@ class TCPDF { $this->ur['signature'] = '/Modify'; $this->ur['ef'] = '/Create/Delete/Modify/Import'; $this->ur['formex'] = ''; - $this->signature_appearance = array('page' => 1, 'rect' => '0 0 0 0', 'name' => 'Signature'); - $this->empty_signature_appearance = array(); // set default JPEG quality $this->jpeg_quality = 75; // initialize some settings @@ -6346,6 +6363,7 @@ class TCPDF { $i = 0; // character position $j = 0; // current starting position $sep = -1; // position of the last blank space + $prevsep = $sep; // previous separator $shy = false; // true if the last blank is a soft hypen (SHY) $l = 0; // current string length $nl = 0; //number of lines @@ -6405,6 +6423,7 @@ class TCPDF { $j = $i + 1; $l = 0; $sep = -1; + $prevsep = $sep; $shy = false; // account for margin changes if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) { @@ -6436,6 +6455,7 @@ class TCPDF { ) ) { // update last blank space position + $prevsep = $sep; $sep = $i; // check if is a SHY if (($c == 173) OR ($c == 45)) { @@ -6459,7 +6479,10 @@ class TCPDF { } else { $l += $this->GetCharWidth($c); } - if (($l > $wmax) OR (($c == 173) AND (($l + $tmp_shy_replacement_width) > $wmax)) ) { + if (($l > $wmax) OR (($c == 173) AND (($l + $tmp_shy_replacement_width) >= $wmax))) { + if (($c == 173) AND (($l + $tmp_shy_replacement_width) > $wmax)) { + $sep = $prevsep; + } // we have reached the end of column if ($sep == -1) { // check if the line was already started @@ -7614,6 +7637,8 @@ class TCPDF { unset($tmparr); // decode signature $signature = base64_decode(trim($signature)); + // add TSA timestamp to signature + $signature = $this->applyTSA($signature); // convert signature to hex $signature = current(unpack('H*', $signature)); $signature = str_pad($signature, $this->signature_max_length, '0'); @@ -7771,19 +7796,22 @@ class TCPDF { } unset($this->cached_files); } + $preserve = array( + 'internal_encoding', + 'state', + 'bufferlen', + 'buffer', + 'diskcache', + 'cached_files', + 'sign', + 'signature_data', + 'signature_max_length', + 'byterange_string', + 'tsa_timestamp', + 'tsa_data' + ); foreach (array_keys(get_object_vars($this)) as $val) { - if ($destroyall OR ( - ($val != 'internal_encoding') - AND ($val != 'state') - AND ($val != 'bufferlen') - AND ($val != 'buffer') - AND ($val != 'diskcache') - AND ($val != 'cached_files') - AND ($val != 'sign') - AND ($val != 'signature_data') - AND ($val != 'signature_max_length') - AND ($val != 'byterange_string') - )) { + if ($destroyall OR !in_array($val, $preserve)) { if ((!$preserve_objcopy OR ($val != 'objcopy')) AND isset($this->$val)) { unset($this->$val); } @@ -7958,7 +7986,9 @@ class TCPDF { $out = '<<'; $out .= ' /Type /Page'; $out .= ' /Parent 1 0 R'; - $out .= ' /LastModified '.$this->_datestring(0, $this->doc_modification_timestamp); + if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) { + $out .= ' /LastModified '.$this->_datestring(0, $this->doc_modification_timestamp); + } $out .= ' /Resources 2 0 R'; foreach ($this->page_boxes as $box) { $out .= ' /'.$box; @@ -9804,7 +9834,9 @@ class TCPDF { } $out .= ' /Fields ['.$objrefs.']'; // It's better to turn off this value and set the appearance stream for each annotation (/AP) to avoid conflicts with signature fields. - $out .= ' /NeedAppearances false'; + if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) { + $out .= ' /NeedAppearances false'; + } if ($this->sign AND isset($this->signature_data['cert_type'])) { if ($this->signature_data['cert_type'] > 0) { $out .= ' /SigFlags 3'; @@ -9827,7 +9859,8 @@ class TCPDF { //$out .= ' /XFA '; $out .= ' >>'; // signatures - if ($this->sign AND isset($this->signature_data['cert_type'])) { + if ($this->sign AND isset($this->signature_data['cert_type']) + AND (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A'))) { if ($this->signature_data['cert_type'] > 0) { $out .= ' /Perms << /DocMDP '.($this->sig_obj_id + 1).' 0 R >>'; } else { @@ -13370,46 +13403,48 @@ class TCPDF { $out .= ' /SubFilter /adbe.pkcs7.detached'; $out .= ' '.TCPDF_STATIC::$byterange_string; $out .= ' /Contents<'.str_repeat('0', $this->signature_max_length).'>'; - $out .= ' /Reference ['; // array of signature reference dictionaries - $out .= ' << /Type /SigRef'; - if ($this->signature_data['cert_type'] > 0) { - $out .= ' /TransformMethod /DocMDP'; - $out .= ' /TransformParams <<'; - $out .= ' /Type /TransformParams'; - $out .= ' /P '.$this->signature_data['cert_type']; - $out .= ' /V /1.2'; - } else { - $out .= ' /TransformMethod /UR3'; - $out .= ' /TransformParams <<'; - $out .= ' /Type /TransformParams'; - $out .= ' /V /2.2'; - if (!TCPDF_STATIC::empty_string($this->ur['document'])) { - $out .= ' /Document['.$this->ur['document'].']'; - } - if (!TCPDF_STATIC::empty_string($this->ur['form'])) { - $out .= ' /Form['.$this->ur['form'].']'; - } - if (!TCPDF_STATIC::empty_string($this->ur['signature'])) { - $out .= ' /Signature['.$this->ur['signature'].']'; - } - if (!TCPDF_STATIC::empty_string($this->ur['annots'])) { - $out .= ' /Annots['.$this->ur['annots'].']'; - } - if (!TCPDF_STATIC::empty_string($this->ur['ef'])) { - $out .= ' /EF['.$this->ur['ef'].']'; - } - if (!TCPDF_STATIC::empty_string($this->ur['formex'])) { - $out .= ' /FormEX['.$this->ur['formex'].']'; + if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) { + $out .= ' /Reference ['; // array of signature reference dictionaries + $out .= ' << /Type /SigRef'; + if ($this->signature_data['cert_type'] > 0) { + $out .= ' /TransformMethod /DocMDP'; + $out .= ' /TransformParams <<'; + $out .= ' /Type /TransformParams'; + $out .= ' /P '.$this->signature_data['cert_type']; + $out .= ' /V /1.2'; + } else { + $out .= ' /TransformMethod /UR3'; + $out .= ' /TransformParams <<'; + $out .= ' /Type /TransformParams'; + $out .= ' /V /2.2'; + if (!TCPDF_STATIC::empty_string($this->ur['document'])) { + $out .= ' /Document['.$this->ur['document'].']'; + } + if (!TCPDF_STATIC::empty_string($this->ur['form'])) { + $out .= ' /Form['.$this->ur['form'].']'; + } + if (!TCPDF_STATIC::empty_string($this->ur['signature'])) { + $out .= ' /Signature['.$this->ur['signature'].']'; + } + if (!TCPDF_STATIC::empty_string($this->ur['annots'])) { + $out .= ' /Annots['.$this->ur['annots'].']'; + } + if (!TCPDF_STATIC::empty_string($this->ur['ef'])) { + $out .= ' /EF['.$this->ur['ef'].']'; + } + if (!TCPDF_STATIC::empty_string($this->ur['formex'])) { + $out .= ' /FormEX['.$this->ur['formex'].']'; + } } + $out .= ' >>'; // close TransformParams + // optional digest data (values must be calculated and replaced later) + //$out .= ' /Data ********** 0 R'; + //$out .= ' /DigestMethod/MD5'; + //$out .= ' /DigestLocation[********** 34]'; + //$out .= ' /DigestValue<********************************>'; + $out .= ' >>'; + $out .= ' ]'; // end of reference } - $out .= ' >>'; // close TransformParams - // optional digest data (values must be calculated and replaced later) - //$out .= ' /Data ********** 0 R'; - //$out .= ' /DigestMethod/MD5'; - //$out .= ' /DigestLocation[********** 34]'; - //$out .= ' /DigestValue<********************************>'; - $out .= ' >>'; - $out .= ' ]'; // end of reference if (isset($this->signature_data['info']['Name']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Name'])) { $out .= ' /Name '.$this->_textstring($this->signature_data['info']['Name'], $sigobjid); } @@ -13477,11 +13512,12 @@ class TCPDF { * @param $extracerts (string) specifies the name of a file containing a bunch of extra certificates to include in the signature which can for example be used to help the recipient to verify the certificate that you used. * @param $cert_type (int) The access permissions granted for this document. Valid values shall be: 1 = No changes to the document shall be permitted; any change to the document shall invalidate the signature; 2 = Permitted changes shall be filling in forms, instantiating page templates, and signing; other changes shall invalidate the signature; 3 = Permitted changes shall be the same as for 2, as well as annotation creation, deletion, and modification; other changes shall invalidate the signature. * @param $info (array) array of option information: Name, Location, Reason, ContactInfo. + * @param $approval (string) Enable approval signature eg. for PDF incremental update * @public * @author Nicola Asuni * @since 4.6.005 (2009-04-24) */ - public function setSignature($signing_cert='', $private_key='', $private_key_password='', $extracerts='', $cert_type=2, $info=array()) { + public function setSignature($signing_cert='', $private_key='', $private_key_password='', $extracerts='', $cert_type=2, $info=array(), $approval='') { // 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 @@ -13503,6 +13539,7 @@ class TCPDF { $this->signature_data['extracerts'] = $extracerts; $this->signature_data['cert_type'] = $cert_type; $this->signature_data['info'] = $info; + $this->signature_data['approval'] = $approval; } /** @@ -13571,6 +13608,54 @@ class TCPDF { return $sigapp; } + /** + * Enable document timestamping (requires the OpenSSL Library). + * The trusted timestamping improve document security that means that no one should be able to change the document once it has been recorded. + * Use with digital signature only! + * @param $tsa_host (string) Time Stamping Authority (TSA) server (prefixed with 'https://') + * @param $tsa_username (string) Specifies the username for TSA authorization (optional) OR specifies the TSA authorization PEM file (see: example_66.php, optional) + * @param $tsa_password (string) Specifies the password for TSA authorization (optional) + * @param $tsa_cert (string) Specifies the location of TSA certificate for authorization (optional for cURL) + * @public + * @author Richard Stockinger + * @since 6.0.085 (2014-06-16) + */ + public function setTimeStamp($tsa_host='', $tsa_username='', $tsa_password='', $tsa_cert='') { + $this->tsa_data = array(); + if (!function_exists('curl_init')) { + $this->Error('Please enable cURL PHP extension!'); + } + if (strlen($tsa_host) == 0) { + $this->Error('Please specify the host of Time Stamping Authority (TSA)!'); + } + $this->tsa_data['tsa_host'] = $tsa_host; + if (is_file($tsa_username)) { + $this->tsa_data['tsa_auth'] = $tsa_username; + } else { + $this->tsa_data['tsa_username'] = $tsa_username; + } + $this->tsa_data['tsa_password'] = $tsa_password; + $this->tsa_data['tsa_cert'] = $tsa_cert; + $this->tsa_timestamp = true; + } + + /** + * NOT YET IMPLEMENTED + * Request TSA for a timestamp + * @param $signature (string) Digital signature as binary string + * @return (string) Timestamped digital signature + * @protected + * @author Richard Stockinger + * @since 6.0.085 (2014-06-16) + */ + protected function applyTSA($signature) { + if (!$this->tsa_timestamp) { + return $signature; + } + //@TODO: implement this feature + return $signature; + } + /** * Create a new page group. * NOTE: call this function before calling AddPage() @@ -17724,22 +17809,25 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $spacew = ($spacewidth * $ns); } $offset = $strpiece[2][1] + strlen($strpiece[2][0]); - $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, $offset); - $epsposend = strpos($pmid, $this->epsmarker.'Q', $offset) + strlen($this->epsmarker.'Q'); - if ((($epsposbeg > 0) AND ($epsposend > 0) AND ($offset > $epsposbeg) AND ($offset < $epsposend)) - OR (($epsposbeg === false) AND ($epsposend > 0) AND ($offset < $epsposend))) { - // shift EPS images - $trx = sprintf('1 0 0 1 %F 0 cm', $spacew); - $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, ($prev_epsposbeg - 6)); - $pmid_b = substr($pmid, 0, $epsposbeg); - $pmid_m = substr($pmid, $epsposbeg, ($epsposend - $epsposbeg)); - $pmid_e = substr($pmid, $epsposend); - $pmid = $pmid_b."\nq\n".$trx."\n".$pmid_m."\nQ\n".$pmid_e; - $offset = $epsposend; - continue; - + $epsposend = strpos($pmid, $this->epsmarker.'Q', $offset); + if ($epsposend !== null) { + $epsposend += strlen($this->epsmarker.'Q'); + $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, $offset); + if ($epsposbeg === null) { + $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, ($prev_epsposbeg - 6)); + $prev_epsposbeg = $epsposbeg; + } + if (($epsposbeg > 0) AND ($epsposend > 0) AND ($offset > $epsposbeg) AND ($offset < $epsposend)) { + // shift EPS images + $trx = sprintf('1 0 0 1 %F 0 cm', $spacew); + $pmid_b = substr($pmid, 0, $epsposbeg); + $pmid_m = substr($pmid, $epsposbeg, ($epsposend - $epsposbeg)); + $pmid_e = substr($pmid, $epsposend); + $pmid = $pmid_b."\nq\n".$trx."\n".$pmid_m."\nQ\n".$pmid_e; + $offset = $epsposend; + continue; + } } - $prev_epsposbeg = $epsposbeg; $currentxpos = 0; // shift blocks of code switch ($strpiece[2][0]) {