2011-12-22 9 views
3

これはChromeとFirefoxで動作しますが、IE8では何も表示されません... Webformsボタンで同じコードを試してみると3つのブラウザすべてで機能します。IHttpHandler Response.ContentType = "application/pdf"がIE8で壊れています

IE8でこれを動作させるにはどうすればよいですか?

public class ShowPDF : IHttpHandler 
{ 

    public void ProcessRequest(HttpContext context) 
    { 
     // create PDF document 
     var document = new PdfDocument(); 
     var page = document.AddPage(); 
     var font = new XFont("Verdana", 20, XFontStyle.Bold); 
     var gfx = XGraphics.FromPdfPage(page); 
     gfx.DrawString("Hello, World!", font 
      , PdfSharp.Drawing.XBrushes.Black 
      , new PdfSharp.Drawing.XRect(0, 0, page.Width, page.Height) 
      , PdfSharp.Drawing.XStringFormats.Center 
     ); 

     // Send PDF to browser 
     var stream = new System.IO.MemoryStream(); 
     document.Save(stream, false); 
     context.Response.Clear(); 
     context.Response.ContentType = "application/pdf"; 
     context.Response.AddHeader("content-length", stream.Length.ToString()); 
     context.Response.BinaryWrite(stream.ToArray()); 
     context.Response.Flush(); 
     stream.Close(); 
     context.Response.End(); 
    } 

    public bool IsReusable 
    { 
     get 
     { 
      return false; 
     } 
    } 
} 
+0

FFとChromeでコードが動作する場合は、application/pdf mimeタイプがIEに登録されていない可能性が最も高いです。 IEから他のPDFリンクにアクセスできますか? –

+0

はい、これをaspxボタンのクリックに入れるとIE8で正常に動作します。私はそれをページの読み込みに入れると何も表示しません。 – Garfield

+0

IE9を試しましたか? –

答えて

2

解決済み!それはブラウザの設定になった。

@BrianRogers - これをテストしていただきありがとうございます。私は "window.location.href = 'ShowPDF.ashx';" IE8は空白のページを表示しました。これにより、私はブラウザの設定に疑問を感じました。私はFoxit Readerをアンインストールし、Adobe Readerをインストールしました。今はすべて期待どおりに動作します。

私はaspxサーバー側のボタンをクリックしてPDFをレンダリングするコードを置くと混乱していましたが、IE8はPDFをうまく表示しました! Go figure!そのため私は以前のブラウザ構成には疑問を呈していませんでした。