Z. Final Tutorial - MiguelFieira/AMO-HANDBOEK GitHub Wiki
composer create-project symfony/website-skeleton:4.4.* my-project
/**
* @Route("/pdf/{id}", name="user_pdf", methods={"GET"})
*/
public function pdf(User $user): Response
{
// Configure Dompdf according to your needs
$pdfOptions = new Options();
$pdfOptions->set('defaultFont', 'Arial');
// Instantiate Dompdf with our options
$dompdf = new Dompdf($pdfOptions);
// dd($dompdf);
// Load HTML to Dompdf
$html = $this->renderView('user/pdf.html.twig', [
'user' => $user
]);
// dd($user);
$dompdf->loadHtml($html);
// (Optional) Setup the paper size and orientation 'portrait' or 'portrait'
$dompdf->setPaper('A4', 'portrait');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser (inline view)
$dompdf->stream("mypdf.pdf", [
"Attachment" => false
]);
// return $this->render('user/show.html.twig', [
// 'user' => $user,
// ]);
}<!-- Create file in template -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the PDF</title>
</head>
<body>
<p>{{ user }}</p>
<p>{{ user.email }}</p>
</body>
</html>ZET DIT BOVEN DE INDEX!
/**
* @Route("/pdf", name="onderdelen_pdf", methods={"GET"})
*/
public function pdf(SchapenRepository $schapenRepository): Response
{
//Print all in a PDF YAYY :D
// Configure Dompdf according to your needs
$pdfOptions = new Options();
$pdfOptions->set('defaultFont', 'Arial');
// Instantiate Dompdf with our options
$dompdf = new Dompdf($pdfOptions);
// dd($dompdf);
// Load HTML to Dompdf
$html = $this->renderView('onderdelen/pdf.html.twig', [
'schapen' => $onderdelenRepository->findAll(),
]);
// dd($user);
$dompdf->loadHtml($html);
// (Optional) Setup the paper size and orientation 'portrait' or 'portrait'
$dompdf->setPaper('A4', 'portrait');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser (inline view)
$dompdf->stream("mypdf.pdf", [
"Attachment" => false
]);
// return $this->render('user/show.html.twig', [
// 'user' => $user,
// ]);
} {% for schaap in schapen %}
<tr>
<td>{{ schaap.id }}</td>
<td>{{ schaap.naam }}</td>
<td>{{ schaap.omschrijving }}</td>
<td>{{ schaap.prijsperkg }}</td>
<td>{{ schaap.voorraadkg }}</td>
</tr>
{% endfor %}