PHP Classes

PHP Image to PDF Converter: Create a PDF file from images in a directory

Recommend this page to a friend!
  Info   View files Example   View files View files (42)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 136 This week: 1All time: 9,258 This week: 560Up
Version License PHP version Categories
ppdf 1.0.0Custom (specified...5PHP 5, Graphics, Files and Folders, P...
Description 

Author

This class can create a PDF file from images in a directory.

It can scan a given directory and open image files to create a PDF document that will contain those images.

The class provides options to define the image directory, patterns to filter the image files to be included in the document and the output PDF file path.

Picture of silvio
  Performance   Level  
Name: silvio <contact>
Classes: 3 packages by
Country: Italy Italy
Age: ???
All time rank: 3683145 in Italy Italy
Week rank: 411 Up18 in Italy Italy Up

Recommendations

What is the best PHP convert docx to html with images class?
Send generated docx document as body of email message

Example

<?php
/**
 * @copyright Copyright 2020 Silvio Sparapano <ssilvio@libero.it>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 *
 * @file doxphp.php
 * This script is a general language filter for Doxygen documentation, useful for languages not supported by Doxygen.
 * It creates a php-like source code, starting from a DocBlock documented source file.
 * Doesn't matter the programming language of the source file, the script analyze only the DocBlocks inside and create minimal source code declaration for Doxygen.
 * The output can be interpreted by Doxygen as standard PHP code.
 *
 * **General info & limitations**
 * Only `@class`, `@fn`, and `@var` Doxygen commands are managed by this script (with '@', not '\'!).
 * All other Doxygen command can exists into DocBlocks but will be ignored by the script (not by Doxygen).
 * The whole source code is *not* reported to the output.
 * The output contains only the original DocBlocks, and below of each of them, one row representing the declaration of Class, Function or Variable to be documented.
 * Only documented section of the source file will be processed.
 * DocBlocks must be defined by '/** ... *' multi-line sections (not "//").
 *
 * **Classes**
 * Use the command `@class` followed by the class name.
 * The script will report to the output the DocBlock, followed by the class definition.
 * IMPORTANT: do not place other comments after `@class <className>`, on the same line. Use the following lines of the DocBlock.
 *
 * **Functions**
 * Use the command `@fn` followed by the function name, including parameters.
 * Example: @fn foo(bar)
 * This script will report to the output the DocBlock, followed by the function definition.
 * If the function belongs to a class, it's necessary to tell this to Doxygen by the command `@memberof <className>`.
 * IMPORTANT: do not place other comments after `@fn <functionName>`, on the same line. Use the following lines of the DocBlock.
 *
 * **Variables**
 * Use the command `@var` followed by the variable name.
 * Example: @var foo
 * If the variable belongs to a class, it's necessary to tell this to Doxygen by the command `@memberof <className>`.
 * IMPORTANT: do not place other comments after `@var <variableName>`, on the same line. Use the following lines of the DocBlock.
 *
 * **Doxygen Configuration**
 * From Doxygen configuration file (e.g. for javascript source code):
 * FILTER_PATTERNS = *.js="php /doxphp.php"
 *
 * @version 1.0.0
 */

require_once("ppdf.class.php");

$o = fopen('e:\test\outstream.txt', 'w');
$dox = new ppdf();
$opt = parseOptions($dox);
if(
$opt[0]){
   
$dox->run();
}elseif(
$opt[1]){
   
showHelp($dox);
}

function
cReset() {return "\033[0m";};
function
cWhite() {return "\033[37m";};
function
cRed() {return "\033[91m";};
function
cLight() {return "\033[97m";};
function
cGrey() {return "\033[90m";};

function
showHelp($dox){
   
fwrite($dox->getOutputStream(), PHP_EOL);
   
fwrite($dox->getOutputStream(), cGrey()."Usage:".cReset().PHP_EOL);
   
fwrite($dox->getOutputStream(), ' '.cLight().'> php ppdf.php [options] [-i "<input>"] [-o "<output>"] [-t "<temp>"] [-x "<filter>, <filter>, ..."] [-n "<filter>, <filter>, ..."] [-s "name|size|creation|modify[,asc|desc"]'.cReset().PHP_EOL);
   
fwrite($dox->getOutputStream(), PHP_EOL);
   
fwrite($dox->getOutputStream(), cGrey()."Options:".cReset().PHP_EOL);
   
fwrite($dox->getOutputStream(), ' '.cLight().'-i "<input>" Folder to parse for input files (default current)'.cReset().PHP_EOL);
   
fwrite($dox->getOutputStream(), ' '.cLight().'-o "<output>" Output file name whith full path (default "./output.pdf")'.cReset().PHP_EOL);
   
fwrite($dox->getOutputStream(), ' '.cLight().'-t "<temp>" Folder for temporary files (default "./temp")'.cReset().PHP_EOL);
   
fwrite($dox->getOutputStream(), ' '.cLight().'-x "<filter>, <filter>, ..." Filters for extension input filenames'.cReset().PHP_EOL);
   
fwrite($dox->getOutputStream(), ' '.cLight().'-n "<filter>, <filter>, ..." Filters for file input filenames'.cReset().PHP_EOL);
   
fwrite($dox->getOutputStream(), ' '.cLight().'-s "name|size|creation|modify[,asc|desc]" Ordering files mode'.cReset().PHP_EOL);
   
fwrite($dox->getOutputStream(), ' '.cLight().'-r Set recursive input folders mode'.cReset().PHP_EOL);
   
fwrite($dox->getOutputStream(), ' '.cLight().'-d Enable debug mode'.cReset().PHP_EOL);
   
fwrite($dox->getOutputStream(), ' '.cLight().'-h, --help Show usage'.cReset().PHP_EOL);
   
fwrite($dox->getOutputStream(), ' '.cLight().'-v, --version Show version'.cReset().PHP_EOL);
   
fwrite($dox->getOutputStream(), ' '.cLight().'-v, --manual Show manual'.cReset().PHP_EOL);
   
fwrite($dox->getOutputStream(), PHP_EOL);
}

function
parseOptions($dox) : array {

   
$ret = false;
   
$showhelp = false;
   
$options = getopt("i:o:t:x:n:s:hvmrd", ["help", "version", "manual"]);

    if(
array_key_exists("version", $options) || array_key_exists("v", $options)){
       
$dox->showVersion();
    }elseif(
array_key_exists("help", $options) || array_key_exists("h", $options)){
       
$showhelp = true;
    }elseif(
array_key_exists("manual", $options) || array_key_exists("m", $options)){
       
$dox->showMan();
       
$showhelp = true;
    }else{

       
$ret = true;

        if(
array_key_exists("i", $options)){
            if(!
$dox->setInputFolder($options['i'])){
               
$ret = false;
               
$showhelp = true;
            }
        }
        if(
array_key_exists("o", $options)){
            if(!
$dox->setOutputFile($options['o'])){
               
$ret = false;
               
$showhelp = true;
            }
        }
        if(
array_key_exists("t", $options)){
            if(!
$dox->setTempDir($options['t'])){
               
$ret = false;
               
$showhelp = true;
            }
        }
        if(
array_key_exists("x", $options)){
           
//Filter on extension of the files
           
$dox->setFilterExtension(array_map('trim', explode(",", $options['x'])));
        }
        if(
array_key_exists("n", $options)){
           
//Filter on the name of the files
           
$dox->setFilterName(array_map('trim', explode(",", $options['n'])));
        }
        if(
array_key_exists("s", $options)){
           
//Sorting mode
           
$sort = array_map('strtolower', array_map('trim', explode(",", $options['s'])));
            if(isset(
$sort[0])){
                if(isset(
$sort[1])){
                    if(!
$dox->setSort($sort[0], $sort[1])){
                       
$ret = false;
                       
$showhelp = true;
                    }
                }else{
                    if(!
$dox->setSort($sort[0])){
                       
$ret = false;
                       
$showhelp = true;
                    }
                }
            }else{
               
$ret = false;
               
$showhelp = true;
            }
        }
        if(
array_key_exists("r", $options)){
           
//Option to search in recursive subdirectory mode
           
$dox->setRecursiveMode(true);
        }else{
           
$dox->setRecursiveMode(false);
        }
        if(
array_key_exists("d", $options)){
           
//Option to set the debug mode
           
$dox->setDebugMode(true);
        }else{
           
$dox->setDebugMode(false);
        }
    }
    return [
$ret, $showhelp];
}




Details

ppdf

PDF creator from image files.


  Files folder image Files  
File Role Description
Files folder imageFPDF (2 files, 2 directories)
Accessible without login Plain text file LICENSE Lic. License text
Plain text file ppdf.class.php Class Class source
Accessible without login Plain text file ppdf.php Example Example script
Accessible without login Plain text file README.md Data Read me

  Files folder image Files  /  FPDF  
File Role Description
Files folder imagefont (14 files)
Files folder imagemakefont (22 files)
  Plain text file FPDF.class.php Class Class source
  Accessible without login Plain text file fpdf.css Data Auxiliary data

  Files folder image Files  /  FPDF  /  font  
File Role Description
  Accessible without login Plain text file courier.php Aux. Auxiliary script
  Accessible without login Plain text file courierb.php Aux. Auxiliary script
  Accessible without login Plain text file courierbi.php Aux. Auxiliary script
  Accessible without login Plain text file courieri.php Aux. Auxiliary script
  Accessible without login Plain text file helvetica.php Aux. Auxiliary script
  Accessible without login Plain text file helveticab.php Aux. Auxiliary script
  Accessible without login Plain text file helveticabi.php Aux. Auxiliary script
  Accessible without login Plain text file helveticai.php Aux. Auxiliary script
  Accessible without login Plain text file symbol.php Aux. Auxiliary script
  Accessible without login Plain text file times.php Aux. Auxiliary script
  Accessible without login Plain text file timesb.php Aux. Auxiliary script
  Accessible without login Plain text file timesbi.php Aux. Auxiliary script
  Accessible without login Plain text file timesi.php Aux. Auxiliary script
  Accessible without login Plain text file zapfdingbats.php Aux. Auxiliary script

  Files folder image Files  /  FPDF  /  makefont  
File Role Description
  Accessible without login Plain text file cp1250.map Data Auxiliary data
  Accessible without login Plain text file cp1251.map Data Auxiliary data
  Accessible without login Plain text file cp1252.map Data Auxiliary data
  Accessible without login Plain text file cp1253.map Data Auxiliary data
  Accessible without login Plain text file cp1254.map Data Auxiliary data
  Accessible without login Plain text file cp1255.map Data Auxiliary data
  Accessible without login Plain text file cp1257.map Data Auxiliary data
  Accessible without login Plain text file cp1258.map Data Auxiliary data
  Accessible without login Plain text file cp874.map Data Auxiliary data
  Accessible without login Plain text file iso-8859-1.map Data Auxiliary data
  Accessible without login Plain text file iso-8859-11.map Data Auxiliary data
  Accessible without login Plain text file iso-8859-15.map Data Auxiliary data
  Accessible without login Plain text file iso-8859-16.map Data Auxiliary data
  Accessible without login Plain text file iso-8859-2.map Data Auxiliary data
  Accessible without login Plain text file iso-8859-4.map Data Auxiliary data
  Accessible without login Plain text file iso-8859-5.map Data Auxiliary data
  Accessible without login Plain text file iso-8859-7.map Data Auxiliary data
  Accessible without login Plain text file iso-8859-9.map Data Auxiliary data
  Accessible without login Plain text file koi8-r.map Data Auxiliary data
  Accessible without login Plain text file koi8-u.map Data Auxiliary data
  Accessible without login Plain text file makefont.php Example Example script
  Plain text file ttfparser.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:136
This week:1
All time:9,258
This week:560Up