как открыть сгенерированный pdf в новой вкладке на symfony 4

в моем приложении Symfony 4 у меня есть кнопка, которая использовалась для создания pdf из html с помощью knp snappy bundle, но сгенерированный pdf отображается на той же странице, поэтому я ищу способ открыть сгенерированный pdf на новой вкладке, есть ли способ чтобы это осуществить?
Заранее спасибо.


person Mohamed Aarab    schedule 22.01.2020    source источник


Ответы (2)


можешь выложить код?

однако вы должны добавить target="_blank", где PDF-файл открывается следующим образом:

<a target="_blank" href="http://your_url.html">Link to the route that generates the pdf</a>
person Nobady    schedule 23.01.2020

вот мое действие с квитанцией, я создал новую квитанцию, а затем распечатал ее:

/**
 * @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);
    }

}
person Mohamed Aarab    schedule 23.01.2020