Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm using iTextSharp for generating a pdf. I can save the PDF file from the PDF byte[].

byte[] outputPDF = cnt.CreateBreakPDF();
File.WriteAllBytes(pdfOutPutPath, outputPDF);

What is the best way to display the output byte[] to a web page?

I've seen answers for MVC, but I'm using ASP.NET Web Application.

Is there a better way than using HTTP handlers to do so? I don't want to send all the details for creating PDF as query string.

share|improve this question

2 Answers

You can try the following code. It does require a file instance - just a byte array representing your pdf:

byte[] outputPDF = cnt.CreateBreakPDF();

Response.Clear();
Response.ContentType = "application/pdf";
Response.BinaryWrite(outputPDF);
Response.Flush();
Response.End();
share|improve this answer

Try this

Response.ContentType = "application/pdf";
Response.AddHeader("content-length", outputPDF.Length.ToString());
Response.BinaryWrite(outputPDF);
share|improve this answer
I want to show the PDF inside a div in my page. Not the PDF as response.. – Sen Jacob 4 hours ago
@SenJacob you have not specified that in your question.Update it so you may get more answers – karthi 2 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.