2015-10-16 70 views
2

我將我的證書主題作爲html存儲在數據庫中。我的模板字體正在除草。主題在瀏覽器中看起來不錯。但是當我試圖從數據庫中取出並以pdf格式顯示時,正常的字體輸出即將到來。我沒有得到我錯在哪裏。在DATABSE存儲模板在輸出中無法獲得預期的字體

代碼:

<?php 
ob_start(); 
?> 
<head> 
    <link rel="stylesheet" href="stylesheet.css" type="text/css" charset="utf-8" /> 
    <style type="text/css"> 
     h1{ 
      font-family: 'weddingtext_btregular'; 
      font-weight:200; 
      font-size:25px; 
     } 
     h2{ 
      font-family: 'weddingtext_btregular'; 
      font-weight:300; 
      font-size:30px; 
     } 
     .span { 
      font-family: cursive; 
     } 
     .span1 { 
      padding-left:20%; 
     } 
     .span2 { 
      padding-left:50%; 
     } 
    </style> 
</head> 
<?php 
// normal output 
echo '<img alt="Nimhans Logo" src="img/1.png" width="100%" ; /> 
     <h1>SL NO. <span class="span">##SLNO##</span></h1> 
      <div class="body"> 
      <center><h1>Institute of National Importance</h1></center> 
      <center><h1>Bengaluru - 560 029</h1></center> 
       <br> 
      <center><h1>Certifies that</h1></center> 
      <br> 
      <center><h2>##NAME##</h2></center> 
      <br> 
     <center><h1>has been dulg admitted to the Degreeof</h1>     </center> 

      <br> 
      <center><h2>##COURSE##</h2></center> 
     <br> 
      <center><h1>in recognition of the fulfilment of requirements</h1></center> 
      <center><h1>under the statutes of the institute</h1></center> 
      <center><h1>##YEAR##</h1></center> 
     <br> 
      <center><h2>##CLASS##</h2></center> 
      <br> 
       <h1>##QRCODE## <span class="span1"> Biben under the seal of the Institute</span></h1> 
      <br> 
       <br> 
      <h1>Date:29th November, 2015 <span class="span2"> Director/Dice Chancellor</span></h1> 
      '; 

// store buffer to variable and turn output buffering offer 
$html = ob_get_clean(); 

echo $html; 

include 'configaration/config.php'; 

$html = mysql_real_escape_string($html); 

$dpt_name = "Nursing"; 
$qry = "INSERT INTO certificate (cert_data,department) 
      VALUES ('$html','$dpt_name')"; 

if (!mysql_query($qry)) { 

    die('Error: ' . mysql_error()); 
} 
?> 

取出由DATABSE模板和PDF顯示。

這裏是我的代碼:

$qry1 = "SELECT * FROM certificate WHERE department = '" . $dpt_name . "'"; 
$result1 = mysql_query($qry1); 

if ($result1) { 
    while ($row = mysql_fetch_array($result1)) { 

     $template_data = $row["cert_data"]; 
    } 
} 
$template_data = str_replace('##NAME##', $std_name, $template_data); 
$template_data = str_replace('##FROM##', $join_date, $template_data); 
$template_data = str_replace('##NAME##', $std_name, $template_data); 
$template_data = str_replace('##TO##', $to, $template_data); 

ob_end_clean(); 

include 'MPDF57/mpdf.php'; 

$mpdf = error_reporting(E_STRICT); 
$mpdf = new mPDF('win-1252', 'A4', '', '', 15, 10, 16, 10, 10, 10); 
$mpdf->Bookmark('Start of the document'); 
$mpdf->SetDisplayMode('fullpage'); 
$mpdf->WriteHTML($template_data); 
$mpdf->Output(); 

exit(); 

瀏覽器輸出:

BROWSER OUTPUT

PDF輸出圖像: PDF out put

請幫我在哪裏,我錯了。對不起,我的英語不好 。

+0

我猜字體在服務器上不可用時,它會嘗試構建PDF以便替換字體。我會建議嘗試在服務器上安裝字體。 – Yoink

+0

@Nayana 你有字體的otf文件嗎?您是否在使用之前導入它?我沒有看到你導入它的任何地方。 – Akshay

+0

是的。我已經包含style.css。我的style.css包含 @ font-face {font-family {font-family:'weddingtext_btregular'; src:url('ufonts.com_wedding-text-bt_1.eot'); url('ufonts.com_wedding-text-bt_1.eot?#iefix')format('embedded-opentype'), url('ufonts.com_wedding-text-bt_1.woff2')格式('woff2') ('ufonts.com_wedding-text-bt_1.woff')格式('woff'), url('ufonts.com_wedding-text-bt_1.ttf')格式('truetype'), url('ufonts' .com_wedding-text-bt_1.svg#weddingtext_btregular')format('svg'); font-weight:normal; font-style:normal; } – Nayana

回答

0

您正在使用css中的字體。但你應該在mpdf中使用。

config_fonts.php // you should add in this page and 

那麼它會反映出來。並在您的ttfonts目錄中添加字體文件。

$this->fontdata = array(
    "name of your font" => array(
     'T' => "Neutra_Display_Thin_Alt.ttf",// path to your font 
    ) 
); 

有關更多信息,請參閱此link