entityManager->getRepository(Shipment::class)->find($id); if (!$shipment instanceof Shipment) { throw new NotFoundHttpException('Shipment not found.'); } $options = new Options(); $options->set('isRemoteEnabled', true); $dompdf = new Dompdf($options); $html = $this->twig->render('shipment_voucher.html.twig', [ 'shipment' => $shipment, ]); $dompdf->loadHtml($html); $dompdf->setPaper('A4'); $dompdf->render(); $filename = sprintf('bon-expedition-%d.pdf', $shipment->getId()); return new Response($dompdf->output(), Response::HTTP_OK, [ 'Content-Type' => 'application/pdf', 'Content-Disposition' => 'inline; filename="'.$filename.'"', ]); } }