-7

I have data in a byte array. Now I need to generate a PDF from the byte array in a browser when a button is clicked. How can I do this?

Avery
  • 2,270
  • 4
  • 33
  • 35
user1369860
  • 19
  • 1
  • 2
  • If the bytes are already in the form of a PDF document, you just need to set the headers correctly. This is covered here: http://stackoverflow.com/questions/6319389/streaming-mime-type-application-pdf-from-asp-app-fails-in-google-chrome – David Jul 05 '12 at 13:21
  • @DavidStratton that link to [whathaveyoutried](http://www.whathaveyoutried.com) should really be in the FAQ but then again, users posting questions like these never actually read the FAQ which is all the more ... well... downvotes speak for itself :) – t0mm13b Jul 05 '12 at 15:47
  • hate them bloody userxxxxx hiding behind it and posting questions that just ensures the question the OP posted gets burned with fire! – t0mm13b Jul 05 '12 at 15:49
  • I'm presuming that the byte array is not _actually_ a PDF document, but a series of numbers that you wish to render as a PDF? I recommend you add substantially more detail to your question, since it is likely to close in its present state! – halfer Jul 05 '12 at 20:22

2 Answers2

7

If that byte array is of pdf document then you may write bytes to the response buffer.

Response.ClearHeaders();
Response.Clear();
Response.AddHeader("Content-Type","application/pdf");
Resopnse.AddHeader("Content-Length",byteArray.Length.ToString());
Response.AddHeader("Content-Disposition","inline; filename=sample.pdf");
Response.BinaryWrite(byteArray);
Response.Flush();
Response.End();
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
0

If the byte array is the binary representation of the PDF file, you should be able to set the correct response content type, and use the function BinaryWrite within the Response object.

Matthew
  • 24,703
  • 9
  • 76
  • 110