Git Product home page Git Product logo

cakephp-dompdf-view's Introduction

PDF View for the CakePHP Framework

This plugin for the CakePHP Framework allows you to use the dompdf HTML to PDF converter to easily create PDF documents. It's tightly integrated with the CakePHP view renderer.

Requirements

Installation

Download the repository and extract the archive to a folder called Dompdf in your Plugin folder.

Vendor Files

Download dompdf 0.6 and move the content of the archive to Plugin/Dompdf/Vendor/dompdf.

Cache Permissions

Please create a cache folder for dompdf called dompdf in APP/tmp/cache and change the permissions to 777.

Usage

Because of the tight integration between this plugin and CakePHP, there's only a few things you have to do to get started.

  1. Load the plugin by adding CakePlugin::load('Dompdf', array('bootstrap' => true)); to APP/Config/bootstrap.php.
  2. Instruct CakePHP to look for the PDF extension by adding Router::parseExtensions('pdf'); to APP/Config/routes.php. If you already use Router::parseExtensions in your project, simply add 'pdf' to the list.
  3. Finally, make sure that the RequestHandlerComponent is loaded for all controllers by adding public $components = array('RequestHandler'); to APP/Controller/AppController.php.

Configuration Options

Copy the APP/Plugin/Dompdf/Config/dompdf.php to APP/Config if you want to change any of the default configuration.

Layout

You'll need to create the default layout for your PDF documents by creating a file named default.ctp in APP/View/Layouts/pdf.

Views

For each action that should return a PDF, simply create a pdf folder in the folder where the views for the controller reside and create a file with the name of the action inside the pdf folder.

For example, if your controller is named DocumentsController and the action is named view, you need to create the view.ctp file in APP/View/Documents/pdf.

View Variables

There are a few view variables that you can use to change the behaviour of the view.

  • download Set to true to set a Content-Disposition header. This is ideal for file downloads.
  • name The filename that will be sent to the user, specified with the extension.
  • paperOrientation The paper orientation. Must be either 'landscape' or 'portrait'.
  • paperSize The paper size. Acceptable values include 'letter', 'legal', 'a4', etc. See CPDF_Adapter::$PAPER_SIZES.

Example:

public function view($id)
{
    // ...
    
    $params = array(
        'download' => false,
        'name' => 'example.pdf',
        'paperOrientation' => 'portrait',
        'paperSize' => 'legal'
    );
    $this->set($params);
}

URL

To access any action as a PDF, all you have to do is point your browser to the URL associated with the action in question and add '.pdf' at the end just like you would do for JSON or XML.

For example:

http://example.com/documents/view/100.pdf

cakephp-dompdf-view's People

Contributors

fdeschenes avatar

Watchers

James Cloos avatar Francisco Velazquez 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.