在Moodle
我正在使用javascript
在course
中使用information
PDF
打印页面(在单独的文件中使用TCPDF
library
)
javascript:
$( document ).ready(function() {
$('#page-enrol-index .printpdf').click(function(){
//jquery extend function
$.extend(
{
redirectPost: function(location, args)
{
var form = '';
$.each( args, function( key, value ) {
form += '<input type="hidden" name="'+key+'" value="'+value+'">';
});
$('<form action="'+location+'" method="POST">'+form+'</form>').appendTo('body').submit();
}
});
//fill the variables
var title = $("div.sessioninfo_title span.sessioninfodata").text();
var description = $("div.content div.summary").text();
console.log(title);
//create the pdf
$.redirectPost("/moodle/local/printpdf.php", {
ptitle: title,
pdesc: description,
});
});
});
PDF
(两个variables
$title
和$description
,不会打印):
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
$pdf->SetFont('helvetica', '', 9);
$pdf->AddPage();
if (!empty($_POST["ptitle"])) {
$title = $_POST["ptitle"];
$description = $_POST["pdesc"];
}
$html = '<html>
<body>
<img src="/moodle/theme/base/pix/logo.png" alt="test alt attribute" border="0" height="100" width="220" allign="left" /><br />
<p><span style="font-size: small;"><font color="#C0C0C0">Organisation name<br><b>Department<br></font></span></p>
<h2>Information about the course</h2>
<!--
<h3>'. $title . '</h3><br />
'. $description . '<br />
-->
</body>
</html>';
// $pdf->writeHTML($html, true, false, true, false, '');
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->lastPage();
$pdf->Output('CourseInfo.pdf', 'D');