title: TCPDF - Showing unwanted characters when downloading file without IDM
body: <p>I am downloading MYSQL data as PDF format using tcpdf. Now if I enable the IDM (Internet Download Manager) then the file is downloading but If I disabled the IDM then it's showing something unwanted characters :( </p>
  
  <blockquote>
    <p>%PDF-1.7 %���� 6 0 obj &lt;&lt; /Type /Page /Parent 1 0 R /LastModified
    (D:20180929100233+02'00') /Resources 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] /Contents 7 0 R /Rotate 0 /Group &lt;&lt; /Type /Group /S /Transparency /CS /DeviceRGB >> /Annots [ 5 0 R ] /PZ
    1 >> endobj 7 0 obj &lt;> stream
    x��]MS�8��+t[��$[�L��j�vg�!��a&amp;q��$�8�d�׏���
    �l(:[��<code>"���Y��k�Q��9Ȝ0�Ѽ�!_��]�4�ۣF��z!�</code>�-����{Ӂ��y87�9+�0���e:b��v�|9n�㼘��#�⚈k\�N�
    �??|%폋��ĉv�,Һ|ỻ\�
    W;���٪�箶TǷ��Sܒ��)��3R���I'�{�@"�����_![����qw��JDT��M1$�UDF1��7=j�;�+�������,5/"j�M�O���Y֞K�!���&amp;�)�����k��a����
    �mG��ڑ� Ҷ#"���ph9v��dF�</p>
  </blockquote>
  
  <p><strong>My PHP Code:</strong></p>
  
  <pre><code>&lt;?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 &lt; $bookingEnd ";
  } elseif( !empty($bookingStart) &amp;&amp; !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-&gt;rowQuery($sql);
  
  $letter-&gt;rowQuery("SELECT letterhead, profile_img, printFooter FROM admin WHERE a_id = $logged_id ");
  $dateLetterHead   =  $letter-&gt;result-&gt;fetch_assoc();
  $letterhead       =  $dateLetterHead['letterhead'];
  $printFooter      =  $dateLetterHead['printFooter'];
  $profile_img      =  $dateLetterHead['profile_img'];
  
  $numRows        =   $booking-&gt;rows;
  
  if($numRows &gt; 0 ) {
  
  // create new PDF document
  $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  $pdf-&gt;SetCreator(PDF_CREATOR);
  $pdf-&gt;SetTitle('Booking Report on ' . date('d-m-Y h:i A'));
  $pdf-&gt;SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  $pdf-&gt;SetHeaderMargin(PDF_MARGIN_HEADER);
  $pdf-&gt;SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  $pdf-&gt;setImageScale(PDF_IMAGE_SCALE_RATIO);
  if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
      require_once(dirname(__FILE__).'/lang/eng.php');
      $pdf-&gt;setLanguageArray($l);
  }
  
  $pdf-&gt;SetFont('helvetica', 'B', 20);
  $pdf-&gt;SetPrintHeader(false);
  $pdf-&gt;SetPrintFooter(false);
  $pdf-&gt;AddPage('L', 'A4');
  $pdf-&gt;Cell(0, 0, 'Report On ' . date('m-d-y h:i A'), 0, 1, 'C');
  $pdf-&gt;SetFont('helvetica', '', 8);
  
  $html_heading = &lt;&lt;&lt;EOD
  &lt;br/&gt;&lt;br/&gt;
  &lt;table cellspacing="0" cellpadding="1" width="100%"&gt;
      &lt;tr&gt;
        &lt;th&gt;&lt;strong&gt;Sl.&lt;/strong&gt;&lt;/th&gt;
        &lt;th&gt;&lt;strong&gt;Tour Name&lt;/strong&gt;&lt;/th&gt;
        &lt;th&gt;&lt;strong&gt;Ref ID&lt;/strong&gt;&lt;/th&gt;
        &lt;th&gt;&lt;strong&gt;Booking Date&lt;/strong&gt;&lt;/th&gt;
        &lt;th&gt;&lt;strong&gt;Guest Name&lt;/strong&gt;&lt;/th&gt;
        &lt;th&gt;&lt;strong&gt;No Of Pax&lt;/strong&gt;&lt;/th&gt;
        &lt;th&gt;&lt;strong&gt;Pickup Location&lt;/strong&gt;&lt;/th&gt;
        &lt;th&gt;&lt;strong&gt;Pickup Time&lt;/strong&gt;&lt;/th&gt;
        &lt;th&gt;&lt;strong&gt;Drop Off Location&lt;/strong&gt;&lt;/th&gt;
        &lt;th&gt;&lt;strong&gt;Ref&lt;/strong&gt;&lt;/th&gt;
        &lt;th&gt;&lt;strong&gt;Booking ID&lt;/strong&gt;&lt;/th&gt;
        &lt;th&gt;&lt;strong&gt;Vehicle Type&lt;/strong&gt;&lt;/th&gt;
        &lt;th&gt;&lt;strong&gt;Driver&lt;/strong&gt;&lt;/th&gt;
        &lt;th&gt;&lt;strong&gt;Vehicle&lt;/strong&gt;&lt;/th&gt;
        &lt;th&gt;&lt;strong&gt;Supplier&lt;/strong&gt;&lt;/th&gt;
        &lt;th&gt;&lt;strong&gt;payable to supplier&lt;/strong&gt;&lt;/th&gt;
        &lt;th&gt;&lt;strong&gt;Recieve form customer &lt;/strong&gt;&lt;/th&gt;
        &lt;th&gt;&lt;strong&gt;Remark&lt;/strong&gt;&lt;/th&gt;
     &lt;/tr&gt;
  &lt;/table&gt;
  EOD;
  
      $pdf-&gt;writeHTML($html_heading, true, false, false, false, '');
      $count = 1;
      $amount             =   0;
      $payable            =   0;
  
  while ( $data           =   $booking-&gt;result-&gt;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 . ' &lt;br/&gt; ' . $assign . ' &lt;br/&gt; ' . $is_complete_status;
  
      $is_assign         =    $data['is_assign'];
      $is_complete       =    $data['is_complete'];
      $fname             =    $data['fname'];
      $lname             =    $data['lname'];
      $vehicleName       =    $data['vehicleName'];
  
  $html = &lt;&lt;&lt;EOD
  &lt;table&gt;
  &lt;tr&gt;
      &lt;td&gt;$count&lt;/td&gt;
      &lt;td&gt;
  EOD;
  
  foreach ($tourName as $key =&gt; $value) {
  $html .= &lt;&lt;&lt;EOD
  $value
  EOD;
  }
  
  $html .= &lt;&lt;&lt;EOD
      &lt;/td&gt;
      &lt;td&gt;$refid&lt;/td&gt;
      &lt;td&gt;$bookingDate&lt;/td&gt;
      &lt;td&gt;$gname&lt;/td&gt;
      &lt;td&gt;$noOfAdult Adult(s) &lt;br/&gt;  $noOfChild Child(s)&lt;/td&gt;
      &lt;td&gt;
  EOD;
  foreach ($trip as $key =&gt; $value) {
      $chunk = array_chunk($value, 3);
          foreach ($chunk as $key1 =&gt; $value1) {
  $html .= &lt;&lt;&lt;EOD
  $value1[0] &lt;br/&gt;
  EOD;
      }
  }
  $html .= &lt;&lt;&lt;EOD
      &lt;/td&gt;
  EOD;
  
  $html .= &lt;&lt;&lt;EOD
      &lt;td&gt;
  EOD;
  foreach ($trip as $key =&gt; $value) {
      $chunk = array_chunk($value, 3);
      foreach ($chunk as $key1 =&gt; $value1) {
  $html .= &lt;&lt;&lt;EOD
  $value1[2] &lt;br/&gt;
  EOD;
      }
  }
  $html .= &lt;&lt;&lt;EOD
      &lt;/td&gt;
  EOD;
  
  $html .= &lt;&lt;&lt;EOD
      &lt;td&gt;
  EOD;
  
  foreach ($trip as $key =&gt; $value) {
      $chunk = array_chunk($value, 3);
      foreach ($chunk as $key1 =&gt; $value1) {
  $html .= &lt;&lt;&lt;EOD
  $value1[1] &lt;br/&gt;
  EOD;
      }
  }
  
  $html .=&lt;&lt;&lt;EOD
      &lt;/td&gt;
      &lt;td&gt;$ref&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;$bookingId&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;$vehicleType&lt;/td&gt;
      &lt;td&gt;$fname $lname&lt;/td&gt;
      &lt;td&gt;$vehicleName&lt;/td&gt;
      &lt;td&gt;$supplierName&lt;/td&gt;
      &lt;td&gt;$show_payable AED&lt;/td&gt;
      &lt;td&gt;$show_amount AED&lt;/td&gt;
      &lt;td&gt;$remark&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  EOD;
  
  $pdf-&gt;writeHTML($html, true, false, false, false, '');
  $count++;
  }
  
  $html_footer =&lt;&lt;&lt;EOD
  &lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;Total = &lt;/td&gt;
          &lt;td&gt;$payable AED&lt;/td&gt;
          &lt;td&gt;$amount AED&lt;/td&gt;
          &lt;td&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  EOD;
  $pdf-&gt;writeHTML($html_footer, true, false, false, false, '');
  
  //$pdf-&gt;Output( 'booking-report-'.substr(md5(mt_rand()), 0, 7).'.pdf', 'I');
  $pdf-&gt;Output( 'booking-report-on-'.time().'.pdf', 'I');
  
  } else {
      echo '&lt;div class="alert alert-danger"&gt;Opps! No data found. &lt;/div&gt;';
  }
  </code></pre>