直到现在 - 我们在WP上有在线考试网络应用程序。我将问题纸保存为PDF而不用HTML格式打开它。
如果我在网页上显示问题文件,由于 mathjax.js ,它会适当地转换所有数学公式。当数据(试卷)在网页上时,mathjax.js工作。但如果我尝试将相同的问题纸保存为PDF而不在任何网页上打开它,它就不起作用。因为mathjax.js需要在网页上显示数据。
我的实验 - 1.当我从DB接收数据(问题文件)时,我试图加载mathjax.js。我以为这会将公式转换回原始状态。但是,它不是。因为,mathjax需要数据在网页上。
我想要的东西 - 我希望数学公式显示为PDF格式。公式仅使用mathjax转换。所以,我将只使用mathjax将其重新转换为原始状态。
如何实现这一目标??
<?php
//db connection
$dbConn = mysql_connect ("localhost", "username", "password") or die ('MySQL connect failed. ' . mysql_error());
//db selection
mysql_select_db("db_name") or die('Cannot select database. ' . mysql_error());
$id = $_REQUEST['id'];
if($_REQUEST['action'] == "print") {
mysql_query('SET character_set_results = utf8');
$result = mysql_query("SELECT question_id FROM wpc6_emp_exam_questions WHERE exam_id = '$id' ");
$exam_details = mysql_fetch_assoc(mysql_query("SELECT name, duration, passing_percent, negative_marking FROM wpc6_emp_exams WHERE id = '$id' "));
$num = mysql_num_rows($result);
while($row = mysql_fetch_assoc($result))
{
$results[] = $row['question_id'];
$question_id = $row['question_id'];
$result1 = mysql_query("SELECT question, option1, option2, option3, option4 FROM wpc6_emp_questions WHERE id = '$question_id' ");
while($row1 = mysql_fetch_assoc($result1))
{
$results1[] = $row1;
}
}
}
?>
<!-- Mathjax Script Start -->
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=AM_HTMLorMML-full"></script>
<script type="text/x-mathjax-config">MathJax.Hub.Config({extensions: ["tex2jax.js"],jax: ["input/TeX", "output/HTML-CSS"],tex2jax: {inlineMath: [["$", "$"],["\\(", "\\)"]]}});</script>
<!-- Mathjax Script End -->
<?php
$html .= '
<style>
p, div { font-family: freeserif}
</style>
<div style="text-align: center;"><img src="logo_3.png"></div>
<br/><hr><br/>
<div style="float: left; width: 70%;">Exam - '.$exam_details['name'].'</div>
<div style="float: right; width: 30%;">Duration - '.$exam_details['duration'].' Mins</div>
<div style="float: left; width: 70%;">Passing Percent - '.$exam_details['passing_percent'].'</div>
<div style="float: right; width: 30%;">Negative Marking - '.$exam_details['negative_marking'].'</div><hr>';
for($i=1; $i<=count($results1); $i++) {
$question = $i.'. '.$results1[$i-1]['question'];
$question = str_replace(array("\\","[","]"),"",$question);
$question = str_replace("(","<br> (",$question);
$option1 = $results1[$i-1]['option1'];
$option1 = str_replace(array("\\","[","]"),"",$option1);
$option2 = $results1[$i-1]['option2'];
$option2 = str_replace(array("\\","[","]"),"",$option2);
$option3 = $results1[$i-1]['option3'];
$option3 = str_replace(array("\\","[","]"),"",$option3);
$option4 = $results1[$i-1]['option4'];
$option4 = str_replace(array("\\","[","]"),"",$option4);
$html .= '<p style="font-size: 12pt; font-family: freeserif "><div style="float: left; width: 100%; margin-bottom:5px; font-family: freeserif">'.$question.'</div>';
if(strlen($option1)>40 || strlen($option2)>40 || strlen($option3)>40 || strlen($option4)>40 ) {
$html .= '<div>(a) '.$option1.'<br/>'
.'(b) '.$option2.'<br/>'
.'(c) '.$option3.'<br/>'
.'(d) '.$option4.'<br/>
</p>';
} else if(strlen($option1)>15 || strlen($option2)>15 || strlen($option3)>15 || strlen($option4)>15 ) {
$html .= '<div style="float: left; width: 50%;">(a) '.$option1.'</div>'
.'<div style="float: left; width: 50%;">(b) '.$option2.'</div>'
.'<div style="float: left; width: 50%;">(c) '.$option3.'</div>'
.'<div style="float: left; width: 50%;">(d) '.$option4.'</div>
</p>';
} else if(strlen($option1)<=15 || strlen($option2)<=15 || strlen($option3)<=15 || strlen($option4)<=15 ) {
$html .= '<div style="float: left; width: 25%;">(a) '.$option1.'</div>'
.'<div style="float: left; width: 25%;">(b) '.$option2.'</div>'
.'<div style="float: left; width: 25%;">(c) '.$option3.'</div>'
.'<div style="float: left; width: 25%;">(d) '.$option4.'</div>
</p>';
}
}
$html .= '<br/><br/><br/><div style="text-align: center"> --------- O Best of Luck O --------- </div>';
include("../mpdf.php");
$mpdf=new mPDF('');
$html = mb_convert_encoding($html, 'UTF-8', 'UTF-8');
$mpdf->SetWatermarkImage('logo_1.png');
$mpdf->showWatermarkImage = true;
$mpdf->WriteHTML($html);
?>
如果需要,您可以忽略代码中的 Mathjax Script Start 部分。
任何解决方案都可以理解
由于