【问题标题】:Symfony & Phantom JS Bundle - Routing ErrorSymfony 和 Phantom JS 捆绑包 - 路由错误
【发布时间】:2015-12-07 09:19:10
【问题描述】:

我正在使用 this Bundle 将 HTML 转换为 PDF 文件。

实际转换有效,但我对路由的理解有问题。

这是我的代码:

/**
 * @Route("/formulare/selbstauskunft/{keycode}", name="saPrint")
 */
public function saPrintAction(Request $request, $keycode)
{


    $em = $this->getDoctrine()->getManager();
    $sa = $em->getRepository('AppBundle:Selfinfo')->findOneBy(array(
        'keycode' => $keycode,
    ));

    if(count($sa) > 0){

        $response = new Response(
            $this->get('padam87_rasterize.rasterizer')->rasterize(
                $this->renderView('default/formSAPrint.html.twig', array(
                    'selfinfo' => $sa,
                ))
            ),
            200, [
                'Content-Type'          => 'application/pdf',
                'Content-Disposition'   => 'attachment; filename="my.pdf"'
            ]
        );

        return $response;

    }else{
        return new Response("fail");
    }
}

该包创建了 2 个文件,rasterize-UNIQUEID.htmlrasterize-UNIQUEID.pdf。 html 文件包含正确的输出。 在/bundles/padam87rasterize/temp/ 中创建html 文件后,脚本的第二部分通过url 调用here 打开该文件。 不幸的是,实际呈现的页面是一个 symfony 错误页面,上面写着:

找不到GET /bundles/padam87rasterize/temp/rasterize-UNIQUEID.html的路线

为了呈现 html 文件,我必须设置什么?

【问题讨论】:

    标签: php html symfony phantomjs rasterize


    【解决方案1】:

    我认为您实际上必须创建一个单独的路由来呈现 html。据我所知,rasterize 函数会从临时 html 文件中生成一个 pdf(关键字是临时的)。

    【讨论】:

      猜你喜欢
      • 2017-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-31
      • 2016-02-09
      • 2018-02-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多