1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| <?php
namespace App\Controller;
use App\Entity\Candidat;
use App\Entity\Tuteur;
use App\Form\CandidatType;
use App\Form\TuteurType;
use App\Repository\CandidatRepository;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
use Knp\Bundle\SnappyBundle\Snappy;
use Knp\Snappy\Pdf;
use Knp\Bundle\SnappyBundle\DependencyInjection;
class VanController extends AbstractController
{
/**
* @Route("/listCandidats", name="van_list", methods={"GET"})
*
*/
public function listCandidats(Request $request)
{
$repo = $this->getDoctrine()->getRepository(Candidat::class);
$candidat = $repo->findAll();
$snappy = $this->get("knp_snappy.pdf");
//$snappy->setOption("encoding", "UTF-8");
$html = $this->renderView('van/list.html.twig', [
'candidats'=> $candidat,
'title' => "Welcome to our PDF Test"
]);
$filename = "myfirst_pdf_with_snappy";
return new Response(
$snappy->getOutputFromHtml($html),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline; filename="'.$filename.'.pdf"'
)
);
}
} |
Partager