Giter Site home page Giter Site logo

fuel-pdf's Introduction

##Developers

  • Ben Corlett (PHP Developer, TJS Technology) @ben_corlett
  • Thomas Stevens (Lead Developer, TJS Technology) @tomo89aus

##To install this package

  • Through OIL: php oil install pdf

  • Manually:

    1. Download or Clone the repo.

##How it works

The TJS Technology PDF class is a driver-based PDF class. Why reinvent the wheel when you can adapt well-developed and maintained code? You can add most of any PHP5 PDF generating libraries under the lib folder and configure it in the config files.

The PDF class then forwards any functions you call onto the parent class (you call functions using Fuel's standards - underscores as opposed to camcel-casing or pascal casing). Even if the PDF library you use takes camel-casing, you can just use underscores and this package adapts and changes your function calls so they work with the library.

##Usage To use, firstly call the static method factory() on the PDF class, and provide it one string - the driver to use (by default there are two drivers - dompdf and tcpdf). Then chain on the init() method and provide any parameters that the driver's library needs when calling a new instance. DomPDF doesn't take any input however tcpdf does (see the code under lib/tcpdf or the examples for the parameters to provide).

DomPDF example: // Create an instance of the PDF class $pdf = \PDF::factory('dompdf')->init();

TCPDF example: // Create an instance of the PDF class // Construct takes following input: $orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false $pdf = \PDF::factory('tcpdf')->init('P', 'mm', 'A4', true, 'UTF-8', false); // Of course these parameters are optional so we could just call init(). All errors are handled by the libraries themselves.

Now once you've initialised the class you use the libraries exactly as documented. See TCPDF and DomPDF documentation.

  • Note: As explained earlier, you can camelcase functions used in the PDF classes so that it feels more Fuel-like (is that a word??). // Normally, to add a page in TCPDF you call addPage(); $pdf = \PDF::factory('tcpdf')->init('P', 'mm', 'A4', true, 'UTF-8', false); $pdf->add_page(); // This works.

##Adding Libraries Adding libraries is stupidly simple.

  • Download the PHP5 PDF library.

  • Drop the folder it's contained in under the lib/ directory of this package.

  • You'll need to add the following code into the PDF config file (which you should have copied to your APPPATH/config/ directory): // Look for the following code 'drivers' => array( 'tcpdf' => array( 'includes' => array( // Relative to lib path 'tcpdf/config/lang/eng.php', 'tcpdf/tcpdf.php', ), 'class' => 'TCPDF', ), 'dompdf' => array( 'includes' => array( 'dompdf/dompdf_config.inc.php', ), 'class' => 'DOMPDF', ), ),

      // Add a new driver to the array
      'drivers'			=> array(
      	'tcpdf'		=> array(
      		'includes'	=> array(
      			// Relative to lib path
      			'tcpdf/config/lang/eng.php',
      			'tcpdf/tcpdf.php',
      		),
      		'class'		=> 'TCPDF',
      	),
      	'dompdf'	=> array(
      		'includes'	=> array(
      			'dompdf/dompdf_config.inc.php',
      		),
      		'class'		=> 'DOMPDF',
      	),
      	
      	// New Driver
      	'somenewpdfdriver' => array(
      		'includes'		=> array(
      			'somenewpdfdriver/somenewpdfdriver.php',
      		),
      		'class'			=> 'somenewpdfdriver'
      	),
      ),
    
  • Now, simply when you initialise the pdf class: $pdf = \PDF::factory('somenewpdfdriver')->init('option1', 'anotheroption');

fuel-pdf's People

Contributors

bencorlett avatar weztec avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.