1

I am having trouble streaming my PDF to the browser and displaying the correct size. It actually works fine in Firefox, Chrome, Safari but for some reason IE wants to set my zoom level to 662%. If I manually set it to "Actual Fit" it looks like it does in all the other browsers. IE is setting to "Fit Width" I am not sure if I am missing something and that is why IE is doing it's own thing. My code is as follows:

using (MemoryStream memoryStream = new MemoryStream())
{
    Document oDocument = new Document(PageSize.LETTER, 0f, 0f, 0f, 0f);

    PdfWriter oWriter = PdfWriter.GetInstance(oDocument, memoryStream);
    Image oImage = Image.GetInstance(GetBadge(context.Request["badge"]));

    float width = oImage.Width / 4f;
    float height = oImage.Height / 4f;

    oImage.ScaleToFit(width,height);
    oDocument.SetPageSize(new Rectangle(width, height));

    oDocument.Open();
    oDocument.Add(oImage);
    oDocument.Close();

    byte[] bytes = memoryStream.ToArray();
    memoryStream.Close();

    context.Response.Buffer = true;
    context.Response.Clear();
    context.Response.ClearContent();
    context.Response.ClearHeaders();
    context.Response.ContentType = "application/pdf";
    context.Response.AddHeader("Content-Disposition", string.Format("inline; filename=badge_{0}", DateTime.Now.ToShortDateString()));
    context.Response.AddHeader("Content-Length", bytes.Length.ToString());
    context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
    context.Response.BinaryWrite(bytes);
    context.Response.Flush();
}

The GetBadge function on Image is just getting a varbinary field from the database.

briank
  • 83
  • 11
  • 1
    You aren't setting any zoom or default magnification hints above, so is it possible that IE is just using whatever setting it had previously? Try unzooming in IE, quitting IE and trying your page again to see if it changes. Also, take a look at [Bruno's answer here](http://stackoverflow.com/a/24383193/231316) for setting these initial hints. – Chris Haas Jun 03 '15 at 19:22

0 Answers0