寻找一种方法将PHP动态html输出到一个看起来像PDF的证书文件中 - 我的证书看起来很好,但是当我使用mPDF将html结果返回到PDF时,我什么也得不到。我确定html存储在php var中的方式和脚本需要在html之外,但我不知道如何实现这一点?
<?php
$html = '
<HTML>
<HEAD>
<!-- saved from url=(0014)about:internet -->
<TITLE>Certificate</TITLE>
<SCRIPT>
var strTitle = "MIEMSS Course Title";
var g_arrMonths = new Array()
// Enter the month names below
try
{
g_arrMonths[0] = __MONTH_JAN__;
g_arrMonths[1] = __MONTH_FEB__;
g_arrMonths[2] = __MONTH_MAR__;
g_arrMonths[3] = __MONTH_APR__;
g_arrMonths[4] = __MONTH_MAY__;
g_arrMonths[5] = __MONTH_JUN__;
g_arrMonths[6] = __MONTH_JUL__;
g_arrMonths[7] = __MONTH_AUG__;
g_arrMonths[8] = __MONTH_SEP__;
g_arrMonths[9] = __MONTH_OCT__;
g_arrMonths[10] = __MONTH_NOV__;
g_arrMonths[11] = __MONTH_DEC__;
// Enter the column headers
var g_strDateTime = __DATE_TIME__;
var g_strStudentScore = __STUDENT_SCORE__;
var g_strPassingScore = __PASSING_SCORE__;
var g_strResult1 = __RESULT__;
var g_strQuestion = __QUESTION__;
var g_strCorrectAns = __CORRECT_ANS__;
var g_strResult2 = __RESULT__;
var g_strStudentAns = __STUDENT_ANS__;
var g_strPointsAwarded = __POINTS_AWARD__;
var g_strNeutral = __NEUTRAL__;
var g_strCorrect = __CORRECT__;
var g_strIncorrect = __INCORRECT__;
}
catch(e)
{
g_arrMonths[0] = "January";
g_arrMonths[1] = "February";
g_arrMonths[2] = "March";
g_arrMonths[3] = "April";
g_arrMonths[4] = "May";
g_arrMonths[5] = "June";
g_arrMonths[6] = "July";
g_arrMonths[7] = "August";
g_arrMonths[8] = "September";
g_arrMonths[9] = "October";
g_arrMonths[10] = "November";
g_arrMonths[11] = "December";
// Enter the column headers
var g_strDateTime = "Date / Time";
var g_strStudentScore = "Student Score";
var g_strPassingScore = "Passing Score";
var g_strResult1 = "Result";
var g_strQuestion = "Question";
var g_strCorrectAns = "Correct Answer";
var g_strResult2 = "Result";
var g_strStudentAns = "Student Answer";
var g_strPointsAwarded = "Points Awarded";
var g_strNeutral = "Neutral";
var g_strCorrect = "Correct";
var g_strIncorrect = "Incorrect";
}
</SCRIPT>
<STYLE>
TD {
font-size:10pt;
font-family:arial;
text-align: center;
width: 12.5%;
}
.CORRECT {
font-size:10pt;
font-family:arial;
color: #008800;
}
.INCORRECT {
font-size:10pt;
font-family:arial;
color: #880000;
}
.NEUTRAL {
font-size:10pt;
font-family:arial;
color: #000088;
}
.QUESTION {
font-size:10pt;
font-family:arial;
text-align: left;
width: 46.25%;
}
.NUMBER {
font-size:10pt;
font-family:arial;
text-align: center;
width: 3.75%;
}
.DATE {
font-size:10pt;
font-family:arial;
text-align: center;
}
.DATETIME {
font-size:10pt;
font-family:arial;
margin-top: 0;
margin-bottom: 0;
}
.SUMMARY {
font-size:10pt;
font-family:arial;
text-align: center;
}
H1 {
font-size:14pt;
font-family:arial;
text-align: center;
}
TH {
font-size:12pt;
font-family:arial;
}
.image {
position: relative;
width: 100%; /* for IE 6 */
}
H2 {
font-size:14pt;
font-family:arial;
text-align: center;
position: absolute;
top: 200px;
left: 0;
width: 100%;
}
</STYLE>
<SCRIPT>
var g_oContentResults = window.opener.g_oContentResults;
var g_listQuizzes = window.opener.g_listQuizzes;
var g_oPrintOptions = window.opener.g_oPrintOptions;
var player = GetPlayer()
//var myscore = player.GetVar("g_strStudentScore");
var scoreTotal = player.GetVar("userScore").toString();
function FormatDate(dtmDate)
{
var strResult = "";
var nHours = dtmDate.getHours();
var strAM = "am";
var nMinutes = dtmDate.getMinutes();
var strMinutes = "" + nMinutes;
if (nMinutes < 10)
{
strMinutes = "0" + nMinutes;
}
if (nHours == 12)
{
strAM = "pm";
}
if (nHours > 12)
{
nHours -= 12;
strAM = "pm";
}
strResult += "<P>"
strResult += g_arrMonths[dtmDate.getMonth()] + " ";
strResult += dtmDate.getDate() + ", ";
strResult += dtmDate.getFullYear() + " ";
strResult += nHours + ":";
strResult += strMinutes + " ";
strResult += strAM;
strResult += "</P>"
return strResult;
}
</SCRIPT>
</HEAD>
<BODY>
<center>
<img src="quizimages/cert.png">
</center>
<p>
<SCRIPT>
//document.write("<P><H1>" + strTitle + "</H1></P>");
if (g_oPrintOptions.strName)
{
if (g_oPrintOptions.strName.length > 0)
{
document.write("<H2><CENTER><I>This certifies:</I></br></br>");
document.write("" + g_oPrintOptions.strName + "</br></br>");
document.write("<I>has completed the course:</I></br></br>");
document.write("" + strTitle + "</br></br>");
document.write("</br></br>");
document.write( FormatDate(g_oContentResults.dtmFinished));
document.write("Score: " + g_listQuizzes[g_oPrintOptions.strMainQuizId].nPtScore + "</br></br></H2>" );
document.write('<center> <input type=button onClick="window.print()" value="Print This Page"/> </center>');
}
}
document.write("USER SCORE: "+scoreTotal+"");
document.write("<H2><CENTER><I>This certifies:</I></br></br>");
document.write("" + g_oContentResults.strName + "</br></br>");
document.write("<I>has completed the course:</I></br></br>");
document.write("" + strTitle + "</br></br>");
document.write("</br></br>");
document.write( FormatDate(g_oContentResults.dtmFinished));
document.write("Score: " + g_listQuizzes[g_oContentResults.strMainQuizId].nPtScore + "</br></br></H2>" );
document.write('<center> <input type=button onClick="window.print()" value="Print This Page"/> </center>');
</SCRIPT>
</BODY>
</HTML>
';
//==============================================================
//==============================================================
//==============================================================
include("../mpdf/mpdf.php");
$mpdf=new mPDF('c');
$mpdf->WriteHTML($html);
$mpdf->Output();
exit;
//==============================================================
//==============================================================
//==============================================================
?>
答案 0 :(得分:1)
绘制php页面后html加载中的javascript变量。 javascript var需要通过POST,GET或查询字符串传递给php var,并在刷新或新页面中获取 - 因此$ html只需要那个html而不包含脚本。