HTML (js внутри) страница в pdf с использованием проблемы HTML2PDF

У меня возникают проблемы, когда я хочу изменить HTML-страницу в PDF с использованием HTML2PDF. на самом деле, я не знаю, что происходит с моим кодом. но ошибка выглядит так:

чтобы быть понятным, это код:

<?php
session_start();
ob_start();
include_once("config.php"); 
?>
<html xmlns="http://www.w3.org/1999/xhtml"> <!-- Bagian halaman HTML yang akan konvert -->
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo $judul; ?></title>
</head>
<body>
<?php 
echo "<h1>".$judul."</h1>"; 
?>
    <div id="chart_div"></div>
   
  
<script type="text/javascript">    
 google.charts.load('current', {packages:["orgchart"]});
      google.charts.setOnLoadCallback(drawChart);

      function drawChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Name');
        data.addColumn('string', 'Manager');https://jsfiddle.net/klometerz/zyq1rp81/#run
        data.addColumn('string', 'ToolTip');

        // For each orgchart box, provide the name, manager, and tooltip to show.
        data.addRows([
  
  <?php 
  include "inc/koneksi.php";
  $data = mysql_query("select * from t_chart");
  while($d = mysql_fetch_array($data))
  {
   echo "[{v:'".$d[id_chart]."', f:'".$d[f_chart];?></a><div style="color:red; size:11px; font-style:italic"><?php echo "<a href=edit_chart.php?id=".$d[id_chart].">".$d[batch_chart]."</a></div>'},'".$d[manager_chart]."', '".$d[tooltip_chart]."'],";
  }
  ?>
        
        ]);

        // Create the chart.
        var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
        // Draw the chart, setting the allowHtml option to true for the tooltips.
        chart.draw(data, {allowHtml:true});
      }
   </script>
   
   <?php
echo $isi;
echo "<p align='right'>".$penulis."</p>";
?>
</body>
</html>
<?php
$content = ob_get_clean();
 $content = '<page style="font-family: freeserif">'.nl2br($content).'</page>';
 require_once(dirname(__FILE__).'/html2pdf/html2pdf.class.php');
 try
 {
  $html2pdf = new HTML2PDF('L','A4','en', false, 'ISO-8859-15',array(30, 0, 20, 0));
  $html2pdf->setDefaultFont('Arial');
  $html2pdf->writeHTML($content, isset($_GET['vuehtml']));
  $html2pdf->Output('SO');
 }
 catch(HTML2PDF_exception $e) { echo $e; }
?>

пожалуйста, кто-нибудь может помочь мне решить эту проблему? Я буду очень признателен. благодарю вас.

1 ответ

Хорошо, сообщение об ошибке, которое вы разместили, предполагает, что библиотека HTML2PDF не поддерживает теги сценария в html. Вы можете удалить теги сценариев из HTML, используя регулярные выражения. Например:

$text = preg_replace("/<script[^>]*?>.*?<\/script>/si", "", $content);

Вышеуказанная строка может быть добавлена ​​сразу после строки:

$content = ob_get_clean();

Приведенный выше код был взят с: http://php.net/manual/en/function.preg-replace.php.

Другие вопросы по тегам