1. Go to this page and download the library: Download prolix/knp-snappy-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
prolix / knp-snappy-bundle example snippets
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
//...
new Knp\Bundle\SnappyBundle\KnpSnappyBundle(),
//...
use Knp\Bundle\SnappyBundle\Snappy\Response\JpegResponse;
class SomeController
{
public function imageAction()
{
$html = $this->renderView('MyBundle:Foo:bar.html.twig', array(
'some' => $vars
));
return new JpegResponse(
$this->get('knp_snappy.image')->getOutputFromHtml($html),
'image.jpg'
);
}
}
use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
class SomeController extends Controller
{
public function pdfAction()
{
$html = $this->renderView('MyBundle:Foo:bar.html.twig', array(
'some' => $vars
));
return new PdfResponse(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
'file.pdf'
);
}
}
use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
class SomeController extends Controller
{
public function pdfAction()
{
$pageUrl = $this->generateUrl('homepage', array(), true); // use absolute path!
return new PdfResponse(
$this->get('knp_snappy.pdf')->getOutput($pageUrl),
'file.pdf'
);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.