Ich bin mit Symfony 3.1.2 mit KnpSnappyBundle 1.4 und ich folgte alles, was der Doc sagt hier (als pdf zu erzeugen): https://github.com/KnpLabs/KnpSnappyBundleKnpSnappyBundle kein Javascript ausführen
Aber es funktioniert nicht. Das PDF wird erzeugt, aber das Javascript nicht ausgeführt ...
Hier ist mein Symfony-Controller:
/**
* @Route("/report")
*/
public function report(Request $request)
{
$idTown = 1;//$request->request->get("idTown");
$html = $this->renderView("@AppBundle/Resources/views/report.html.twig", array
(
"idTown" => $idTown
));
return new Response
(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html,
array(
'enable-javascript' => true,
'no-stop-slow-scripts' => true,
'javascript-delay' => 5000)
),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="file.pdf"'
)
);
}
Hier ist die die HTML-Datei (report.html.twig
):
<html>
<head>
<script
src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous"></script>
<script>
$("body").html("okkkkkkkkkkkkkkkkkkkkkkk");
</script>
<style>
html
{
background-color : red;
}
</style>
</head>
<body>
</body>
Wenn ich zur URL localhost/report
gehe, erhalte ich eine Download-Aufforderung für eine rote Seite ohne Text. Für das, was es wert ist, habe ich auch mit nativem JavaScript (anstelle von jQuery) versucht und es hat auch nicht funktioniert. Aber Sie sehen, das CSS wird ausgeführt ...
Hilfe bitte, danke.