1

I want to create a pdf file from Binary data. I looked around and found examples using iTextSharp by fetching data from the database.

But almost all of them show how to display in the browser. I want to create a file like pdffromDB.pdf instead of displaying as shown below

doc.Close();
Response.BinaryWrite(MemStream.GetBuffer());
Response.End();
MemStream.Close();

I would really appreciate if you can direct me to an example that will allow me to create a real pdf file.

Thanks

1 Answer 1

1

Assuming your MemStream already contains all the bytes making up a valid PDF file, you should be able to convince the visitor's browser to prompt to save it as a file by adding the following statement before Response.BinaryWrite:

Response.AddHeader("Content-Disposition", "attachment; filename=Whatever.pdf")

As an aside, code after Response.End generally isn't executed: your MemStream will still be closed and disposed of just fine in this case due to going out of scope, but in general you should treat Response.End the same as Exit Sub, and code accordingly, e.g.

Using ms As New IO.MemoryStream
    ...
    Response.End()
End Using
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.