简体   繁体   中英

Generating PDFs when JavaScript is being used

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!

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, eg : http://www.highcharts.com/docs/export-module/render-charts-serverside

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM