diff --git a/mod/assign/feedback/editpdf/fpdi/LICENSE b/mod/assign/feedback/editpdf/fpdi/LICENSE index 7b4f5302921..e33384d2159 100644 --- a/mod/assign/feedback/editpdf/fpdi/LICENSE +++ b/mod/assign/feedback/editpdf/fpdi/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Setasign - Jan Slabon, https://www.setasign.com +Copyright (c) 2017 Setasign - Jan Slabon, https://www.setasign.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/mod/assign/feedback/editpdf/fpdi/filters/FilterASCII85.php b/mod/assign/feedback/editpdf/fpdi/filters/FilterASCII85.php index b7e89663292..dc100c4c70f 100644 --- a/mod/assign/feedback/editpdf/fpdi/filters/FilterASCII85.php +++ b/mod/assign/feedback/editpdf/fpdi/filters/FilterASCII85.php @@ -3,9 +3,9 @@ * This file is part of FPDI * * @package FPDI - * @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com) + * @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com) * @license http://opensource.org/licenses/mit-license The MIT License - * @version 1.6.1 + * @version 1.6.2 */ /** diff --git a/mod/assign/feedback/editpdf/fpdi/filters/FilterASCIIHexDecode.php b/mod/assign/feedback/editpdf/fpdi/filters/FilterASCIIHexDecode.php index 66ddae48392..3c29a952b7e 100644 --- a/mod/assign/feedback/editpdf/fpdi/filters/FilterASCIIHexDecode.php +++ b/mod/assign/feedback/editpdf/fpdi/filters/FilterASCIIHexDecode.php @@ -3,9 +3,9 @@ * This file is part of FPDI * * @package FPDI - * @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com) + * @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com) * @license http://opensource.org/licenses/mit-license The MIT License - * @version 1.6.1 + * @version 1.6.2 */ /** diff --git a/mod/assign/feedback/editpdf/fpdi/filters/FilterLZW.php b/mod/assign/feedback/editpdf/fpdi/filters/FilterLZW.php index f855d22c7aa..c3d26ad5d79 100644 --- a/mod/assign/feedback/editpdf/fpdi/filters/FilterLZW.php +++ b/mod/assign/feedback/editpdf/fpdi/filters/FilterLZW.php @@ -3,9 +3,9 @@ * This file is part of FPDI * * @package FPDI - * @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com) + * @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com) * @license http://opensource.org/licenses/mit-license The MIT License - * @version 1.6.1 + * @version 1.6.2 */ /** diff --git a/mod/assign/feedback/editpdf/fpdi/fpdf_tpl.php b/mod/assign/feedback/editpdf/fpdi/fpdf_tpl.php index de746dda313..47592b270a3 100644 --- a/mod/assign/feedback/editpdf/fpdi/fpdf_tpl.php +++ b/mod/assign/feedback/editpdf/fpdi/fpdf_tpl.php @@ -3,9 +3,9 @@ * This file is part of FPDI * * @package FPDI - * @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com) + * @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com) * @license http://opensource.org/licenses/mit-license The MIT License - * @version 1.6.1 + * @version 1.6.2 */ if (!class_exists('fpdi_bridge')) { diff --git a/mod/assign/feedback/editpdf/fpdi/fpdi.php b/mod/assign/feedback/editpdf/fpdi/fpdi.php index 8ecc661d8e4..926deb5397b 100644 --- a/mod/assign/feedback/editpdf/fpdi/fpdi.php +++ b/mod/assign/feedback/editpdf/fpdi/fpdi.php @@ -3,9 +3,9 @@ * This file is part of FPDI * * @package FPDI - * @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com) + * @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com) * @license http://opensource.org/licenses/mit-license The MIT License - * @version 1.6.1 + * @version 1.6.2 */ if (!class_exists('FPDF_TPL')) { @@ -22,7 +22,7 @@ class FPDI extends FPDF_TPL * * @string */ - const VERSION = '1.6.1'; + const VERSION = '1.6.2'; /** * Actual filename @@ -88,6 +88,7 @@ class FPDI extends FPDF_TPL * * @param string $filename A valid path to the PDF document from which pages should be imported from * @return int The number of pages in the document + * @throws Exception */ public function setSourceFile($filename) { @@ -95,16 +96,27 @@ class FPDI extends FPDF_TPL if (false !== $_filename) $filename = $_filename; - $this->currentFilename = $filename; - - if (!isset($this->parsers[$filename])) { - $this->parsers[$filename] = $this->_getPdfParser($filename); - $this->setPdfVersion( - max($this->getPdfVersion(), $this->parsers[$filename]->getPdfVersion()) - ); - } + $currentFilename = $this->currentFilename; + $currentParser = $this->currentParser; - $this->currentParser = $this->parsers[$filename]; + try { + $this->currentFilename = $filename; + + if (!isset($this->parsers[$filename])) { + $this->parsers[$filename] = $this->_getPdfParser($filename); + $this->setPdfVersion( + max($this->getPdfVersion(), $this->parsers[$filename]->getPdfVersion()) + ); + } + + $this->currentParser = $this->parsers[$filename]; + + } catch (Exception $e) { + unset($this->parsers[$filename]); + $this->currentFilename = $currentFilename; + $this->currentParser = $currentParser; + throw $e; + } return $this->parsers[$filename]->getPageCount(); } diff --git a/mod/assign/feedback/editpdf/fpdi/fpdi_bridge.php b/mod/assign/feedback/editpdf/fpdi/fpdi_bridge.php index 2062185378f..8283876b171 100644 --- a/mod/assign/feedback/editpdf/fpdi/fpdi_bridge.php +++ b/mod/assign/feedback/editpdf/fpdi/fpdi_bridge.php @@ -3,9 +3,9 @@ * This file is part of FPDI * * @package FPDI - * @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com) + * @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com) * @license http://opensource.org/licenses/mit-license The MIT License - * @version 1.6.1 + * @version 1.6.2 */ /** @@ -16,12 +16,21 @@ * This way it is possible to use FPDI for both FPDF and TCPDF with one FPDI version. */ +if (!class_exists('TCPDF', false)) { /** * Class fpdi_bridge - * - * This has been modified to use the Moodle pdf class which in turn extends the TCPDF class. */ - class fpdi_bridge extends pdf + class fpdi_bridge extends FPDF + { + // empty body + } + +} else { + + /** + * Class fpdi_bridge + */ + class fpdi_bridge extends TCPDF { /** * Array of Tpl-Data @@ -194,3 +203,4 @@ return current(unpack('H*', $str)); } } +} \ No newline at end of file diff --git a/mod/assign/feedback/editpdf/fpdi/fpdi_pdf_parser.php b/mod/assign/feedback/editpdf/fpdi/fpdi_pdf_parser.php index 9e6d521a4cb..0204b9c919f 100644 --- a/mod/assign/feedback/editpdf/fpdi/fpdi_pdf_parser.php +++ b/mod/assign/feedback/editpdf/fpdi/fpdi_pdf_parser.php @@ -3,9 +3,9 @@ * This file is part of FPDI * * @package FPDI - * @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com) + * @copyright Copyright (c) 2017 Setasign - Jan Slabon (http://www.setasign.com) * @license http://opensource.org/licenses/mit-license The MIT License - * @version 1.6.1 + * @version 1.6.2 */ if (!class_exists('pdf_parser')) { @@ -155,6 +155,10 @@ class fpdi_pdf_parser extends pdf_parser if (isset($this->_pages[$this->pageNo][1][1]['/Contents'])) { $contents = $this->_getPageContent($this->_pages[$this->pageNo][1][1]['/Contents']); foreach ($contents AS $tmpContent) { + if ($tmpContent[0] !== pdf_parser::TYPE_STREAM) { + continue; + } + $buffer .= $this->_unFilterStream($tmpContent) . ' '; } } @@ -335,6 +339,10 @@ class fpdi_pdf_parser extends pdf_parser foreach ($kids as $v) { $pg = $this->resolveObject($v); + if ($pg[0] !== pdf_parser::TYPE_OBJECT) { + throw new Exception('Invalid data type in page tree.'); + } + if ($pg[1][1]['/Type'][1] === '/Pages') { // If one of the kids is an embedded // /Pages array, resolve it as well. diff --git a/mod/assign/feedback/editpdf/fpdi/pdf_context.php b/mod/assign/feedback/editpdf/fpdi/pdf_context.php index 474aa72e4a8..dac38b49a27 100644 --- a/mod/assign/feedback/editpdf/fpdi/pdf_context.php +++ b/mod/assign/feedback/editpdf/fpdi/pdf_context.php @@ -3,9 +3,9 @@ * This file is part of FPDI * * @package FPDI - * @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com) + * @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com) * @license http://opensource.org/licenses/mit-license The MIT License - * @version 1.6.1 + * @version 1.6.2 */ /** @@ -67,7 +67,14 @@ class pdf_context public function getPos() { if ($this->_mode == 0) { - return ftell($this->file); + if (feof($this->file)) { + $stat = fstat($this->file); + fseek($this->file, $stat['size']); + } + + $pos = ftell($this->file); + + return $pos; } else { return 0; } @@ -85,7 +92,7 @@ class pdf_context { if ($this->_mode == 0) { if (!is_null($pos)) { - fseek ($this->file, $pos); + fseek($this->file, $pos); } $this->buffer = $l > 0 ? fread($this->file, $l) : ''; diff --git a/mod/assign/feedback/editpdf/fpdi/pdf_parser.php b/mod/assign/feedback/editpdf/fpdi/pdf_parser.php index 490b1350c79..6151cb5cf03 100644 --- a/mod/assign/feedback/editpdf/fpdi/pdf_parser.php +++ b/mod/assign/feedback/editpdf/fpdi/pdf_parser.php @@ -3,9 +3,9 @@ * This file is part of FPDI * * @package FPDI - * @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com) + * @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com) * @license http://opensource.org/licenses/mit-license The MIT License - * @version 1.6.1 + * @version 1.6.2 */ /** diff --git a/mod/assign/feedback/editpdf/fpdi/readme_moodle.txt b/mod/assign/feedback/editpdf/fpdi/readme_moodle.txt index edc01d85d79..467cf935660 100644 --- a/mod/assign/feedback/editpdf/fpdi/readme_moodle.txt +++ b/mod/assign/feedback/editpdf/fpdi/readme_moodle.txt @@ -19,6 +19,14 @@ Installation 3) Update mod/assign/feedback/editpdf/fpdi/fpdi_bridge.php (or the replacement file) to extend 'pdf' instead of 'TCPDF'. 4) Make a note below of any changes made. +2017/10/03 +---------- +1/ Updated to 1.6.2 +2/ Cherry-picked changes in MDL-55848 +3/ Renamed 'TCPDF' to 'pdf' as stated above. + +Updated by Ankit Agarwal (MDL-60301) + 2016/11/15 ---------- diff --git a/mod/assign/feedback/editpdf/thirdpartylibs.xml b/mod/assign/feedback/editpdf/thirdpartylibs.xml index cf10e9b1496..7a80291e4dc 100644 --- a/mod/assign/feedback/editpdf/thirdpartylibs.xml +++ b/mod/assign/feedback/editpdf/thirdpartylibs.xml @@ -4,7 +4,7 @@ fpdi FPDI MIT - 1.6.1 + 1.6.2