开发者

opening pdf using ashx (handler) file

开发者 https://www.devze.com 2023-04-13 04:31 出处:网络
This is the handler code: If I navigate directly to this handler it shows pdf fine. On Aspx page I have a image control, pdf doesn\'t show in imagecontrol. Accroding to all google search this is suppo

This is the handler code: If I navigate directly to this handler it shows pdf fine. On Aspx page I have a image control, pdf doesn't show in imagecontrol. Accroding to all google search this is supposed to be shown in image control

public void ProcessRequest(HttpContext context)
    {

            WebClient imageWebClient = new WebClient();
            byte[] imageBytes = imageWebClient.DownloadData(Testlocation);
            context.Response.ClearHeaders();
            //context.Response.ClearContent();
            context.Response.AddHeader("content-disposition", "inline; filename=image.pdf");
            context.Response.ContentType = "application/pdf";
            context.Response.AddHeader("Content-Length", imageBytes.Length.ToString());
            context.Response.BinaryWrite(imageBytes);
            context.Response.Flush();

}

Marku开发者_如何学编程p on Aspx page:


Accroding to all google search this is supposed to be shown in image control

No idea what searches you are referring to but image controls are supposed to display images, not PDFs. Image controls render as <img> tags in the HTML. <img> tags can only be used with images. If you want to embed a PDF inside a page you could use an <iframe> pointing its src property to your ashx handler.

0

精彩评论

暂无评论...
验证码 换一张
取 消