在DOMPDF中使用时,我遇到了阿拉伯字符问题...我尝试了所有内容,但没有任何工作......
我的DOMPDF版本是最后一个。我尝试安装字体并将charest设置为UTF-8和Windows-1256,但它仍然无效......
以下是HTML页面的代码:
<?php require("login3.php"); ?>
<?php
if (!empty($_POST)) {
// Used for later to determine result
$success = $error = false;
// Object syntax looks better and is easier to use than arrays to me
$post = new stdClass;
// Usually there would be much more validation and filtering, but this
// will work for now.
foreach ($_POST as $key => $val)
$post->$key = trim(strip_tags($_POST[$key]));
// Check for blank fields
if (empty($post->itemCode) OR
empty($post->itemDesc) OR
empty($post->itemQty) OR
empty($post->itemPrice) OR
empty($post->itemAgent))
$error = true;
else {
// Get this directory, to include other files from
$dir = dirname(__FILE__);
// Get the contents of the pdf into a variable for later
ob_start();
require_once($dir . '/pdf.php');
$pdf_html = ob_get_contents();
ob_end_clean();
// Load the dompdf files
require_once($dir . '/dompdf/dompdf_config.inc.php');
$dompdf = new DOMPDF(); // Create new instance of dompdf
$dompdf->load_html($pdf_html, "UTF-8"); // Load the html
$dompdf->render(); // Parse the html, convert to PDF
$pdf_content = $dompdf->output(); // Put contents of pdf into variable for later
// Get the contents of the HTML email into a variable for later
ob_start();
require_once($dir . '/html.php');
$html_message = ob_get_contents();
ob_end_clean();
date_default_timezone_set('Asia/Amman');
$tym = date('m-d-Y : hi a');
$filename = ' Order ' . $tym;
$dompdf->load_html($_SESSION['prints']['table']);
$dompdf->stream( $_SESSION["username"] . $filename . ".pdf"); // Streams the PDF to the client. Will open a download dialog by default
// Load the SwiftMailer files
require_once($dir . '/swift/swift_required.php');
$mailer = new Swift_Mailer(new Swift_MailTransport()); // Create new instance of SwiftMailer
$message = Swift_Message::newInstance()
->setSubject('New Order') // Message subject
->setTo(array('hussammoz@aol.com', 'hussammoz@GMAIL.com' => 'Orange Pharmacy Store')) // Array of people to send to
->setFrom(array('no-reply@net.tutsplus.com' => 'Orange Pharmacy Order System')) // From:
->setBody($html_message, 'text/html') // Attach that HTML message from earlier
->attach(Swift_Attachment::newInstance($pdf_content, $_SESSION["username"] . $filename . ".pdf", 'application/pdf')); // Attach the generated PDF from earlier
// Send the email, and show user message
if ($mailer->send($message))
$success = true;
else
$error = true;
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<link rel="shortcut icon" href="favicon.ico" />
<title>Orange Pharmacy Order System</title>
<style type="text/css" title="currentStyle">
@import "css/layout-styles.css";
@import "css/themes/smoothness/jquery-ui-1.8.4.custom.css";
{
font-family: arabic, Arabic, Serif;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
<script src="includes/jquery.ticker.js" type="text/javascript"></script>
<script src="includes/site.js" type="text/javascript"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<!-- jQuery libraries-->
<script type="text/javascript" src="js/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.14.custom.min.js"></script>
<script type="text/javascript" src="js/atooltip.jquery.js"></script>
<script type="text/javascript" src="js/kwicks-1.5.1.pack.js"></script>
<script type="text/javascript" src="js/script.js"></script>
<!-- Our jQuery script to make everything work -->
<script type="text/javascript" src="js/jq-ac-script.js"></script>
</head>
<body background="images/bg.jpg";>
<div id="cont">
<div style="position:absolute; top: 10px; left: 25px;">
<a href="index.php" class="normaltip" style="text-decoration:none" title="Home"> <img src="images/home.png"height="48" width="48"></a></div>
<div style="position:absolute; top: 60px; left: 25px;">
<a href="order.php" class="normaltip" style="text-decoration:none" title="New Order"><img src="images/system-software-update.png"height="48" width="48"></a></div>
<div id="container">
<h2 align="center"><img src="images/418694_259331167468533_385322251_n.jpg"></h1>
<div class="panel">
<div class="title-large">
<div class="theme"></div>
<p>
<h4 align="left"><b>Branch: <FONT COLOR="white"><?php echo($_SESSION["username"]); ? ></b></h4>
<script type="text/javascript">
function GetClock(){
d = new Date();
nday = d.getDay();
nmonth = d.getMonth();
ndate = d.getDate();
nyear = d.getYear();
nhour = d.getHours();
nmin = d.getMinutes();
nsec = d.getSeconds();
if (nyear<1000)
nyear=nyear+1900;
if (nhour == 0) {
ap = " AM";nhour = 12;
}
else if(nhour <= 11) {ap = " AM";}
else if(nhour == 12) {ap = " PM";}
else if(nhour >= 13) {ap = " PM";nhour -= 12;}
if(nmin <= 9) {nmin = "0" +nmin;}
if(nsec <= 9) {nsec = "0" +nsec;}
document.getElementById('clockbox').innerHTML =
"" + (nmonth+1) + "/" + ndate + "/" + nyear + " " +
nhour + ":" + nmin + ":" + nsec + ap + "";
setTimeout("GetClock()", 1000);
}
window.onload = GetClock;
</script>
<div id="clockbox"></div></font></div>
<?php if ($success) { ?>
<div class="message success">
<h4>Order Successfully Sent to Store </h4>
</div>
<?php } elseif ($error) { ?>
<div class="message error">
<h4>Sorry, an error occurred. Try again!</h4>
</div>
<?php } ?>
<div class="content inpad">
<div id="messageBox" style="margin-left:15px; padding-left:20px; padding-bottom:5px; border:1px #ccc solid; display:none;"></div>
<form method="post" action="#" id="itemsForm">
<h1 align="center"><font color="black"><b>Branch Order Form</b> </font></h1><br><br>
<select name="Priority" size="1">
<option value="Daily">Daily</option>
<option value="Monthly">Monthly</option>
<option value="Urgent">Urgent</option>
</select>
<table id="itemsTable" class="general-table">
<thead>
<tr>
<th></th>
<th>Item Code</th>
<th>Item Description</th>
<th>Item Qty</th>
<th>Item Price</th>
<th>Item Agent</th>
</tr>
</thead>
<tbody>
<tr class="item-row">
<td></td>
<td><input name="itemCode[]" value="" class="tInput" id="itemCode" readonly="readonly" /> </td>
<td><input name="itemDesc[]" value="" class="tInput" id="itemDesc" tabindex="1"/></td>
<td><input name="itemQty[]" value="" class="tInput" id="itemQty" tabindex="2"/></td>
<td><input name="itemPrice[]" value="" class="tInput" id="itemPrice" readonly="readonly" /> </td>
<td><input name="itemAgent[]" value="" class="tInput" id="itemAgent" readonly="readonly" /></td>
</tr>
</tbody>
</table>
<a href="#" id="addRow" class="button-clean large"><span> <img src="images/icon-plus.png" alt="Add" title="Add Row" /> Add Item</span> </a>
</div>
<input type="submit" value="SEND TO THE STORE">
</form>
</div>
</div>
<div id="container">
<link href="styles/ticker-style.css" rel="stylesheet" type="text/css" />
<h1></h1>
<ul id="js-news" class="js-hidden">
<li class="news-item">WELCOME <?php echo($_SESSION["username"]); ?> Branch Team:)</li>
<li class="news-item"><a href="newItem.php"target="_blank">LIST OF EXPIRY OF 03/2013 </a></li>
<li class="news-item">التي تنتهي بتاريخ 06/2013 avene الرجاء سحب جميع أصناف </li>
<li class="news-item">REMEMBER THAT URGENT ORDERS MUST BE BEFORE 10 A.M AND AFTER THAT ONLY DAILY ORDER</li>
<li class="news-item">URGENT ORDER IS THAT WHICH CONTAIN ITEMS YOU DON'T HAVE IN BRANCH OR CUSTOMER REQUEST!</li>
<li class="news-item"><FONT COLOR="RED">NEW ITEM<a href="newdrug.php">  Prospan Sachet</a></FONT>is available in store now... ORDER IT :)</li>
<li class="news-item">Further updates to jQuery News Ticker are coming soon!</li>
</ul>
<noscript>
<h2>Latest News</h2>
<ul id="no-js-news">
<li class="news-item">jQuery News Ticker now has support for multiple tickers per page!</li>
<li class="news-item">jQuery News Ticker now has support right-to-left languages!</li>
<li class="news-item">jQuery News Ticker now has support for loading content via an RSS feed!</li>
<li class="news-item">jQuery News Ticker now has an optional fade effect between items!</li>
<li class="news-item">New updates have been made to jQuery News Ticker! Check below for more details!</li>
<li class="news-item">jQuery News Ticker is now compatible with jQuery 1.3.2! See below for further details and for latest download.</li>
<li class="news-item">Further updates to jQuery News Ticker are coming soon, come back soon for more details.</li>
</ul>
</noscript>
</div>
</body>
</html>
PDF生成页面代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<style type="text/css">
HTML, BODY
{
font-family: Serif, arabic;
}
</style>
<h1 align="center"><img src=http://orangepharmacy.hostzi.com/418694_259331167468533_385322251_n.jpg></h1>
</head>
<body>
<h3 align="center"><b>Items <?php echo($_POST["Priority"]); ?> Order <br> Branch: <FONT COLOR="ORANGE"><?php echo($_SESSION["username"]); ?></h3>
<h6>
<table id="itemsTable" border="1" width="100%">
<thead>
<tr>
<th></th>
<th>Item Code</th>
<th>Item Description</th>
<th> Qty</th>
<th> Price</th>
<th> Agent</th>
</tr>
</thead>
<tbody>
<?php
foreach ($_POST["itemCode"] as $Key=> $itemCode) {
$itemDesc=$_POST["itemDesc"][$Key];
$itemPrice=$_POST["itemPrice"][$Key];
$itemQty=$_POST["itemQty"][$Key];
$itemAgent=$_POST["itemAgent"][$Key];
echo "<tr><td></td><td>" . $itemCode . "</td><td>" . $itemDesc .
"</td><td>" . $itemQty . " </td><td>" . $itemPrice .
"</td><td>" . $itemAgent ."</td></tr>";
}
?>
</tbody>
</table>
</h6>
<script type="text/php">
if (isset($pdf))
{
$font = Font_Metrics::get_font("serif");
// If verdana isn't available, we'll use sans-serif.
if (!isset($font)) {
Font_Metrics::get_font("serif");
}
$size = 6;
$color = array(0,0,0);
$text_height = Font_Metrics::get_font_height($font, $size);
$w = $pdf->get_width();
$h = $pdf->get_height();
// ------------------ FOOTER ------------------------------------------
if ($PAGE_NUM > 0)
{
$footer = $pdf->open_object();
$y = $h - 3 * $text_height - 24;
$text = "Orange Pharmacy Tel: 5536170 - Fax: 5536171"; //"Page {PAGE_NUM} of {PAGE_COUNT}"
$width = Font_Metrics::get_text_width("Orange Pharmacy Tel: 5536170 - Fax: 5536171", $font, $size);
$pdf->page_text($w / 2 - $width / 2, $y, $text, $font, $size, $color);
// Copyright line
$y += $text_height * 2;
$text = "Madina Monawara - University Street - Hussain - Dabouq - Jabal Amman - Airport - Dahet Alrasheed - Jubaiha - Yasmeen - Zarqa";
// Center the text
$width = Font_Metrics::get_text_width($text, $font, $size);
$pdf->page_text($w / 2 - $width / 2, $y, $text, $font, $size, $color);
// Add a logo
$img_w = 0.5 * 72; // 0.5 inches, in points
$img_h = 0.5 * 72; // 0.5 inch, in points -- change these as required
//$pdf->image("", 0, $y, $img_w, $img_h);
$pdf->close_object();
$pdf->add_object($footer, "all");
}
// ------------------ FOOTER END ------------------------------------------
}
</script>
<script type="text/php">
if ( isset($pdf) ) {
$font = Font_Metrics::get_font("serif", "bold");
$pdf->page_text(36, 9, "Page: {PAGE_NUM} of {PAGE_COUNT}",
$font, 6, array(0,0,0));
}
</script>
</body>
</html>
我尝试了一个月,但没有任何作用。我该如何解决?
答案 0 :(得分:0)
对我来说,我使用了以下内容
$html=mb_convert_encoding($html, 'UTF-8',
mb_detect_encoding($html, 'UTF-8, ISO-8859-1', true));
$mpdf = new \Mpdf\Mpdf();
$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;
$mpdf->WriteHTML($html);
$mpdf->Output();
然后它起作用。
答案 1 :(得分:0)
我将这个包用于 Persian
并且它运行良好:
https://github.com/mccarlosen/laravel-mpdf