我正在使用FPDF创建PDF。 PDF可以95%的时间呈现到网页。有时,PDF将呈现到页面,所有文本字符左对齐,但堆叠在彼此之上。好像字母间距设置为零!
当我右键单击网页并从“右键单击”菜单中单击“打印”并打印PDF时,同样的事情发生了,但是所有的时间.....然而,当我保存PDF到我的桌面,并打开它打印,PDF将打印正常所有的时间!为什么??我已卸载,然后重新安装我的打印机\驱动程序两次。我没有尝试从不同的打印机/计算机打印...此外,我确实有一个备份副本,我知道从2017年12月18日没有这个问题,它仍然使用该副本也是如此....
查看图片
date_default_timezone_set('America/Phoenix');
require('fpdf/fpdf.php');
class PDF_receipt extends FPDF {
function __construct ($orientation = 'L', $unit = 'pt', $format = 'Letter',
$margin = 33) {
$this->FPDF($orientation, $unit, $format);
$this->SetTopMargin($margin);
$this->SetLeftMargin($margin);
$this->SetRightMargin($margin);
$this->SetAutoPageBreak(true, $margin);
}
// HEADER FUNCTION
function Header() {
$this->SetFont('Arial', '', 16);
$this->SetXY(30, 15);
$this->SetFillColor(232, 249, 169);
$this->SetTextColor(100);
$this->Cell(0, 30, "MONKEYPOD KITCHEN ONLINE ORDERING", 0, 1, 'C', true);
$this->Image("images/ttdinfocopy.jpg",40,55,225,60,"jpg", "");
$this->Image("images/mens-ladies-keiki.jpg",535,58,200,42,"jpg", "");
}
// ORDER SUBMIT DATE FUNCTION
function SubmitDate() {
$this->SetFont('Arial', '', 11);
$this->SetXY(150, 252);
$this->Cell(222, 20, 'Order Date: ' . date('F jS Y g:i:s A') . ' AZ time', 0, 1);
}
// TABLE CONSTRUCTION FUNCTION
function QtyTable() {
$this->SetFont('Arial', '', 9);
$this->SetTextColor(0);
$this->SetFillColor(240);
$this->SetLineWidth(1);
$this->SetXY(30, 242);
$this->Cell(100, 10, "", '0', 0, 'C', false);
$this->Cell(300, 10, "", '0', 0, 'C', false);
$this->Cell(95, 10, "", '0', 0, 'C', false);
$this->Cell(28, 10, "", '0', 0, 'C', false);
$this->Cell(28, 12, "3-6", 'LTR', 0, 'C', true);
$this->Cell(28, 12, "6-12", 'LTR', 0, 'C', true);
$this->Cell(28, 12, "12-18", 'LTR', 0, 'C', true);
$this->Cell(28, 12, "18-24", 'LTR', 0, 'C', true);
$this->Cell(28, 10, "", '0', 0, 'C', false);
$this->Cell(28, 10, "", '0', 0, 'C', false);
$this->Cell(38, 10, "", '0', 0, 'C', false);
$this->Ln(10);
$this->Cell(97, 10, "", '0', 0, 'C', false);
$this->Cell(300, 10, "", '0', 0, 'C', false);
$this->Cell(95, 10, "", '0', 0, 'C', false);
$this->Cell(28, 10, "", '0', 0, 'C', false);
$this->Cell(28, 10, "Month", 'LR', 0, 'C', true);
$this->Cell(28, 10, "Month", 'LR', 0, 'C', true);
$this->Cell(28, 10, "Month", 'LR', 0, 'C', true);
$this->Cell(28, 10, "Month", 'LR', 0, 'C', true);
$this->Cell(28, 10, "", '0', 0, 'C', false);
$this->Cell(28, 10, "", '0', 0, 'C', false);
$this->Cell(38, 10, "", '0', 0, 'C', false);
$this->Ln(10);
$this->Cell(97, 20, "", '0', 0, 'C', false);
$this->Cell(300, 20, "", '0', 0, 'C', false);
$this->Cell(95, 20, "", '0', 0, 'C', false);
$this->Cell(28, 20, "2", 'LTR', 0, 'C', true);
$this->Cell(28, 20, "4", 'LTR', 0, 'C', true);
$this->Cell(28, 20, "6", 'LTR', 0, 'C', true);
$this->Cell(28, 20, "8", 'LTR', 0, 'C', true);
$this->Cell(28, 20, "10", 'LTR', 0, 'C', true);
$this->Cell(28, 20, "12", 'LTR', 0, 'C', true);
$this->Cell(28, 20, "O/S", 'LTR', 0, 'C', true);
$this->Cell(38, 20, "", '0', 0, 'C', false);
$this->Ln(18);
$this->Cell(97, 20, "Item Name", 'LTR', 0, 'C', true);
$this->Cell(300, 20, "Description", 'LTR', 0, 'C', true);
$this->Cell(95, 20, "Color", 'LTR', 0, 'C', true);
$this->Cell(28, 20, "XS", 'LTR', 0, 'C', true);
$this->Cell(28, 20, "SM", 'LTR', 0, 'C', true);
$this->Cell(28, 20, "MD", 'LTR', 0, 'C', true);
$this->Cell(28, 20, "LG", 'LTR', 0, 'C', true);
$this->Cell(28, 20, "XL", 'LTR', 0, 'C', true);
$this->Cell(28, 20, "XX", 'LTR', 0, 'C', true);
$this->Cell(28, 20, "XXX", 'LTR', 0, 'C', true);
$this->Cell(38, 20, "Total", 'LTR', 1, 'C', true);
}
function MessageBottom() {
$message = "Thank you for your online order. If you have any questions, you can email us at the following address: ";
$this->SetFont('Arial', '', 10);
$this->SetFillColor(242);
$this->SetXY(35, 560);
$this->Write(12, $message);
}
function EmailAddress() {
$this->SetFont('Arial', 'U', 10);
$this->SetTextColor(1, 162, 232);
$this->SetXY(488, 559.5);
$this->Write(12, "orders@taketwodesigns.com", "mailto:orders@taketwodesigns.com?subject=Question...&body=link to PDF: http://taketwodesigns.com/monkeypod/php-pdf-practice/retrieve_order.php");
}
function Footer() {
$this->SetFont('Arial', '', 10);
$this->SetTextColor(0);
$this->SetXY(30, 575);
$this->Cell(0, 35, "Take Two Designs", 'T', 0, 'C');
}
// KA'ANAPALI ITEMS BELOW
// ITEM 1
function Item1() {
if(isset($_POST['item1Qty'])) {
$item1name = $_POST['item1name'];
$item1desc = $_POST['item1desc'];
$item1color = $_POST['item1color'];
$item1Qty = $_POST['item1Qty'];
$this->SetFont('Arial', '', 10);
$this->SetFillColor(242);
$this->SetLineWidth(1);
$this->SetXY(33, 302);
$this->Cell(97, 20, $item1name, 1, 0, 'L');
$this->Cell(300, 20, $item1desc, 1, 0, 'L');
$this->Cell(95, 20, $item1color, 1, 0, 'L');
$this->Cell(28, 20, $item1Qty[0], 1, 0, 'C');
$this->Cell(28, 20, $item1Qty[1], 1, 0, 'C');
$this->Cell(28, 20, $item1Qty[2], 1, 0, 'C');
$this->Cell(28, 20, $item1Qty[3], 1, 0, 'C');
$this->Cell(28, 20, $item1Qty[4], 1, 0, 'C');
$this->Cell(28, 20, $item1Qty[5], 1, 0, 'C');
$this->Cell(28, 20, '', 1, 0, 'C');
$this->Cell(38, 20, array_sum($item1Qty), '1', 0, 'C');
}
}
// CREATE PDF PAGE
$pdf = new PDF_receipt();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 12);
// GREY RECTANGLES CREATED TO FILL PDF FIELD BACKGROUND COLOR
$pdf->SetFillColor(242);
$pdf->Rect(128, 125, 200, 100, 'F');
$pdf->Rect(537, 125, 200, 100, 'F');
// ORDERED-BY TEXT
$pdf->SetFont('Arial', '', 10);
$pdf->SetXY(45, 125);
$pdf->Cell(80, 20, "Customer PO:", 0, 2, 'R');
$pdf->Cell(80, 20, "Cancel Date:", 0, 2, 'R');
$pdf->Cell(80, 20, "Contact Phone:", 0, 2, 'R');
$pdf->Cell(80, 20, "Buyer:", 0, 2, 'R');
$pdf->Cell(80, 20, "Email:", 0, 2, 'R');
// ORDERED-BY INFO BOX
$pdf->SetFont('Arial', '');
$pdf->SetXY(128, 125);
$pdf->Cell(200, 20, $_POST['ponum'], 1, 2);
$pdf->Cell(200, 20, $_POST['canceldate'], 1, 2);
$pdf->Cell(200, 20, $_POST['contactphone'], 1, 2);
$pdf->Cell(200, 20, $_POST['buyer'], 1, 2);
$pdf->Cell(200, 20, $_POST['orderemail'], 1, 2);
// SHIP-TO TEXT
$pdf->SetFont('Arial', '');
$pdf->SetXY(454, 125);
$pdf->Cell(80, 20, "Ship To/Bill To:", 0, 2, 'R');
$pdf->Cell(80, 20, "Address:", 0, 2, 'R');
$pdf->Cell(80, 20, "City, State, Zip:", 0, 2, 'R');
$pdf->Cell(80, 20, "Phone:", 0, 2, 'R');
$pdf->Cell(80, 20, "Email:", 0, 2, 'R');
// SHIP-TO INFO BOX
$pdf->SetFont('Arial', '');
$pdf->SetXY(537, 125);
$pdf->Cell(200, 20, ' Monkeypod Kitchen - Ka\'anapali', 1, 2);
$pdf->Cell(200, 20, ' 1489 Ka\'anapali Pkwy.', 1, 2);
$pdf->Cell(200, 20, ' Lahaina HI, 96742', 1, 2);
$pdf->Cell(200, 20, ' 602-555-5555', 1, 2);
$pdf->Cell(200, 20, ' bigd@ccccvvbb.net', 1, 2);
// ITEMS TABLE FUNCTION CALL
$pdf->QtyTable();
// ORDER DATE FUNCTION CALL
$pdf->SubmitDate();
// ITEMS FUNCTION CALLS
$pdf->Item1();
$pdf->Item2();
$pdf->Item3();
$pdf->Item4();
$pdf->Item5();
$pdf->Item6();
$pdf->Item7();
$pdf->Item8();
$pdf->Item9();
$pdf->Item10();
$pdf->Item11();
// BOTTOM MESSAGES FUNCTION CALLS
$pdf->MessageBottom();
$pdf->EmailAddress();
// OUTPUT NEW PDF TO FOLDER
$pdf->Output('receipts/receipt_' . date("mdY_His") . '.pdf', 'F');
“检索文件代码”
date_default_timezone_set('America/Phoenix');
$dir = "receipts";
$pattern = '/\.(zip|ZIP|pdf|PDF)$/'; // only check files with these extensions
$newstamp = 0;
$newname = "";
if ($handler = opendir($dir)) {
while (false !== ($fname = readdir($handler))) {
// Eliminate current directory, parent directory
if (preg_match('/^\.{1,2}$/',$fname)) continue;
// Eliminate other pages not in pattern
if (! preg_match($pattern,$fname)) continue;
$timedat = filemtime("$dir/$fname");
if ($timedat > $newstamp) {
$newstamp = $timedat; // $newstamp is the time for the latest file
$newname = $fname; // $newname is the name of the latest file
}
}
}
closedir ($handler);
// We'll be outputting a PDF
header('Content-Type: application/pdf');
header('Location: receipts/'.$newname);