Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ php:
- 7.1
- 7.2
- 7.3
- 7.4
before_install:
- composer self-update
install:
Expand Down
3 changes: 0 additions & 3 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This is the class that validates and merges configuration from your app/config files
*/
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
Expand Down
5 changes: 0 additions & 5 deletions DependencyInjection/EnseparHtml2pdfExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
* This is the class that loads and manages your bundle configuration
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class EnseparHtml2pdfExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
Expand Down
2 changes: 2 additions & 0 deletions Factory/Html2pdfFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public function __construct($orientation, $format, $lang, $unicode, $encoding, $
* @param boolean $unicode
* @param string $encoding
* @param int[] $margin
*
* @return Html2Pdf
*/
public function create($orientation = null, $format = null, $lang = null, $unicode = null, $encoding = null, $margin = null)
{
Expand Down
69 changes: 42 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,70 @@ EnseparHtml2pdfBundle
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/0e16b696-0da3-4efc-b856-60429a9672b4/mini.png)](https://insight.sensiolabs.com/projects/0e16b696-0da3-4efc-b856-60429a9672b4)
[![Build Status](https://travis-ci.org/OwlyCode/EnseparHtml2pdfBundle.svg?branch=master)](https://travis-ci.org/OwlyCode/EnseparHtml2pdfBundle)

Html2pdf for Symfony 2 as a service.
[Html2pdf](https://github.com/spipu/html2pdf) for Symfony as a service.

How to install ?
----------------
How to install?
---------------

Just add this to your composer.json file:
Use Composer to install it:

```js
"require": {
...
"ensepar/html2pdf-bundle" : "~2.0"
}
```bash
$ composer require ensepar/html2pdf-bundle
```
Enable it in the Kernel

Enable it in your `Kernel.php` file:

```php
new Ensepar\Html2pdfBundle\EnseparHtml2pdfBundle(),
```

How to use ?
------------
How to use?
-----------

In your action:
In your code:

```php
$html2pdf = $this->get('html2pdf_factory')->create();
```

You can pass every option you would pass to html2pdf, for instance :
use Ensepar\Html2pdfBundle\Factory\Html2pdfFactory;

class MyClass
{
private $html2pdfFactory;

public function __construct(Html2pdfFactory $html2pdfFactory)
{
$this->html2pdfFactory = $html2pdfFactory;
}
}

// you can also get it from the container in your controller action:
$html2pdfFactory = $this->get(Html2pdfFactory::class)->create();

```
$html2pdf = $this->get('html2pdf_factory')->create('P', 'A4', 'en', true, 'UTF-8', array(10, 15, 10, 15));

You can pass every options you would pass to html2pdf, for instance:

```php
$html2pdfFactory = $this->get(Html2pdfFactory::class)->create('P', 'A4', 'en', true, 'UTF-8', array(10, 15, 10, 15));
```

If the previous arguments are not provided, the factory uses its own default values. You can
change this default values by adding the bundle configuration to your `app/config/config.yml` :
If the previous arguments are not provided, the factory uses its own default values.
You can configure those default values by adding the bundle configuration to your config file:

```yml
```yaml
ensepar_html2pdf:
orientation: P
format: A4
lang: en
orientation: 'P'
format: 'A4'
lang: 'en'
unicode: true
encoding: UTF-8
margin: [10,15,10,15]
encoding: 'UTF-8'
margin: [10, 15, 10, 15]
```

How to run the tests ?
----------------------
Read more on the library `Html2pdf` [here](https://github.com/spipu/html2pdf/blob/master/doc/README.md).

How to run tests?
-----------------

```
composer install
Expand Down
2 changes: 1 addition & 1 deletion Tests/Fixtures/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
*/
public function getCacheDir()
{
$dir = sys_get_temp_dir().'/test_html2pdf_bundle';
$dir = sys_get_temp_dir().'/test_html2pdf_bundle_cache';
if (!is_dir($dir)) {
mkdir($dir, 0777, true);
}
Expand Down
10 changes: 5 additions & 5 deletions Tests/Fixtures/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ framework:
secret: foo

ensepar_html2pdf:
orientation: P
format: A4
lang: en
orientation: 'P'
format: 'A4'
lang: 'en'
unicode: true
encoding: UTF-8
margin: [10,15,10,15]
encoding: 'UTF-8'
margin: [10, 15, 10, 15]
14 changes: 9 additions & 5 deletions Tests/Functional/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class FunctionalTest extends KernelTestCase
{
public static function getKernelClass()
{
return 'Ensepar\Html2pdfBundle\Tests\Fixtures\AppKernel';
return AppKernel::class;
}

/**
Expand All @@ -27,16 +27,20 @@ public function testMultipleCalls()
$pdf1 = $factory->create();
$pdf1->writeHTML("<html><body><p>foo</p></body></html>");

$pdf1Output = $pdf1->output('my.pdf', 'S');

$pdf2 = $factory->create();
$pdf2->writeHTML("<html><body><p>foo</p></body></html>");

$pdf2Output = $pdf2->output('my.pdf', 'S');

// The two pdfs should have the same chars count.
if (method_exists($this, 'assertStringContainsString')) {
$this->assertStringContainsString("6020\n%%EOF", $pdf1->output('my.pdf', 'S'));
$this->assertStringContainsString("6020\n%%EOF", $pdf2->output('my.pdf', 'S'));
$this->assertStringContainsString("6434\n%%EOF", $pdf1Output);
$this->assertStringContainsString("6434\n%%EOF", $pdf2Output);
} else {
$this->assertContains("6020\n%%EOF", $pdf1->output('my.pdf', 'S'));
$this->assertContains("6020\n%%EOF", $pdf2->output('my.pdf', 'S'));
$this->assertContains("6434\n%%EOF", $pdf1Output);
$this->assertContains("6434\n%%EOF", $pdf2Output);
}
}
}
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ensepar/html2pdf-bundle",
"type": "symfony-bundle",
"description": "Use HTML2PDF as a Symfony2 Service",
"description": "Use HTML2PDF as a Symfony Service",
"keywords": ["pdf", "tcpdf", "html2pdf"],
"homepage": "https://github.com/OwlyCode/EnseparHtml2pdfBundle",
"license": "MIT",
Expand All @@ -14,13 +14,13 @@
"require": {
"php": ">=5.4",
"spipu/html2pdf": "~5.2",
"symfony/dependency-injection": "^2.7 || ^2.8 || ^3.4 || ^4.1",
"symfony/http-kernel": "^2.7 || ^2.8 || ^3.4 || ^4.1"
"symfony/dependency-injection": "^2.7 || ^2.8 || ^3.4 || ^4.1 || ^5.0",
"symfony/http-kernel": "^2.7 || ^2.8 || ^3.4 || ^4.1 || ^5.0"
},
"require-dev": {
"symfony/framework-bundle": "^2.7 || ^2.8 || ^3.4 || ^4.1",
"symfony/framework-bundle": "^2.7 || ^2.8 || ^3.4 || ^4.1 || ^5.0",
"phpunit/phpunit": "^7.2 || ^6.5 || ^4.8",
"symfony/yaml": "^2.7 || ^2.8 || ^3.4 || ^4.1"
"symfony/yaml": "^2.7 || ^2.8 || ^3.4 || ^4.1 || ^5.0"
},
"autoload": {
"psr-4": { "Ensepar\\Html2pdfBundle\\": "./" }
Expand Down