我有这个简单的HTML文件(simple.html
)来测试DomPDF:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Bootstrap 101 Template</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<h1>Hello, world!</h1>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</body>
</html>
这是我的DomPDF生成器文件:
<?php
require_once '../../../lib/dompdf/autoload.inc.php';
use Dompdf\Dompdf;
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$invoice = file_get_contents('invoice.html');
$dompdf->loadHtml($invoice);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'portrait');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream();
?>
这里是错误信息......
Warning: fopen(/home/***/lib/dompdf/lib/fonts/345658495770f44fa67e0e37c1b01eb4.ufm): failed to open stream: Permission denied in /home/***/lib/dompdf/lib/php-font-lib/src/FontLib/AdobeFontMetrics.php on line 45
Warning: fwrite() expects parameter 1 to be resource, boolean given in /home/***/lib/dompdf/lib/php-font-lib/src/FontLib/AdobeFontMetrics.php on line 191
为什么PHP无法打开/ lib / dompdf / lib / fonts文件夹?它已获得drwxrwxr-x
权限。
为什么我在那里看不到任何345658495770f44fa67e0e37c1b01eb4.ufm
文件?
谢谢
答案 0 :(得分:1)
我尝试将所有必需的html保存在变量 $ html 中,然后使用
$dompdf->loadHtml(html_entity_decode($html));
从外部文件中获取html时也应该有效。尝试替换你的行
$dompdf->loadHtml($invoice);
与
$dompdf->loadHtml(html_entity_decode($invoice));