'How to show a logo on every page of multi page pdf in template
I am using snappy bundle to generate a pdf from the twig file (Symfony 3.4). The number of pages increases as the content increases. Here, now I am wanted to add the company logo on top of every page. Can anyone suggest me a solution approach? Below are my code snippets. Till now, the code is working fine and multiple pdf pages are getting generated but image is only on the first page.
test.html.twig template:
<html>
<head>
<title>Test</title>
</head>
<body>
<img src="{{ asset('img/logo.svg') }}" />
<h1>{{title}}</h1>
<p>{{text|raw}}</p>
</body>
</html>
testpdfcontroller.php
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class testpdfcontroller extends Controller{
/**
* @Route("/test/{id}", name="show_test_pdf", methods={"get"})
*/
public function showpdf($id)
{
$repository = $this->getDoctrine()->getRepository('AppBundle:Ev\testpdf');
$testpdf = $repository->find($id);
$snappy = $this->get('knp_snappy.pdf');
$title = $testpdf->getTitle();
$text = $testpdf->getSourceTxt();
$text = $result = str_replace("\n", "<br />\n", $text);
$html = $this->renderView('test.html.twig', array(
'title' => $title,
'text' => $text
));
$filename = "test_pdf";
return new Response(
$snappy->getOutputFromHtml($html),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline; filename="'.$filename.'.pdf"'
)
);
}
}
?>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
