WordPress中的TCPDF输出疯狂的代码

时间:2018-08-29 01:27:21

标签: wordpress tcpdf

我想在我的wordpress项目中实现tcpdf。我尝试调用下面的示例tcpdf文件(这是来自tcpdf的示例),不幸的是,其输出如下所示是疯狂的代码, %PDF-1.7%����8 0 obj << / Type / Page / Parent 1 0 R / LastModified(D:20180829011846 + 00'00')/ Resources 2 0 R /MediaBox.....

我不知道这是什么问题,非常感谢,如果有任何指导,非常感谢。

<?php
// Include the main TCPDF library (search for installation path).
require_once(dirname(__FILE__).'/tcpdf/examples/tcpdf_include.php');
ob_end_clean(); 

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 038');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 038', PDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}

// ---------------------------------------------------------

// set font
$pdf->SetFont('helvetica', '', 20);

// add a page
$pdf->AddPage();

$txt = 'Example of CID-0 CJK unembedded font.
To display extended text you must have CJK fonts installed for your PDF reader:';
$pdf->Write(0, $txt, '', 0, 'L', true, 0, false, false, 0);

// set font
$pdf->SetFont('cid0jp', '', 40);

$txt = 'こんにちは世界';
$pdf->Write(0, $txt, '', 0, 'L', true, 0, false, false, 0);

// ---------------------------------------------------------

//Close and output PDF document
$pdf->Output('example_038.pdf', 'I');
?>

1 个答案:

答案 0 :(得分:0)

在pdf输出方法中,尝试使用'F'作为第二个参数,而不是'I'。

<html>
<head>
  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  <script type="text/javascript">

  var completed = [["blockwork",5],["lift",5],["cladding",5],["painting",5],["plumbing",2]];
  var completednow = [["blockwork",2],["lift",2],["cladding",4],["painting",1],["plumbing",0]];
  var balance = [["blockwork",3],["lift",3],["cladding",1],["painting",4],["plumbing",8]];

 function drawAxisTickColors() {
 var data = new google.visualization.DataTable(['completed','completednow','balance']);

 data.addColumn('string',"Activity");
 data.addColumn('number',"Completed");
 data.addColumn('number',"Completednow");
 data.addColumn('number',"Balance");

     for(var i=0;i<completed.length;i++)
     {
         data.addRows([
             [completed[i][0],completed[i][1],completednow[i][1],balance[i][1]]
         ]);
     }

 var options = {
  width: 1200,
  height: 800,
  legend: { position: 'right', maxLines: 1 },
  bar: { groupWidth: '20%' },
  theme: 'stroke-width',
  isStacked: true,
  is3D: true,
  vAxis: {
         minValue:0,
         viewWindow: {
             min: 0
         }
  }
};



 var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
 chart.draw(data, options);
 }

 google.charts.load('current', {packages: ['corechart', 'bar']});
 google.charts.setOnLoadCallback(drawAxisTickColors);

  </script>
</head>
<body>
<div id="chart_div"></div>
 </body>
 </html>