diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ec68ea --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/vendor/ +composer.lock +coverage.html diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..7cbd3c5 --- /dev/null +++ b/composer.json @@ -0,0 +1,20 @@ +{ + "name": "czproject/pdf-rotate", + "type": "library", + "description": "Rotation of PDF pages.", + "license": "BSD-3-Clause", + "authors": [ + { + "name": "Jan Pecha", + "homepage": "https://www.janpecha.cz/" + } + ], + "require": { + "php": ">=5.3.0", + "setasign/fpdi": "^1.6", + "setasign/fpdi-fpdf": "^1.6" + }, + "autoload": { + "classmap": ["src/"] + } +} diff --git a/license.md b/license.md new file mode 100644 index 0000000..4c52135 --- /dev/null +++ b/license.md @@ -0,0 +1,26 @@ +New BSD License +--------------- + +Copyright © 2016 Jan Pecha (https://www.janpecha.cz/) All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. +* Neither the name of “CzProject“ nor the names of its contributors may be used to + endorse or promote products derived from this software without specific prior + written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..0f93a04 --- /dev/null +++ b/readme.md @@ -0,0 +1,35 @@ + +# PdfRotate + +## Usage + + +``` php +rotatePdf($sourceFile, $outputFile, $pdf::DEGREES_90); +``` + + +Installation +------------ + +[Download a latest package](https://github.com/czproject/pdf-rotate/releases) or use [Composer](http://getcomposer.org/): + +``` +composer require [--dev] czproject/pdf-rotate +``` + +`CzProject\PdfRotate` requires PHP 5.3.0 or later. + + +------------------------------ + +License: [New BSD License](license.md) +
Author: Jan Pecha, https://www.janpecha.cz/ diff --git a/src/PdfRotate.php b/src/PdfRotate.php new file mode 100644 index 0000000..81ed379 --- /dev/null +++ b/src/PdfRotate.php @@ -0,0 +1,42 @@ +setSourceFile($sourceFile); //the original file + + for ($i = 1; $i <= $pageCount; $i++) { + $pageformat = array('Rotate' => $degrees); + + $tpage = $pdf->importPage($i); + $size = $pdf->getTemplateSize($tpage); + + // get original page orientation + $orientation = $size['w'] > $size['h'] ? 'L' : 'P'; + + $pdf->AddPage($orientation, '', $degrees); + $pdf->useTemplate($tpage); + } + + $pdf->Output($outputFile, "F"); + } + }