【问题标题】:Generate pdf in HHVM not work在 HHVM 中生成 pdf 不起作用
【发布时间】:2017-05-15 06:48:20
【问题描述】:

我在我的 ubuntu 服务器上使用了 nginx 和 hhvm,并在 laravel 中使用了 mikehaertl/phpwkhtmltopdf 包来生成 pdf,但是在 HHVM 中生成的 pdf 显示下面的内容,并且在我的本地机器上运行良好:

我的代码是:

  $logo = storage_path('logo/logo.jpg');
  $font = storage_path('fonts/IRRoya.ttf');
  $barcode = DNS2D::getBarcodePNG($order["registration_number"], "QRCODE",5,5);
  $date = jDateTime::strftime('Y-m-d H:i:s', strtotime($order['order_date']));
  $f_date = jDateTime::convertNumbers($date);
  $view =   view('bill.bill',compact('order','logo','font','barcode','f_date'));
  $pdf = new Pdf(array(
      'no-outline',
      'margin-top'    => 0,
      'margin-right'  => 0,
      'margin-bottom' => 0,
      'margin-left'   => 0,
      'disable-smart-shrinking',
      'commandOptions' => array(
          'useExec' => true,
          'procEnv' => array(
              'LANG' => 'fa_IR.utf-8',
          ),
      ),
    ));
    $pdf->addPage($view);
    $pdf->send();

我该如何解决?

【问题讨论】:

  • 您是否正确发送了Content-Type 标头?
  • phpwkhtmltopdf 没有?
  • 取决于你如何使用它
  • 更新了我输入代码的问题

标签: laravel pdf laravel-5.2 hhvm phpwkhtmltopdf


【解决方案1】:

我找到了解决方案:

  $logo = storage_path('logo/logo.jpg');
  $font = storage_path('fonts/IRRoya.ttf');
  $barcode = DNS2D::getBarcodePNG($order["registration_number"], "QRCODE",5,5);
  $date = jDateTime::strftime('Y-m-d H:i:s', strtotime($order['order_date']));
  $f_date = jDateTime::convertNumbers($date);
  $view =   view('bill.bill',compact('order','logo','font','barcode','f_date'));
  $pdf = new Pdf(array(
      'no-outline',
      'encoding' => 'UTF-8',
      'margin-top'    => 0,
      'margin-right'  => 0,
      'margin-bottom' => 0,
      'margin-left'   => 0,
      'disable-smart-shrinking',
      'commandOptions' => array(
          'useExec' => true,
          'procEnv' => array(
              'LANG' => 'fa_IR.utf-8',
          ),
      ),
    ));
    $pdf->addPage($view);
    $content = $pdf->toString();
    return response($content)->withHeaders([
            'Content-Type' => 'application/pdf',
            'Pragma' => 'public',
            'Content-disposition' => 'attachment; filename='.$order["registration_number"].'.pdf',
            'Content-Transfer-Encoding' => 'binary',
            'Content-Length' => strlen($content)
        ]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-30
    • 2019-10-31
    • 1970-01-01
    • 1970-01-01
    • 2018-01-01
    • 2021-12-04
    • 2015-12-10
    相关资源
    最近更新 更多