C#iTextSharp流PDF到浏览器和控制放大IE

时间:2015-06-03 14:31:58

标签: c# pdf itextsharp

我无法将PDF流式传输到浏览器并显示正确的大小。它实际上在Firefox,Chrome,Safari中工作正常,但出于某种原因,IE想要将缩放级别设置为662%。如果我手动将其设置为" Actual Fit"它看起来像在所有其他浏览器中一样。 IE设置为"适合宽度"我不确定我是否遗漏了一些东西,这就是为什么IE正在做它自己的事情。我的代码如下:

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();
}

Image上的GetBadge函数只是从数据库中获取varbinary字段。

0 个答案:

没有答案
相关问题