ibeautiful
这是我的收据操作,我创建了新收据,然后打印它:/** * @Route("/receipt/{id}", name="receipt_index", methods={"GET","POST"}) * @param Bill $bill * @return Response * @throws Exception */public function newReceipt(Bill $bill): Response{ $receipt = new Receipt(); $date = new \DateTime('now'); $receipt->setBill($bill); $receipt->setBillCost($bill->getCost()); $receipt->setBillDate($bill->getPrintDate()); $receipt->setBillNumber($bill->getId()); $receipt->setClientName($bill->getClient()->getFullName()); $receipt->setReceiptDate($date); $receipt->getBill()->setStatus(true); $binary = $this->container->getParameter('knp_snappy.pdf.binary'); $snappy = new Snappy($binary); try { $newDate= $date->format('Y-m-d'); $entityManager = $this->getDoctrine()->getManager(); $entityManager->persist($receipt); $entityManager->flush(); $html= $this->renderView('bill/receipt.html.twig', array( 'receipt'=>$receipt, )); $pdf=$snappy->getOutputFromHtml($html,array( 'orientation' => 'portrait', 'enable-javascript' => true, 'javascript-delay' => 1000, 'no-stop-slow-scripts' => true, 'no-background' => false, 'encoding' => 'utf-8', 'lowquality' => false, 'page-width' => '8cm', 'page-height' => '12.40cm', 'margin-left'=>0, 'margin-right'=>0, 'margin-top'=>0, 'margin-bottom'=>0, 'images' => true, 'cookie' => array(), 'dpi' => 300, 'enable-external-links' => true, 'enable-internal-links' => true, ) ); return new Response($pdf,200,array( 'Content-Type' => 'application/pdf', 'Content-Disposition' => 'inline; filename="recu-'.$newDate.'.pdf"' )); } catch (Exception $e){ dump($e); }}