开发者

Streaming pdf to the browser

I have to read pdf from a vendor url and then stream to the webpage. I am trying following code but it doesn't work. I checkecked image bytes - those are populated.

This is how the image control's p开发者_开发问答roperty set ImageUrl = "~/Controls/CheckImage/DraftImage.ashx?FB=F"

Following is the code from ashx page

public void ProcessRequest(HttpContext context) {

 WebClient imageWebClient = new WebClient();
  CheckImg.Draft.FrontImage.Image = imageWebClient.DownloadData(Url);
  context.Response.Clear();
  context.Response.ContentType = ("application/pdf");
  context.Response.AddHeader("Content-Disposition", "inline;filename=image.pdf");
  context.Response.BinaryWrite(CheckImg.Draft.FrontImage.Image); 
  context.Response.Flush();
  context.Response.Close();
  // context.Response.End(); 
 HttpContext.Current.ApplicationInstance.CompleteRequest();


I had lots of trouble with this. I final hit the right combo with this. The data byte array is an abcPdf.net pdf doc.

hope this helps:

byte[] data = doc.GetData();

            Response.Clear();
            Response.ClearHeaders();
            Response.ClearContent();    
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "inline; filename=MyPDF.PDF");
            Response.AddHeader("content-length", data.Length.ToString());
            Response.BinaryWrite(data);
            Response.Flush();
            Response.Close();
            Response.End(); 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜