Download the PHP package renatio/dynamicpdf-plugin without Composer

On this page you can find all versions of the php package renatio/dynamicpdf-plugin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package dynamicpdf-plugin

Dynamic PDF Plugin

Demo URL: https://october-demo.renatio.com/backend/backend/auth/signin

Login: dynamicpdf

Password: dynamicpdf

This plugin allows developers to create and edit PDF templates with a simple user interface.

HTML to PDF converter uses dompdf library.

Plugin uses dompdf wrapper for Laravel barryvdh/laravel-dompdf.

Like this plugin?

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

My other plugins

Please check my other plugins.

Support

Please use GitHub Issues Page to report any issues with plugin.

Reviews should not be used for getting support or reporting bugs, if you need support please use the Plugin support link.

Icon made by Darius Dan from www.flaticon.com.

Documentation

Installation

There are couple ways to install this plugin.

  1. Use php artisan plugin:install Renatio.DynamicPDF command.
  2. Use composer require renatio/dynamicpdf-plugin in project root. When you use this option you must run php artisan october:migrate after installation.

PDF content

PDF can be created in October using either PDF views or PDF templates. A PDF view is supplied by plugin in the file system in the /views directory. Whereas a PDF template is managed using the back-end interface via Settings > PDF > PDF Templates. All PDFs templates support using Twig for markup.

PDF views must be registered in the Plugin registration file with the registerPDFTemplates and registerPDFLayouts method. This will automatically generate a PDF template and layout and allows them to be customized using the back-end interface.

PDF layouts views

PDF layouts views reside in the file system and the code used represents the path to the view file. For example PDF layout with the code author.plugin::pdf.layouts.default would use the content in following file:

The content inside a PDF view file can include up to 3 sections: configuration, CSS/LESS, and HTML markup. Sections are separated with the == sequence. For example:

Note: Basic Twig tags and expressions are supported in PDF views.

The CSS/LESS section is optional and a view can contain only the configuration and HTML markup sections.

Configuration section

The configuration section sets the PDF view parameters. The following configuration parameters are supported:

Parameter Description
name the layout name, required.

Using PDF layouts

PDF layouts reside in the database and can be created by selecting Settings > PDF > PDF Templates and clicking the Layouts tab. These behave just like CMS layouts, they contain the scaffold for the PDF. PDF views and templates support the use of PDF layouts. The code specified in the layout is a unique identifier and cannot be changed once created.

PDF templates views

PDF templates reside in the file system and the code used represents the path to the view file. For example PDF template with the code author.plugin::pdf.invoice would use the content in following file:

The content inside a PDF view file can include up to 2 sections: configuration and HTML markup. Sections are separated with the == sequence. For example:

Note: Basic Twig tags and expressions are supported in PDF views.

Configuration section

The configuration section sets the PDF view parameters. The following configuration parameters are supported:

Parameter Description
title the template title, required.
layout the layout code, optional.
description the template description, optional.
size the template paper size, optional, default a4.
orientation the template paper orientation, optional, default portrait.

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.

Note: If the PDF template does not exist in the system, this code will attempt to find a PDF view with the same code.

Registering PDF templates and layouts

PDF views can be registered as templates that are automatically generated in the back-end ready for customization. PDF templates can be customized via the Settings > PDF Templates menu. The templates can be registered by adding the registerPDFTemplates method of the Plugin registration class (Plugin.php).

The method should return an array of pdf view names.

Like templates, PDF layouts can be registered by adding the registerPDFLayouts method of the Plugin registration class (Plugin.php).

The method should return an array of pdf view names.

Usage

PDF templates and layouts can be accessed in the back-end area via Settings > PDF > PDF Templates.

Layouts define the PDF scaffold, that is everything that repeats on a PDF, such as a header and footer. Each layout has unique code, optional background image, HTML content and CSS/LESS content. Not all CSS properties are supported, so check CSSCompatibility.

Templates define the actual PDF content parsed from HTML.

Configuration

The default configuration settings are set in config/dompdf.php. Copy this file to your own config directory to modify the values. You can publish the config using this command:

You can still alter the dompdf options in your code before generating the PDF using dynamic methods for all options like so:

or you can use setOption method before generating the pdf using this command:

Available options and their defaults:

See Dompdf\Options for a list of available options.

Methods

Method Description
loadTemplate($code, array $data = [], $encoding = null) Load backend template
loadLayout($code, array $data = [], $encoding = null) Load backend layout
loadHTML($string, $encoding = null) Load HTML string
loadFile($file) Load HTML string from a file
parseTemplate(Template $template, array $data = []) Parse backend template using Twig
parseLayout(Layout $layout, array $mergeData = []) Parse backend layout using Twig
getDomPDF() Get the DomPDF instance
setPaper($paper, $orientation = 'portrait') Set the paper size and orientation (default A4/portrait)
setWarnings($warnings) Show or hide warnings
output() Output the PDF as a string
save($filename) Save the PDF to a file
download($filename = 'document.pdf') Make the PDF downloadable by the user
stream($filename = 'document.pdf') Return a response with the PDF to show in the browser

All methods are available through Facade class Renatio\DynamicPDF\Classes\PDF.

Tips

Background image

To display background image added in layout use following code:

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

If you want to use better quality image like 300 DPI (2480 x 3508 px) than you need to change template options like so:

UTF-8 support

In your layout, set the UTF-8 meta tag in head section:

If you have problems with foreign characters than try to use DejaVu Sans font family.

Page breaks

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

Open basedir restriction error

On some hosting providers there were reports about open_basedir restriction problems with log file. You can change default log file destination like so:

Embed image inside PDF template

You can use absolute path for image eg. https://app.dev/path_to_your_image.

For this to work you must set isRemoteEnabled option.

I assume that $file is instance of October\Rain\Database\Attach\File.

Then in the template you can use following example code:

For retrieving stylesheets or images via http following PHP setting must be enabled allow_url_fopen.

When allow_url_fopen is disabled on server try to use relative path. You can use October getLocalPath function on the file object to retrieve it.

Download PDF via Ajax response

OctoberCMS ajax framework cannot handle this type of response.

Recommended approach is to save PDF file locally and return redirect to PDF file.

Page numbers

Page numbers can be generated using PHP. Inline PHP is disabled by default, because it can be a security risk. You can enable inline PHP using setIsPhpEnabled method.

After that you must place following code before closing </body> tag of the layout file.

Examples

Demo examples

There is a console command that will enable demo templates and layouts.

To disable demo run following command:

The first example shows invoice with custom font and image embed.

The second example shows usage of header & footer, page break, page numbers and full background image.

Render PDF in browser

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

In HTML template you can use {{ name }} to output John Doe.

Download PDF

Fluent interface

You can chain the methods:

Change paper size and orientation

Available paper sizes.

PDF on CMS page

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

Header and footer on every page

Using custom fonts

Plugin provides "Open Sans" font, which can be imported in Layout CSS section.


All versions of dynamicpdf-plugin with dependencies

PHP Build Version
Package Version
Requires october/rain Version ^3.0
composer/installers Version ~1.0
barryvdh/laravel-dompdf Version ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package renatio/dynamicpdf-plugin contains the following files

Loading the files please wait ....