duandao2306 2015-12-03 18:44
浏览 136
已采纳

使用JavaScript时生成PDF

I'm not 100% sure of my error here. I am getting this encoding output when I am trying to generate a PDF:

%PDF-1.4 %���� 3 0 obj <> /Contents 4 0 R>> endobj 4 0 obj <> stream x�S(T0�300@!�ҹ�iab�gai�ji�g`

I am using Yii2 and the highcharts package https://github.com/2amigos/yii2-highcharts-widget along with the mPDF package https://github.com/kartik-v/yii2-mpdf.

My hope was to be able to generate a browser version of this graph and also a PDF version. The browser version works fine, but the PDF attempt doesn't. My code in the action is:

  if($pdf == true){ // render as pdf

  $content = $this->renderPartial('_overallPDF', [
    'model' => $data,
  ]);

  $doc = new Pdf([
    // set to use core fonts only
    'mode' => Pdf::MODE_UTF8,
    // A4 paper format
    'format' => Pdf::FORMAT_A4,
    // portrait orientation
    'orientation' => Pdf::ORIENT_LANDSCAPE,
    // stream to browser inline
    'destination' => Pdf::DEST_BROWSER,
    // your html content input
    'content' => $content,
  ]);

  return $doc->render();

}

I am not sure of the problem here, could it be due to highcharts being a js library and the presentation done in browser?

Either way if anyone could help me find a solution to generate the graph as a PDF that would be great!

  • 写回答

1条回答 默认 最新

  • duanben4771 2015-12-04 15:52
    关注

    Well, this has been already answered : what you are trying to do is simply not possible since MPDF supports basic javascript... And this has nothing to do with yii2.

    If you really want to output highcharts graph in your pdf document, you should use a server side tool, e.g. : http://www.highcharts.com/docs/export-module/render-charts-serverside

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab