簡體   English   中英

使用HTML2PDF問題將HTML頁面內的js轉換為pdf

[英]HTML (js inside) page to pdf using HTML2PDF issue

當我想使用HTML2PDF將html頁面更改為pdf時遇到麻煩。 實際上,我不知道我的代碼是怎么回事。 但錯誤顯示如下: 在此處輸入圖片說明

要清楚,這是代碼:

 <?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; } ?> 

請有人可以在這里幫助我解決這個問題嗎? 我將不勝感激。 謝謝。

好吧,您發布的錯誤消息表明HTML2PDF庫不支持html中的腳本標簽。 您可以使用正則表達式從html中刪除腳本標簽。 例如:

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

可以在該行之后添加以上行:

$content = ob_get_clean();

上面的代碼來自: http : //php.net/manual/en/function.preg-replace.php#76297

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM