title: Why does generated PDF display properly in Internet Explorer but not in FireFox or Chrome?
body: <p>I'm generating PDFs in Java using lowagie/iTextPDF and am having a problem displaying the output in Firefox and Chrome, but IE8 displays them fine.  </p>
  
  <p>Firefox and Chrome display gibberish, like this:</p>
  
  <p>%PDF-1.4 %���� 2 0 obj &lt;>stream x���1B1C��#@�0#��Tm>}Zh�nO?8���1�a��غ�y�ӓB���$��:9XC�a.�/f{���$� o�-$?Ө � ^�c�/��'E�j��}WT�/��Y&lt; ?� �5* endstream endobj 4 0 obj &lt;>>>/MediaBox[0 0 612 1008]/Rotate 90>> endobj 1 0 obj &lt;> endobj 3 0 obj &lt;> endobj 5 0 obj &lt;> endobj 6 0 obj &lt;> endobj xref 0 7 0000000000 65535 f 0000000379 00000 n 0000000015 00000 n 0000000467 00000 n 0000000211 00000 n 0000000530 00000 n 0000000575 00000 n trailer &lt;]/Info 6 0 R/Size 7>> startxref 697 %%EOF </p>
  
  <p>Here's part of the servlet code:</p>
  
  <pre><code>ByteArrayOutputStream baos = new ByteArrayOutputStream();                      
  Document reportPDFDocument = (Document)generateReport(request,conn,baos);             
  PdfWriter.getInstance(reportPDFDocument, baos);
  response.setHeader("Expires", "0");
  response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
  response.setHeader("Pragma", "public");
  response.setContentType("application/pdf");       
  response.setHeader("Content-disposition","inline; filename=PrintedSchedule.pdf");
  ServletOutputStream out = response.getOutputStream();
  baos.writeTo(out);
  out.flush();
  </code></pre>
  
  <p>I've already tried updating Firefox, updating the PDF plugin, and making sure it was set to use Adobe's PDF viewer instead of Firefox's viewer.</p>
  
  <p>As a test, I changed this line:</p>
  
  <p>From:</p>
  
  <pre><code> response.setHeader("Content-disposition","inline; filename=PrintedSchedule.pdf");
  </code></pre>
  
  <p>To:</p>
  
  <pre><code> response.setHeader("Content-disposition","attachment; filename=PrintedSchedule.pdf");
  </code></pre>
  
  <p>Internet Explorer seems to recognize that it's a PDF that's being downloaded. I get a popup window in IE that says:</p>
  
  <p><b>
  Do you want to open or save this file:</p>
  
  <p>Name: PrintedSchedule.pdf
  Type: ADobe Acrobat Document
  </b></p>
  
  <p>But FireFox thinks it's an 'htm' document, and gives this:
  <b></p>
  
  <p>You have chosen to open:</p>
  
  <p>PrintedSchedule.pdf
  which is a: HTML Document
  </b></p>
  
  <p>In Firefox I then choose Adobe Reader to open it with, and it works OK. But In the title bar I noticed that it appended '.htm' to the end of the file name.</p>
  
  <p>Could this be a clue as to the problem?  If so, how can I force Firefox to recognize it as a PDF?  The users want the PDF to display in the browser, not in a popup window, and they don't want to have to download the PDF files separately.</p>