我在Joomla 3中創建一個新的組件,它將使用dompdf在屏幕上生成特定信息的PDF。在joomla組件中使用dompdf有不正確的內容
我已經測試了joomla以外的我的dompdf代碼,並且一切正常,但是一旦我將代碼帶入組件中,它就會出錯。
Dompdf生成PDF,但它無效並且無法正常打開。
我已經在文本編輯器中打開PDF,問題是dompdf生成的pdf已經獲得了所有Joomla頭文件(樣式表,jaavascript等),即使我只是將一些專用HTML傳遞給它。
有什麼我失蹤?代碼如下所示
$fhtml = '<html><head><title>Sales Order</title>';
$fhtml .= PHP_EOL . '<link type="text/css" href="test.css" rel="stylesheet" /></head><body>';
$fhtml .= PHP_EOL . '<center><img src="elite.jpg" /><img src="premierdealer.jpg" /><img src="logo.jpg" /><img src="traveller.jpg" /><img src="childrens.jpg" /><img src="westfield.jpg" /></center>';
$fhtml .= PHP_EOL . '<h2>Header</h2><p>Para</p>';
$fhtml .= PHP_EOL . '</body></html>';
require_once 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$dompdf->setPaper('A4', 'portrait');
$dompdf->loadHtml($fhtml);
$dompdf->render();
$dompdf->stream('salesorder');
從上面的代碼可以看出,我將html傳遞給dompdf-> loadhtml。 PDF文件生成,但是當我在文本編輯器(它被損壞的PDF,所以我不能用pdf閱讀器打開它)我覺得開德PDF中的PDF中的以下內容:
<!DOCTYPE html>
<html lang="en-gb" dir="ltr">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="utf-8" />
<base href="http://test1.questleisure.local/index.php/portal/portal-home" />
<meta name="keywords" content="quest leisure air awnings caravan awnings camping caravan air tents outdoor funriture" />
<meta name="rights" content="Quest Leisure" />
<meta name="description" content="Quest Leisure Public Website" />
<meta name="generator" content="Joomla! - Open Source Content Management" />
<title>Portal Home</title>
<link rel="stylesheet" href="/media/com_questportal/css/default.css" />
<link rel="stylesheet" href="/plugins/system/rokbox/assets/styles/rokbox.css" />
<link rel="stylesheet" href="/media/gantry5/assets/css/font-awesome.min.css?57344a42" />
<link rel="stylesheet" href="/media/gantry5/engines/nucleus/css-compiled/nucleus.css?57344a42" />
<link rel="stylesheet" href="/templates/rt_galatea/custom/css-compiled/galatea_11.css" />
<link rel="stylesheet" href="/media/gantry5/assets/css/bootstrap-gantry.css?57344a42" />
<link rel="stylesheet" href="/media/gantry5/engines/nucleus/css-compiled/joomla.css?57344a42" />
<link rel="stylesheet" href="/media/jui/css/icomoon.css" />
<link rel="stylesheet" href="/templates/rt_galatea/custom/css-compiled/galatea-joomla_11.css" />
<link rel="stylesheet" href="/templates/rt_galatea/custom/css-compiled/custom_11.css" />
<link rel="stylesheet" href="/templates/rt_galatea/css/demo.css" />
<link rel="stylesheet" href="/templates/rt_galatea/css/animate.css" />
<script src="/media/system/js/mootools-core.js"></script>
<script src="/media/system/js/core.js"></script>
<script src="/media/system/js/mootools-more.js"></script>
<script src="/plugins/system/rokbox/assets/js/rokbox.js"></script>
<script src="/templates/rt_galatea/js/jui/jquery.min.js"></script>
<script src="/media/jui/js/jquery-noconflict.js"></script>
<script src="/media/jui/js/jquery-migrate.min.js"></script>
<script src="/media/jui/js/bootstrap.min.js"></script>
<body class="gantry g-galatea-style site com_questportal view-questportal no-layout task-display dir-ltr itemid-229 outline-11 g-offcanvas-left g-default g-style-preset1">
<div id="g-offsidebar-overlay"></div>
<div id="g-offcanvas" data-g-offcanvas-swipe="1" data-g-offcanvas-css3="1">
<div
class="g
所以DOMPDF是從緩衝區中獲取所有基本的Joomla頭文件,即使我只是通過它的某些HTML。 有什麼我必須做的,以阻止使用joomla的所有標題dompdf,並只使用HTML我傳遞它?
乾杯
我做了更多的測試,發現問題是dompdf-> stream命令。如果我使用dompdf-> output()命令將PDf輸出到物理文件,那麼物理文件是正確的,並且沒有所有額外的頭信息。只要我使用流,它會將所有額外的頭信息放入 –
可能重複的[dompdf->流不工作在joomla](http://stackoverflow.com/questions/37277813/dompdf-stream-not-working-in-joomla) – BrianS