我下载了mPDF的v6.0并找到了一个让我入门的例子。如果我用这个:
df[bool_series]
它有效(至少,我得到了PDF,但它不是横向格式)。但是,如果我使用它:
$mpdf=new mPDF('c','LETTER','','' , 0 , 0 , 0 , 0 , 0 , 0,'landscape');
为了最终使用我希望包含在PDF中的ttf字体,我收到此错误:
'无法打开文件 /test_project/php/mpdf/ttfontdata/dejavusanscondensedB.GSUBGPOStables.dat'
我没有在ttfonts文件夹中添加任何自定义字体,并且引用的.css文件未指定任何字体。我看到ttfontsdata文件夹是空的但是可写。
以下是我发现我正在测试的例子:
pdfTest.html
$mpdf=new mPDF('','LETTER','','' , 0 , 0 , 0 , 0 , 0 , 0,'landscape');
dwnldToPDF.php
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(function(){
$('#fileContents').val(document.documentElement.innerHTML);
});
</script>
</head>
<body>
<table>
<tr>
<th></th>
<th>9am</th>
<th>10am</th>
<th>11am</th>
<th>12am</th>
</tr>
<tr>
<th>Monday</th>
<td colspan="2">Geography</td>
<td>Math</td>
<td>Art</td>
</tr>
<tr>
<th>Tuesday</th>
<td colspan="3">Gym</td>
<td>Home Ec</td>
</tr>
</table>
<form action="php/dwnldToPDF.php" method="post">
<div style="display:none;" >
<input type="text" name="fileContents" id="fileContents" value=''/>
<input type="text" name="fileName" id="fileName" value='mySitePage.pdf'/>
<input type="text" name="css" value='style.css'/>
</div>
<input type="submit" id="createPdf" value="Download PDF"/>
</form>
</body>
</html>
的style.css
<?php
$fileContents = stripslashes($_POST['fileContents']);
$css = $_POST['css'];
$fileName = $_POST['fileName'];
//==============================================================
//==============================================================
//==============================================================
include("mpdf60/mpdf.php");
//setup
$mpdf=new mPDF('','LETTER','','' , 0 , 0 , 0 , 0 , 0 , 0,'landscape');
$mpdf->SetDisplayMode('fullpage');
// LOAD a stylesheet
$stylesheet = file_get_contents($css);
$mpdf->WriteHTML($stylesheet,1);
// The parameter 1 tells that this is css/style only and no body/html/text
$mpdf->WriteHTML($fileContents);
$mpdf->Output($fileName,'D');
//I: send the file inline to the browser. The plug-in is used if available. The name given by filename is used when one selects the "Save as" option on the link generating the PDF.
//D: send to the browser and force a file download with the name given by filename.
//F: save to a local file with the name given by filename (may include a path).
//S: return the document as a string. filename is ignored.
exit;
//==============================================================
//==============================================================
//==============================================================
?>
请注意,我无法使用mPDF v7,因为这需要使用Composer进行部署,而且我还没有使用它(我已经安装了Composer和mpdf软件包,但我无法获得它在php文件中工作)。