Initial commit

This commit is contained in:
2020-10-07 10:37:15 +02:00
commit ce5f440392
28157 changed files with 4429172 additions and 0 deletions

View File

@@ -0,0 +1,182 @@
<?php
/**
* PDFMerger created by Jarrod Nettles December 2009
* @author Jarrod Nettles <jarrod@squarecrow.com>
*
* v1.0
*
* Class for easily merging PDFs (or specific pages of PDFs) together into one. Output to a file, browser, download, or return as a string.
* Unfortunately, this class does not preserve many of the enhancements your original PDF might contain. It treats
* your PDF page as an image and then concatenates them all together.
*
* Note that your PDFs are merged in the order that you provide them using the addPDF function, same as the pages.
* If you put pages 12-14 before 1-5 then 12-15 will be placed first in the output.
*
*
* Uses FPDI 1.3.1 from Setasign
* Uses FPDF 1.6 by Olivier Plathey with FPDF_TPL extension 1.1.3 by Setasign
*
* Both of these packages are free and open source software, bundled with this class for ease of use.
* They are not modified in any way. PDFMerger has all the limitations of the FPDI package - essentially, it cannot import dynamic content
* such as form fields, links or page annotations (anything not a part of the page content stream).
*
*/
namespace Clegginabox\PDFMerger;
use Exception;
use fpdi\FPDI;
use fpdf\FPDF;
class PDFMerger
{
private $_files; //['form.pdf'] ["1,2,4, 5-19"]
private $_fpdi;
/**
* Add a PDF for inclusion in the merge with a valid file path. Pages should be formatted: 1,3,6, 12-16.
* @param $filepath
* @param $pages
* @return void
*/
public function addPDF($filepath, $pages = 'all')
{
if (file_exists($filepath)) {
if (strtolower($pages) != 'all') {
$pages = $this->_rewritepages($pages);
}
$this->_files[] = array($filepath, $pages, null);
} else {
throw new Exception("Could not locate PDF on '$filepath'");
}
return $this;
}
/**
* Merges your provided PDFs and outputs to specified location.
* @param $outputmode
* @param $outputname
* @param $orientation
* @return PDF
*/
public function merge($outputmode = 'browser', $outputpath = 'newfile.pdf', $orientation = 'P')
{
if (!isset($this->_files) || !is_array($this->_files)) {
throw new Exception("No PDFs to merge.");
}
$fpdi = new FPDI;
// merger operations
foreach ($this->_files as $file) {
$filename = $file[0];
$filepages = $file[1];
$count = $fpdi->setSourceFile($filename);
//add the pages
if ($filepages == 'all') {
for ($i = 1; $i <= $count; $i++) {
$template = $fpdi->importPage($i);
$size = $fpdi->getTemplateSize($template);
$fpdi->AddPage($size['h'] > $size['w'] ? 'P' : 'L', array($size['w'], $size['h']));
$fpdi->useTemplate($template);
}
} else {
foreach ($filepages as $page) {
if (!$template = $fpdi->importPage($page)) {
throw new Exception(
"Could not load page '$page' in PDF '$filename'. Check that the page exists."
);
}
$size = $fpdi->getTemplateSize($template);
$fpdi->AddPage($size['h'] > $size['w'] ? 'P' : 'L', array($size['w'], $size['h']));
$fpdi->useTemplate($template);
}
}
}
//output operations
$mode = $this->_switchmode($outputmode);
if ($mode == 'S') {
return $fpdi->Output($outputpath, 'S');
} else {
if ($fpdi->Output($outputpath, $mode) == '') {
return true;
} else {
throw new Exception("Error outputting PDF to '$outputmode'.");
return false;
}
}
}
/**
* FPDI uses single characters for specifying the output location. Change our more descriptive string into proper format.
* @param $mode
* @return Character
*/
private function _switchmode($mode)
{
switch (strtolower($mode)) {
case 'download':
return 'D';
break;
case 'browser':
return 'I';
break;
case 'file':
return 'F';
break;
case 'string':
return 'S';
break;
default:
return 'I';
break;
}
}
/**
* Takes our provided pages in the form of 1,3,4,16-50 and creates an array of all pages
* @param $pages
* @return unknown_type
*/
private function _rewritepages($pages)
{
$pages = str_replace(' ', '', $pages);
$part = explode(',', $pages);
$newpages = array();
//parse hyphens
foreach ($part as $i) {
$ind = explode('-', $i);
if (count($ind) == 2) {
$x = $ind[0]; //start page
$y = $ind[1]; //end page
if ($x > $y) {
throw new Exception("Starting page, '$x' is greater than ending page '$y'.");
return false;
}
//add middle pages
while ($x <= $y) {
$newpages[] = (int) $x;
$x++;
}
} else {
$newpages[] = (int) $ind[0];
}
}
return $newpages;
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,35 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;