TCPDF-下载不带IDM的文件时显示不需要的字符

时间:2018-09-29 08:07:01

标签: php tcpdf

我正在使用tcpdf将MYSQL数据下载为PDF格式。现在,如果启用IDM(Internet下载管理器),则文件正在下载,但是如果禁用IDM,则显示不想要的字符:(

  

%PDF-1.7%����6 0 obj << / Type / Page / Parent 1 0 R /最后修改   (D:20180929100233 + 02'00')/资源2 0 R / MediaBox [0.000000   0.000000 841.890000 595.276000] / CropBox [0.000000 0.000000 841.890000 595.276000] / BleedBox [0.000000 0.000000 841.890000 595.276000] / TrimBox [0.000000 0.000000 841.890000 595.276000] / ArtBox [0.000000   0.000000 841.890000 595.276000] /目录7 0 R /旋转0 /组<< /类型/组/ S /透明度/ CS / DeviceRGB >> / Annots [5 0 R] / PZ   1 >> endobj 7 0 obj <>流   x��]MS�8�+ t [��$ [�L��j�vg�!��a&q��$�8�d�׏���    �l(:[��{"���Y��k�Q��9Ȝ0�Ѽ�!_��]�4�ۣF��z!��-����{Ӂ��y87�9+�0���e:b��v�|9n�㼘��#�⚈k\。无    �?? |%폋��ĉv�,Һ|ỻ\。   W;������箶TǷ��Sܒ��)��3R���I'{{@''�����_![����qw��JDT��M1$�UDF1 ��7=j�;�+�������,5 /“j�M�O���֞K�!���&�).����k��a����   ``mG��ڑ�Ҷ#''���ph9v��dF。

我的PHP代码:

<?php
ob_clean();
ob_flush();
session_start();
spl_autoload_register(function ( $class ) {
    require_once('../classes/'.strtolower($class).'.'.'php');
});

require_once('tcpdf_include.php');

// get booking data
$booking        = new Admin;
$letter         = new Admin;

$permission     = Session::get('logged_permission');
$logged_id      = Session::get('logged_id');
$logged_agent_id  =  Session::get('logged_agent_id');

$bookingStart   = isset($_GET['bookingDate']) ? $_GET['bookingDate'] : '';
$bookingEnd     = isset($_GET['bookingEnd']) ? $_GET['bookingEnd'] : '';
$ref            = isset($_GET['ref']) ? $_GET['ref'] : '';
$supplier       = isset($_GET['supplier']) ? $_GET['supplier'] : '';
$vehicleName    = isset($_GET['vehicleName']) ? $_GET['vehicleName'] : '';
$driver         = isset($_GET['driver']) ? $_GET['driver'] : '';
$bookingId      = isset($_GET['bookingId']) ? $_GET['bookingId'] : '';

$column_name = "b.bid, b.refid, b.remark, b.tourname, b.noOfAdult, b.noOfChild, b.trip, b.flight, b.ref, b.vehicleType, b.bookingDate, b.gname, b.is_confirm, b.is_assign, b.bookingId, a.payable, a.amount, a.asgid, a.sid, a.vid, a.did, a.note, a.assigned_start, a.assigned_end, a.is_complete, d.fname, d.lname, v.vehicleName, s.supplierName";

$sql = " SELECT $column_name FROM booking AS b LEFT JOIN assigned AS a ON b.bid = a.bid LEFT JOIN vehicle AS v ON v.vid = a.vid LEFT JOIN driver AS d ON d.did = a.did LEFT JOIN supplier AS s ON s.sid = a.sid LEFT JOIN supplier ON s.sid = a.sid  WHERE b.is_confirm = 1 AND b.is_assign = 1 AND b.is_enquiry = 1 AND b.agent_id = $logged_agent_id ";

$time = time();

if( !empty($bookingStart))  {
    $sql .= "AND b.bookingDate BETWEEN $bookingStart AND $time ";
} elseif( !empty($bookingEnd))  {
    $sql .= "AND b.bookingDate < $bookingEnd ";
} elseif( !empty($bookingStart) && !empty($bookingEnd) )  {
    $sql .= "AND b.bookingDate BETWEEN $bookingStart AND $bookingEnd  ";
}
if( !empty($ref))   {
    $sql .= "AND b.ref LIKE '%$ref%' ";
}
if( !empty($supplier))   {
    $sql .= "AND s.supplierName LIKE '%$supplier%' ";
}
if( !empty($vehicleName))   {
    $sql .= "AND v.vehicleName LIKE '%$vehicleName%' ";
}
if( !empty($driver))   {
    $sql .= "AND d.fname LIKE '%$driver%' OR d.lname LIKE '%$driver%' ";
}
if( !empty($bookingId))   {
    $sql .= "AND b.bookingId LIKE '%$bookingId%' ";
}

$sql .= " GROUP BY a.bid";

$booking->rowQuery($sql);

$letter->rowQuery("SELECT letterhead, profile_img, printFooter FROM admin WHERE a_id = $logged_id ");
$dateLetterHead   =  $letter->result->fetch_assoc();
$letterhead       =  $dateLetterHead['letterhead'];
$printFooter      =  $dateLetterHead['printFooter'];
$profile_img      =  $dateLetterHead['profile_img'];

$numRows        =   $booking->rows;

if($numRows > 0 ) {

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetTitle('Booking Report on ' . date('d-m-Y h:i A'));
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}

$pdf->SetFont('helvetica', 'B', 20);
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->AddPage('L', 'A4');
$pdf->Cell(0, 0, 'Report On ' . date('m-d-y h:i A'), 0, 1, 'C');
$pdf->SetFont('helvetica', '', 8);

$html_heading = <<<EOD
<br/><br/>
<table cellspacing="0" cellpadding="1" width="100%">
    <tr>
      <th><strong>Sl.</strong></th>
      <th><strong>Tour Name</strong></th>
      <th><strong>Ref ID</strong></th>
      <th><strong>Booking Date</strong></th>
      <th><strong>Guest Name</strong></th>
      <th><strong>No Of Pax</strong></th>
      <th><strong>Pickup Location</strong></th>
      <th><strong>Pickup Time</strong></th>
      <th><strong>Drop Off Location</strong></th>
      <th><strong>Ref</strong></th>
      <th><strong>Booking ID</strong></th>
      <th><strong>Vehicle Type</strong></th>
      <th><strong>Driver</strong></th>
      <th><strong>Vehicle</strong></th>
      <th><strong>Supplier</strong></th>
      <th><strong>payable to supplier</strong></th>
      <th><strong>Recieve form customer </strong></th>
      <th><strong>Remark</strong></th>
   </tr>
</table>
EOD;

    $pdf->writeHTML($html_heading, true, false, false, false, '');
    $count = 1;
    $amount             =   0;
    $payable            =   0;

while ( $data           =   $booking->result->fetch_assoc() ) {

    $bid               =    (int) $data['bid'];
    $tourName          =    explode(',', $data['tourname']);
    $bookingDate       =    date('d-m-Y', $data['bookingDate']);
    $gname             =    $data['gname'];
    $noOfAdult         =    $data['noOfAdult'];
    $noOfChild         =    $data['noOfChild'];
    $trip              =    json_decode( $data['trip'], true );
    $flight            =    json_decode( $data['flight'], true );
    $ref               =    $data['ref'];
    $refid             =    $data['refid'];
    $remark            =    $data['remark'];
    $bookingId         =    $data['bookingId'];
    $vehicleType       =    $data['vehicleType'];
    $payable           +=    $data['payable'];
    $amount            +=    $data['amount'];
    $show_payable       =   $data['payable'];
    $show_amount       =   $data['amount'];
    $supplierName      =    $data['supplierName'];
    $status            =    $data['is_confirm'];
    $is_assign         =   $data['is_assign'];
    $is_complete       =   $data['is_complete'];

    if($status == 1) {
        $status = 'Booking Confirmed';
    } elseif( $status == 0) {
        $status = 'Booking Pending';
    }

    if($is_assign == 1) {
        $assign = 'Booking Assigned';
    } elseif( $is_assign == 0) {
        $assign = 'Assign Pending';
    }

    if($is_complete == 1) {
        $is_complete_status = 'Completed Booking';
    } elseif( $is_complete == 0) {
        $is_complete_status = 'Pending Complete';
    }

    $final_status = $status . ' <br/> ' . $assign . ' <br/> ' . $is_complete_status;

    $is_assign         =    $data['is_assign'];
    $is_complete       =    $data['is_complete'];
    $fname             =    $data['fname'];
    $lname             =    $data['lname'];
    $vehicleName       =    $data['vehicleName'];

$html = <<<EOD
<table>
<tr>
    <td>$count</td>
    <td>
EOD;

foreach ($tourName as $key => $value) {
$html .= <<<EOD
$value
EOD;
}

$html .= <<<EOD
    </td>
    <td>$refid</td>
    <td>$bookingDate</td>
    <td>$gname</td>
    <td>$noOfAdult Adult(s) <br/>  $noOfChild Child(s)</td>
    <td>
EOD;
foreach ($trip as $key => $value) {
    $chunk = array_chunk($value, 3);
        foreach ($chunk as $key1 => $value1) {
$html .= <<<EOD
$value1[0] <br/>
EOD;
    }
}
$html .= <<<EOD
    </td>
EOD;

$html .= <<<EOD
    <td>
EOD;
foreach ($trip as $key => $value) {
    $chunk = array_chunk($value, 3);
    foreach ($chunk as $key1 => $value1) {
$html .= <<<EOD
$value1[2] <br/>
EOD;
    }
}
$html .= <<<EOD
    </td>
EOD;

$html .= <<<EOD
    <td>
EOD;

foreach ($trip as $key => $value) {
    $chunk = array_chunk($value, 3);
    foreach ($chunk as $key1 => $value1) {
$html .= <<<EOD
$value1[1] <br/>
EOD;
    }
}

$html .=<<<EOD
    </td>
    <td>$ref</td>
    <td><strong>$bookingId</strong></td>
    <td>$vehicleType</td>
    <td>$fname $lname</td>
    <td>$vehicleName</td>
    <td>$supplierName</td>
    <td>$show_payable AED</td>
    <td>$show_amount AED</td>
    <td>$remark</td>
</tr>
</table>
EOD;

$pdf->writeHTML($html, true, false, false, false, '');
$count++;
}

$html_footer =<<<EOD
<table>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td>Total = </td>
        <td>$payable AED</td>
        <td>$amount AED</td>
        <td></td>
    </tr>
</table>
EOD;
$pdf->writeHTML($html_footer, true, false, false, false, '');

//$pdf->Output( 'booking-report-'.substr(md5(mt_rand()), 0, 7).'.pdf', 'I');
$pdf->Output( 'booking-report-on-'.time().'.pdf', 'I');

} else {
    echo '<div class="alert alert-danger">Opps! No data found. </div>';
}

0 个答案:

没有答案