Skip to content

Instantly share code, notes, and snippets.

@ger86
Last active November 7, 2018 07:42
Show Gist options
  • Save ger86/2133bc76a0579a0d7ff449c022d40516 to your computer and use it in GitHub Desktop.
Save ger86/2133bc76a0579a0d7ff449c022d40516 to your computer and use it in GitHub Desktop.
class DownloadSpecificationsController extends Controller {
/**
* @Route("/generate-pdf", name="app_generate_pdf")
*/
public function downloadSpecifications() {
$html = $this->renderView('download-specifications/pdf.html.twig');
$filename = sprintf('specifications-%s.pdf', date('Y-m-d-hh-ss'));
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
200,
[
'Content-Type' => 'application/pdf',
'Content-Disposition' => sprintf('attachment; filename="%s"', $filename),
]
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment