[347] | 1 | # How to Install Html2Pdf
|
---|
| 2 |
|
---|
| 3 | [back](./README.md)
|
---|
| 4 |
|
---|
| 5 | ## Composer and Packagist
|
---|
| 6 |
|
---|
| 7 | You must use Composer to install Html2Pdf.
|
---|
| 8 |
|
---|
| 9 | If you do not know what is Composer, you are a few years late...
|
---|
| 10 |
|
---|
| 11 | It is used by all the modern PHP applications (Magento2, Drupal, EasyPlatform, Symfony, ...).
|
---|
| 12 |
|
---|
| 13 | You can read all the pages on https://getcomposer.org/doc/
|
---|
| 14 |
|
---|
| 15 | You can find all the available packages on https://packagist.org/
|
---|
| 16 |
|
---|
| 17 | For example, you can find Html2Pdf: https://packagist.org/packages/spipu/html2pdf
|
---|
| 18 |
|
---|
| 19 | You have to commit the `composer.json` and `composer.lock` files, but **never** commit the `vendor` folder.
|
---|
| 20 |
|
---|
| 21 | If you do not understand why, it is because you have not read the Composer documentation...
|
---|
| 22 |
|
---|
| 23 | ## Install
|
---|
| 24 |
|
---|
| 25 | You have just to launch the following command on the root folder of your project:
|
---|
| 26 |
|
---|
| 27 | ```bash
|
---|
| 28 | composer require spipu/html2pdf
|
---|
| 29 | ```
|
---|
| 30 |
|
---|
| 31 | ### First Test
|
---|
| 32 |
|
---|
| 33 | Here is a HelloWorld example, that you can put on the root folder of your project.
|
---|
| 34 |
|
---|
| 35 | ```php
|
---|
| 36 | require __DIR__.'/vendor/autoload.php';
|
---|
| 37 |
|
---|
| 38 | use Spipu\Html2Pdf\Html2Pdf;
|
---|
| 39 |
|
---|
| 40 | $html2pdf = new Html2Pdf();
|
---|
| 41 | $html2pdf->writeHTML('<h1>HelloWorld</h1>This is my first test');
|
---|
| 42 | $html2pdf->output();
|
---|
| 43 | ```
|
---|
| 44 |
|
---|
| 45 | Html2Pdf use the PSR-4 autoloader of Composer. You have just to require it. Never require manually the classes, it will not work at all. You must use the Composer functionnalities.
|
---|
| 46 |
|
---|
| 47 | Then, you have just to use the main class `Spipu\Html2Pdf\Html2Pdf`, with the 2 main methods `writeHTML` and `output`.
|
---|
| 48 |
|
---|
| 49 | ### And on production ?
|
---|
| 50 |
|
---|
| 51 | You have **not** to install composer on your production server.
|
---|
| 52 |
|
---|
| 53 | You have to install composer **only** on your dev environement. Composer is a dev tool.
|
---|
| 54 |
|
---|
| 55 | To deliver you app on a server, you have to (on you dev environement) :
|
---|
| 56 |
|
---|
| 57 | * Git clone the tag/branch that you want to deliver
|
---|
| 58 | * Launch the command `composer install --no-dev`
|
---|
| 59 | * Remove the useless files (like the `.git` folder)
|
---|
| 60 | * Zip all
|
---|
| 61 |
|
---|
| 62 | That's all, you have a beautifull package that can be deliver on a server !
|
---|
| 63 |
|
---|
| 64 | [back](./README.md)
|
---|