第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

生成 PDF 并返回響應(yīng)

生成 PDF 并返回響應(yīng)

PHP
動(dòng)漫人物 2022-09-24 16:07:28
今天,我遇到了一個(gè)問題,即在符號(hào)上使用KnpSnappyBundle生成PDF。我正在使用AJAX運(yùn)行路由,代碼工作正常,但它不會(huì)生成PDF,我想在這里完成的是在新的選項(xiàng)卡或窗口中生成PDF,并向客戶端返回成功的消息。這是我的代碼: /** * @Route("/api/release_bills/{month}/{year}/{region}", name="api_print_bills", methods={"GET","POST"}) * @param BillRepository $billRepository * @param ConsumptionRepository $consumptionRepository * @param Request $request * @param Snappy $snappy * @param $month * @param $year * @param $region * @return Response * @throws Exception */public function releaseBills(BillRepository $billRepository,ConsumptionRepository $consumptionRepository, Request $request, Snappy $snappy,  $month,$year,$region ): Response{    $error = array();    $success = array();    if( $month>0 && $month<13 || preg_match("/^\d{4}$/",$year)||$region!=''){        if($year>=2018 && $year <=2050){            $entityManager = $this->getDoctrine()->getManager();                $bills = $consumptionRepository->findAllWaterMetersForBilling($month,$year,$region);                $isBillsExisted = $billRepository->findAllBillsByDate($month,$year,$region);                if(empty($bills)){                    array_push($error,['error'=>'there is not bills to be release for this criteria : [ city: '.$region.', year :'.$year.', and Month : '.$month.'!]']);                    return new JsonResponse($error);                }                $arr = array();                $newBills = array();                $billsEnd=end($bills);                foreach ($bills as $key=>$b){                    $wmNumber =  $b->getWaterMeter()->getWmNumber();                    $fullName = $b->getWaterMeter()->getClient()->getFullName();                    $cin = $b->getWaterMeter()->getClient()->getCin();                    $address= $b->getWaterMeter()->getAddress();                    $wmAddress = $b->getWaterMeter()->getAddress()->getStreetAddress();                    $city = $b->getWaterMeter()->getAddress()->getCity();
查看完整描述

3 回答

?
慕沐林林

TA貢獻(xiàn)2016條經(jīng)驗(yàn) 獲得超9個(gè)贊

可能是以后的事了,但你可以像這樣嘗試:


    $file = $folder . $fileName ;


    if (is_file($file)) {

        unlink($file);

    }

然后,生成并保存具有相同名稱及之后的文件。不要使用,但return new PdfResponse...


$pdf->generateFromHtml($html, $folder . $file);

,然后返回響應(yīng)


    $response = new JsonResponse();

    $response->setStatusCode(Response::HTTP_NOT_FOUND); // 404

    if (is_file($file)) {

        $response->setStatusCode(Response::HTTP_OK); // 200

    }


查看完整回答
反對 回復(fù) 2022-09-24
?
九州編程

TA貢獻(xiàn)1785條經(jīng)驗(yàn) 獲得超4個(gè)贊

嘗試像這樣修改阿賈克斯:


$.ajax({

  url: `http://symfony.localhost/bill/api/release_bills/${monthValue.value}/${yearValue.value}/${regionValue.value}`,

  success: function(data) {

    var blob=new Blob([data]);

    var link=document.createElement('a');

    link.href=window.URL.createObjectURL(blob);

    link.download="<CHOOSE_FILENAME_WITH_EXTENSION>";

    link.click();

  }

});


查看完整回答
反對 回復(fù) 2022-09-24
?
炎炎設(shè)計(jì)

TA貢獻(xiàn)1808條經(jīng)驗(yàn) 獲得超4個(gè)贊

在朋友的幫助下,我設(shè)法生成pdf,但我仍然不知道如何在生成Pdf時(shí)返回錯(cuò)誤或成功消息。


這是我所做的:


generatePDF = () =>{

    const {yearValue, monthValue, regionValue}= this.state;


    var strWindowFeatures = "location=yes,height=570,width=520,scrollbars=yes,status=yes";

    var URL = `http://symfony.localhost/bill/api/release_bills/${monthValue.value}/${yearValue.value}/${regionValue.value}`;

    window.open(URL, "_blank", strWindowFeatures);

};

函數(shù)生成PDF在單擊按鈕上被調(diào)用


查看完整回答
反對 回復(fù) 2022-09-24
  • 3 回答
  • 0 關(guān)注
  • 120 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)