Download the PHP package timatanga/content2pdf without Composer

On this page you can find all versions of the php package timatanga/content2pdf. 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 content2pdf

Content2Pdf

Render PDF documents based on different content is a basic requirement for web applications. This package is a wrapper around the amazing mPDF PHP library with some simplified access methods.

Installation

composer require dbisapps/content2pdf

Documentation

Please refer to the mPDF documentation https://mpdf.github.io/ for PDF rendering options.

Configuration

Providing layout templates is an easy way to support web applications for a consistent look and feel of PDF documents. This packages supports template configurations by a configuration file. Please refer to the mPDF package for supported options.

'default' =>    [
    'mode'                      => 'de_DE',
    'format'                    => 'A4',
    'orientation'               => 'P',
    'margin_left'               => 15,
    'margin_right'              => 15,
    'margin_top'                => 15,
    'margin_bottom'             => 15,
    'margin_header'             => 10,
    'margin_footer'             => 10,
    'default_font_size'         => '11',
    'default_font'              => 'sans-serif',
],

'invoice' => [
],

The configuration file is named templates.php and is located within the packages config directory.

Laravel Configuration

While executing Laravel's vendor:publish command, the config file will be copied as template.php to Laravels config directory. Once the configuration has been published, its values may be accessed like any other configuration file:

config('template.default')

Render HTML Content as PDF

Render HTML content as PDF is as easy as:

$pdf = new Html2PDF;

$pdf->include([
    'body' => 
        '<html><body>
            <h1>Test</h1>
            <p><img src="//localhost/image.jpg"></a></p>
        </body></html>'
]);

$output = pdf->stream();

Above commands includes the given HTML body in the document and streams the PDF as string. On top or instead of template configurations, custom options can be passed to the constructor as second argument. Please refer to the mPdf documentation for further details https://mpdf.github.io/configuration/configuration-v7-x.html

Please take note that configuration options are overriding template settings.

$pdf = new Html2PDF('default', ['orientation' => 'L']);

Besides the HTML body which is floating over as many pages as are required, provided header and footer content is printed on every page:

$pdf = new Html2PDF('default', ['orientation' => 'L']);

$pdf->include([
    'header' => 
        '<div>This is a header printed on every page</div>',
    'body' => 
        '<html><body>
            <h1>Test</h1>
            <p><img src="//localhost/image.jpg"></a></p>
        </body></html>'
    'footer' => 
        '<footer>This is a footer printed on every page</footer>',
]);

A PDF document can be enriched by metadata like title, subject, author and keywords:

$pdf = new Html2PDF('default', ['orientation' => 'L']);

$pdf->include([
    'meta' => [
        'title' => 'Test Document',
        'subject' => 'Just for testing purposes',
        'author' => 'John Doe',
        'keywords' => ['test', 'html2pdf'],
    ],
    'header' => 
        '<div>This is a header printed on every page</div>',
    'body' => 
        '<html><body>
            <h1>Test</h1>
            <p><img src="//localhost/image.jpg"></a></p>
        </body></html>'
    'footer' => 
        '<footer>This is a footer printed on every page</footer>',
]);

Render an HTML page without styles, uugg that sounds like an ugly plan, but wait there is a further option:

$pdf = new Html2PDF('default', ['orientation' => 'L']);

$pdf->include([
    'meta' => [
        'title' => 'Test Document',
        'subject' => 'Just for testing purposes',
        'author' => 'John Doe',
        'keywords' => ['test', 'html2pdf'],
    ],
    'header' => 
        '<div>This is a header printed on every page</div>',
    'body' => 
        '<html><body>
            <h1>Test</h1>
            <p><img src="//localhost/image.jpg"></a></p>
        </body></html>'
    'footer' => 
        '<footer>This is a footer printed on every page</footer>',
    'stylesheet' => '<include the stylesheet here>'
]);

Render Image as PDF

For sure, images can be included within HTML content and rendered as described above. When you think of images or screenshots you'd like to format in a printable manner there must be a better choice. For this reasing the Image2Pdf come to rescue.

An image size is can be automatically constrained to current page margins or otherwise being croped and split on multiple pages. While the image width is always constrained within the page margins, it's height is croped when it doesn't fit on a page.

All configuration options described above are applicable for image contents except "body" which is only valid for HTML content. In place of "body", the key "image" comes into play:

$pdf = new Image2Pdf('default',);

$pdf->include([
    'header' => 
        '<div>This is a header printed on every page</div>',
    'image' => 'path/location of image',
    'footer' => 
        '<footer>This is a footer printed on every page</footer>',
]);

PDF Output

Streaming PDF content as string is just one of several options.

 // finalise the document and return the document as a string
$pdf->stream();

// finalise the document and send the file inline to the browser
$pdf->inline($filename);

// finalise the document and send to the browser and force a file download
$pdf->download($filename);

// finalise the document and save to a local file with the name given by $filename
$pdf->save($filename = 'document.pdf')

Accessing mPDF capabilities

Any methods provided by the underlying mPdf package are accessible via magic PHP methods. Both classes, Html2Pdf as well as Image2Pdf are passing any call to an unknown property or method to the mPdf class. Therefor you can see these two classes as syntactic sugar on top of mPDF.


All versions of content2pdf with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
mpdf/mpdf Version dev-development
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 timatanga/content2pdf contains the following files

Loading the files please wait ....