Git Product home page Git Product logo

dynamicpdf's Introduction

Dynamic PDF plugin

Plugin adds backed-end layouts and templates pdf management features to OctoberCMS.

Plugin was build on Laravel Package barryvdh/laravel-dompdf.

Features

  • Manage PDF Templates and Layouts in OctoberCMS backend
  • Example Invoice.pdf template with background image, custom header and footer, custom Open Sans font embedding
  • Simple function for rendering PDF documents inside OctoberCMS using DOMPDF library
  • Twig support in templates
  • Style templates using pure CSS

Like this plugin?

If you like this plugin, give this plugin a Like or Make donation with PayPal.

Documentation

Installation {#installation}

In order to install this plugin you have to click on Add to project or type Renatio.DynamicPDF in Backend System > Updates > Install Plugin

Using PDF templates {#using-pdf-templates}

PDF templates reside in the database and can be created in the back-end area via Settings > PDF > PDF Templates. The code specified in the template is a unique identifier and cannot be changed once created.

You can use Twig in pdf templates.

In order to render PDF template use this example method in your plugin controller:

public function pdf()
{
    try
    {
        $templateCode = 'renatio::invoice'; // unique code of the template

        $data = ['name' => 'John Doe']; // optional data used in template

        // download PDF as 'attachment', or show in browser as 'inline'
        $params = [
            'filename' => 'Invoice No. 42',
            'content_disposition' => 'attachment',
        ];

        return PDFTemplate::render($templateCode, $data, $params);

    } catch (Exception $e)
    {
        // render method may throw exception
        // handle any thrown error here
        // e.g. Flash::error($e->getMessage());
    }
}

Where $templateCode is an unique code specified when creating the template, $data is optional array of twig fields which will be replaced in template.

DOMPDF Config {#dompdf-config}

You can change DOMPDF configuration dynamically.

Config::set('dompdf.orientation', 'landscape');

PDF on CMS page {#pdf-on-cms-page}

To display PDF on CMS page you can use PHP section of the page like so:

use Renatio\DynamicPDF\Models\PDFTemplate;

function onStart()
{
    $templateCode = 'renatio::invoice';
    $data = ['name' => 'John Doe'];

    return PDFTemplate::render($templateCode, $data);
}

Background image {#background-image}

After adding background image to layout, please add this to your body tag:

<body style="background: url({{ background_img }}) top left no-repeat;">

Background image should be 96 DPI size (793 x 1121 px).

UTF-8 support {#utf-8-support}

In your layout, set the UTF-8 Metatag:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

Styling PDF {#styling-pdf}

You can use the CSS page-break-before/page-break-after properties to create a new page.

<style>
.page-break {
    page-break-after: always;
}
</style>
<h1>Page 1</h1>
<div class="page-break"></div>
<h1>Page 2</h1>

You can style pdf document in CSS layout section. Here you can check CSS support for DOMPDF.

Examples {#examples}

After installation there will an example pdf invoice document.

dynamicpdf's People

Contributors

kocholes avatar matissjanis avatar mplodowski avatar vojtasvoboda avatar

Watchers

 avatar  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.