Download the PHP package contoweb/laravel-pdflib without Composer

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

Laravel PDFlib

Run tests StyleCI Latest Stable Version License

This package is a Laravel wrapper for PDFlib. It makes generating high professional (Print-)PDFs with PDFlib a breeze. PDFlib is the leading developer toolbox for generating and manipulating files in the Portable Document Format (PDF).

PDFlib itself is only free to use for demonstration purposes. If you want to bring it into production, you need a PDFlib license.

Documentation

Requirements

Since PDFlib is much more powerful than any other PDF generator, it's PHP extension needs to be registered. You can download the extension file directly from the PDFlib download page.

If you need further assistance installing PDFlib, check out the installation guide.

You also need:

Please note that only supported Laravel versions are covered by test workflow!

Installation

Require this package with composer.

All basic configuration is done in the pdf.php configuration file. To publish the config, run the vendor publish command:

You can then configure paths, measure unit and so on...

Laravel 5.5+:

Laravel 5.5 uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider. If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php. Since Laravel 11, the file for providers has changed to bootstrap/providers.php.

If you want to use the PDF facade, add this to your facades in app.php:

Usage

To create a new document, you can use the make:document command:

The new document file can be found in the app/Documents directory.

app\Documents\MarketingDocument

Ìn a final step, generating a PDF is as easy as:

You can find your document in your configured export path then! But first, let us take a look how to write a simple PDF.

Quick start

Within your document file, you have a boilerplated method draw():

Here you actually write the document's content. As you can see, a small example is already boilerplated:

  1. Create a new page in the document.
  2. Use an available font from the fonts() method.
  3. Write the text.

Create a page

To create a new page, you can use

You can optionally define the width and height of your document by passing the parameters.

Using a template

In most cases, you want to write dynamic content on a already designed PDF. To use a PDF template, use the FromTemplate concern and define the template PDF in a new template() function:

Now, your first page is using the page 1 from template.pdf. As you can see, you don't need to define a page size since it's using the template's size. Don't forget to configure your templates location in the configuration file.

Preview and print PDF

If you're aware of (professional) print-ready PDFs, you may know that your print PDF isn't the same as the user finally sees.

pdf-bleed

There is a bleed box, crop marks and so on. For this case, you can use WithPreview combined with the FromTemplate concern. While your original template includes all the boxes and marks, your preview PDF is a preview of the final document.

This requires you to add a previewTemplate() and offset() method.

The offset() method defines the offset from the print PDF to the preview PDF (see image above).

Now you can generate the preview PDF with:

You can also generate the print and preview PDF in one step:

The preview PDF will be automatically named to <<name>>_preview.pdf. You can override this by passing the name in ->withPreview('othername.pdf').

Navigate on the page

To tell PDFlib where your elements should be placed, you have to set the X and Y position of your "cursor".

In the configuration file, you can define which measure unit is used for positioning. You can choose between mm or pt.

Note: It may be confusing in the beginning, but PDFlib Y axis are measured from the bottom. So position 0 0 is in the left bottom corner, not the left top corner.

Write text

To write text, you can simply use:

Don't forget to set the cursor position and use the right font before writing text. Since the package extends PDFlib, you also can pass PDFlib options as a second parameter.

You only have to use writeText when placing two text blocks next to each other. Behind the scenes, wirteText() uses PDFlibs show() method, while wirteTextLine() uses the mostly used PDFlib method fit_text_line().

If you want to go to the next line, instead of reposition your cursor every time, you can use:

To use a custom line spacing instead of 1.0, just pass it as a parameter or set the line spacing with:

Fonts

The boilerplate document loads Arial as an example font, but we don't provide a font file in the fonts folder. In this case, PDFlib tries to load it from your host fonts. You may want to use custom fonts and want ensure that your server is able to load it. So it's highly recommended to place the font files (currently .ttf and .otf is supported) inside your configured font location (see pdf.php configuration).

As a next step, you have to make the fonts available in your document. For TrueType fonts, just use the file name without the extension to auto-load the font:

An underlying font file like OpenSans-Regular.ttf has to be available in your fonts location.

Now you can use the font in your document by it's name:

You can also overwrite default font encoding and option list:

Colors

If you need to colorize your text, you can use the concern. This requires you to define custom colors:

You can use the color with:

or as a parameter when using a font:

Tables

To write a table you can follow this example:

Images

You can place images with:

This places an image with and resize it to 150x100.

Since loading rounded images is just a pain in PDFlib, you can use the method:

PDFlib functions

Since this package extending PDFlib, you can use the whole PDFlib toolkit. The PDFlib Cookbook helps a lot, even to understand this package.

Extending

This package is just a basic beginning of wrapping PDFlib. Since PDFlib brings so much more functionality, we have to put the focus on the most used functions in the beginning.

You're welcome to PR your ideas!

Customization

If you want to use a filesystem disk / path other than the config in a specific document, you can use the following concerns:

The storage and path are defined the same way as in the config file:

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-pdflib with dependencies

PHP Build Version
Package Version
Requires ext-pdflib Version *
illuminate/support Version ^9.0|^10.0|^11.0
php Version ^8.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 contoweb/laravel-pdflib contains the following files

Loading the files please wait ....