I'm trying to create an action which will return a pdf (HTML to PDF).
I have a button in my twig file which calls in AJAX a routing pattern which will call the next controller action:
public function pageToPDFAction(){
$html = file_get_contents("http://www.google.com");
$headers = array(
'Content-type' => 'application/pdf'
);
$response = new Response($html,200,$headers);
return $response;
}
The output I'm getting is in fact the google.com website, but what I want to get is the browser opening a pdf file like it happens when you click on a pdf file.
How can I achieve that? what am I missing?