Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Generate and save a PDF
- *
- * @Route("/contracts/{id}/pdf", name="contract_pdf")
- */
- public function pdfAction($id, Request $request) {
- // get contract from database
- $em = $this->getDoctrine()->getManager();
- $c = $em->getRepository('AppBundle:Contract')->find($id);
- $path = $request->server->get('DOCUMENT_ROOT'); // C:/wamp64/www/
- $path = rtrim($path, "/"); // C:/wamp64/www
- $html = $this->renderView('contracts/pdf/content.html.twig', array('c' => $c));
- $header = $this->renderView('contracts/pdf/header.html.twig', array(
- 'path' => $path
- ));
- $footer = $this->renderView('contracts/pdf/footer.html.twig', array(
- 'customer' => $c->getCustomer()
- ));
- $output = $path . $request->server->get('BASE'); // C:/wamp64/www/project/web
- $output .= '/pdf/contract-'. $c->getCustomerCode() .'.pdf';
- // Generate PDF file
- $this->get('knp_snappy.pdf')->generateFromHtml($html, $output, array(
- 'header-html' => $header,
- 'footer-html' => $footer,
- ));
- // Message + redirection
- $this->addFlash('success', 'The PDF file has been saved.');
- return $this->redirectToRoute('contract');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement