@@ -18,16 +18,17 @@ With [composer](https://getcomposer.org), require:
18
18
19
19
` composer require knplabs/knp-snappy-bundle `
20
20
21
- Then enable it in your kernel (optional if you are using the Flex recipe with Symfony4 ) :
21
+ Then enable it in your kernel (optional if you are using the Flex recipe with Symfony >= 4 ) :
22
22
23
23
``` php
24
- // app/AppKernel.php
25
- public function registerBundles()
26
- {
27
- $bundles = array(
28
- //...
29
- new Knp\Bundle\SnappyBundle\KnpSnappyBundle(),
30
- //...
24
+ // config/bundles.php
25
+ <?php
26
+
27
+ return [
28
+ //...
29
+ Knp\Bundle\SnappyBundle\KnpSnappyBundle::class => ['all' => true],
30
+ //...
31
+ ];
31
32
```
32
33
Configuration
33
34
-------------
@@ -74,25 +75,29 @@ The bundle registers two services:
74
75
# ## Generate an image from a URL
75
76
76
77
` ` ` php
77
- $container->get('knp_snappy.image')->generate('http://www.google.fr', '/path/to/the/image.jpg');
78
+ // @var Knp\S nappy\I mage
79
+ $knpSnappyImage->generate('http://www.google.fr', '/path/to/the/image.jpg');
78
80
` ` `
79
81
80
82
# ## Generate a pdf document from a URL
81
83
82
84
` ` ` php
83
- $container->get('knp_snappy.pdf')->generate('http://www.google.fr', '/path/to/the/file.pdf');
85
+ // @var Knp\S nappy\P df
86
+ $knpSnappyPdf->generate('http://www.google.fr', '/path/to/the/file.pdf');
84
87
` ` `
85
88
86
89
# ## Generate a pdf document from multiple URLs
87
90
88
91
` ` ` php
89
- $container->get('knp_snappy.pdf')->generate(array('http://www.google.fr', 'http://www.knplabs.com', 'http://www.google.com'), '/path/to/the/file.pdf');
92
+ // @var Knp\S nappy\P df
93
+ $knpSnappyPdf->generate(array('http://www.google.fr', 'http://www.knplabs.com', 'http://www.google.com'), '/path/to/the/file.pdf');
90
94
` ` `
91
95
92
96
# ## Generate a pdf document from a twig view
93
97
94
98
` ` ` php
95
- $this->get('knp_snappy.pdf')->generateFromHtml(
99
+ // @var Knp\S nappy\P df
100
+ $knpSnappyPdf->generateFromHtml(
96
101
$this->renderView(
97
102
'MyBundle:Foo:bar.html.twig',
98
103
array(
@@ -107,17 +112,18 @@ $this->get('knp_snappy.pdf')->generateFromHtml(
107
112
108
113
` ` ` php
109
114
use Knp\B undle\S nappyBundle\S nappy\R esponse\J pegResponse;
115
+ use Symfony\B undle\F rameworkBundle\C ontroller\A bstractController;
110
116
111
- class SomeController
117
+ class SomeController extends AbstractController
112
118
{
113
- public function imageAction()
119
+ public function imageAction(Knp \S nappy \I mage $knpSnappyImage )
114
120
{
115
121
$html = $this->renderView('MyBundle:Foo:bar.html.twig', array(
116
122
'some' => $vars
117
123
));
118
124
119
125
return new JpegResponse(
120
- $this->get('knp_snappy.image') ->getOutputFromHtml($html),
126
+ $knpSnappyImage ->getOutputFromHtml($html),
121
127
'image.jpg'
122
128
);
123
129
}
@@ -128,17 +134,18 @@ class SomeController
128
134
129
135
` ` ` php
130
136
use Knp\B undle\S nappyBundle\S nappy\R esponse\P dfResponse;
137
+ use Symfony\B undle\F rameworkBundle\C ontroller\A bstractController;
131
138
132
- class SomeController extends Controller
139
+ class SomeController extends AbstractController
133
140
{
134
- public function pdfAction()
141
+ public function pdfAction(Knp \S nappy \P df $knpSnappyPdf )
135
142
{
136
143
$html = $this->renderView('MyBundle:Foo:bar.html.twig', array(
137
144
'some' => $vars
138
145
));
139
146
140
147
return new PdfResponse(
141
- $this->get('knp_snappy.pdf') ->getOutputFromHtml($html),
148
+ $knpSnappyPdf ->getOutputFromHtml($html),
142
149
'file.pdf'
143
150
);
144
151
}
@@ -149,15 +156,16 @@ class SomeController extends Controller
149
156
150
157
` ` ` php
151
158
use Knp\B undle\S nappyBundle\S nappy\R esponse\P dfResponse;
159
+ use Symfony\B undle\F rameworkBundle\C ontroller\A bstractController;
152
160
153
- class SomeController extends Controller
161
+ class SomeController extends AbstractController
154
162
{
155
- public function pdfAction()
163
+ public function pdfAction(Knp \S nappy \P df $knpSnappyPdf )
156
164
{
157
165
$pageUrl = $this->generateUrl('homepage', array(), true); // use absolute path!
158
166
159
167
return new PdfResponse(
160
- $this->get('knp_snappy.pdf') ->getOutput($pageUrl),
168
+ $knpSnappyPdf ->getOutput($pageUrl),
161
169
'file.pdf'
162
170
);
163
171
}
0 commit comments