title: Output PDF file using header
body: <p>I can output a PHP table in an excel file using this code:</p>
  
  <pre><code>&lt;?php 
  
  require("aacfs.php");
  
  header("Content-type: application/octet-stream");
  header("Content-Disposition: attachment; filename=Cancelled Flight Summary_sortbydate.xls");
  header("Pragma: no-cache");
  header("Expires: 0");
  
  echo "&lt;center&gt;Ayala Aviation Corporation&lt;/center&gt;";
  echo "&lt;center&gt;&lt;b&gt;Cancelled Flight Summary&lt;/b&gt;&lt;/center&gt;";
  echo "&lt;center&gt;For the period ________&lt;/center&gt;&lt;/br&gt;&lt;/br&gt;";
  
  $result=mysql_query("select * from reservation where status='Cancelled' order by bdate");   
  echo "&lt;center&gt;&lt;/br&gt;&lt;/br&gt;&lt;table border=1 class='imagetable'&gt;&lt;tr&gt;
      &lt;th&gt;Flight Date&lt;/th&gt; 
      &lt;th&gt;Client&lt;/th&gt;
      &lt;th&gt;Group Code&lt;/th&gt;
      &lt;th&gt;Itinerary&lt;/th&gt;
      &lt;th&gt;ETD&lt;/th&gt;
      &lt;th&gt;Aircraft&lt;/th&gt;
      &lt;th&gt;ETA&lt;/th&gt;
      &lt;th&gt;Reservation No.&lt;/th&gt;
      &lt;th&gt;Last Status&lt;/th&gt;
      &lt;th&gt;Remarks&lt;/th&gt;
      &lt;th&gt;Reserved By&lt;/th&gt;
      &lt;/tr&gt;";
  if(mysql_num_rows($result)&gt;0)
  {
  while($row=mysql_fetch_array($result))
  {
      $rvno=$row['reservno'];
      $yr=(string) date("Y");
      $rn=$yr."-".$rvno;
      echo"&lt;tr&gt;&lt;td&gt;".$row['fdate']."&lt;/td&gt;&lt;td&gt;".$row['cliename']."&lt;/td&gt;&lt;td&gt;".$row['grpcode']."&lt;/td&gt;&lt;td&gt;".$row['itinerary']."&lt;/td&gt;&lt;td&gt;".$row['etd']."&lt;/td&gt;&lt;td&gt;".$row['acode']."&lt;/td&gt;&lt;td&gt;".$row['eta']."&lt;/td&gt;&lt;td&gt;".$rn."&lt;/td&gt;&lt;td&gt;".$row['lstatus']."&lt;/td&gt;&lt;td&gt;".$row['remarks']."&lt;/td&gt;&lt;td&gt;".$row['adminid']."&lt;/td&gt;&lt;/tr&gt;";
  
  }
  }
  else
      { ?&gt;
          &lt;tr&gt;&lt;td colspan="11" style="text-align:center; color:#FF0000; font-size:16px;"&gt;*No Data Available!*&lt;/td&gt;&lt;/tr&gt;
          &lt;?php
      }
          ?&gt;&lt;?php
  
  
  
  ?&gt;
  </code></pre>
  
  <p>I tried this, </p>
  
  <pre><code>&lt;?php 
  
  require("aacfs.php");
  
  header("Content-type: application/pdf");
  header("Content-Disposition: attachment; filename=Cancelled Flight Summary_sortbydate.pdf");
  header("Pragma: no-cache");
  header("Expires: 0");
  
  echo "&lt;center&gt;Ayala Aviation Corporation&lt;/center&gt;";
  echo "&lt;center&gt;&lt;b&gt;Cancelled Flight Summary&lt;/b&gt;&lt;/center&gt;";
  echo "&lt;center&gt;For the period ________&lt;/center&gt;&lt;/br&gt;&lt;/br&gt;";
  
  $result=mysql_query("select * from reservation where status='Cancelled' order by bdate");   
  echo "&lt;center&gt;&lt;/br&gt;&lt;/br&gt;&lt;table border=1 class='imagetable'&gt;&lt;tr&gt;
      &lt;th&gt;Flight Date&lt;/th&gt; 
      &lt;th&gt;Client&lt;/th&gt;
      &lt;th&gt;Group Code&lt;/th&gt;
      &lt;th&gt;Itinerary&lt;/th&gt;
      &lt;th&gt;ETD&lt;/th&gt;
      &lt;th&gt;Aircraft&lt;/th&gt;
      &lt;th&gt;ETA&lt;/th&gt;
      &lt;th&gt;Reservation No.&lt;/th&gt;
      &lt;th&gt;Last Status&lt;/th&gt;
      &lt;th&gt;Remarks&lt;/th&gt;
      &lt;th&gt;Reserved By&lt;/th&gt;
      &lt;/tr&gt;";
  if(mysql_num_rows($result)&gt;0)
  {
  while($row=mysql_fetch_array($result))
  {
      $rvno=$row['reservno'];
      $yr=(string) date("Y");
      $rn=$yr."-".$rvno;
      echo"&lt;tr&gt;&lt;td&gt;".$row['fdate']."&lt;/td&gt;&lt;td&gt;".$row['cliename']."&lt;/td&gt;&lt;td&gt;".$row['grpcode']."&lt;/td&gt;&lt;td&gt;".$row['itinerary']."&lt;/td&gt;&lt;td&gt;".$row['etd']."&lt;/td&gt;&lt;td&gt;".$row['acode']."&lt;/td&gt;&lt;td&gt;".$row['eta']."&lt;/td&gt;&lt;td&gt;".$rn."&lt;/td&gt;&lt;td&gt;".$row['lstatus']."&lt;/td&gt;&lt;td&gt;".$row['remarks']."&lt;/td&gt;&lt;td&gt;".$row['adminid']."&lt;/td&gt;&lt;/tr&gt;";
  
  }
  }
  else
      { ?&gt;
          &lt;tr&gt;&lt;td colspan="11" style="text-align:center; color:#FF0000; font-size:16px;"&gt;*No Data Available!*&lt;/td&gt;&lt;/tr&gt;
          &lt;?php
      }
          ?&gt;&lt;?php
  
  
  
  ?&gt;
  </code></pre>
  
  <p>And it does download a PDF file but it can't be opened.</p>
  
  <p>Is it really impossible to output the PHP table in a PDF file the same way it does in the above code? Or I'm just doing something wrong on my 2nd code? This way is the easiest for me so I'm eager to know if it is impossible (if it is, then why?) or possible. And please point me out to an easy alternative to achieve this in case it is not possible, since I'm new to generating external files through PHP. Any help would do. Thanks.</p>