Welcome Guest Search | Active Topics | Sign In | Register

Sending PDF to client for download Options
Ross
Posted: Tuesday, April 30, 2013 4:53:40 PM
Rank: Newbie
Groups: Member

Joined: 5/13/2011
Posts: 3
I am trying to send a rendered PDF to the client using the below:

Code: Visual Basic.NET
Response.Clear()
        Response.ContentType = "application/pdf"
        Response.AddHeader("content-disposition", "attachment; filename=test.pdf")
        pdoc.Save(Response.OutputStream)
        Response.End()

I have also tried saving to a memory stream and sending with no luck.

If I use the same code to create the PDF but instead save to file it works fine.
Code: Visual Basic.NET
pdoc.Save(Request.PhysicalApplicationPath + "\pdf\test.pdf")


I have no issue sending XLSX or DOCX files to the client from this same page.

Any help would be appreciated.
eo_support
Posted: Tuesday, April 30, 2013 6:51:19 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

Your code looks fine. I do not see any problems with that. From our product point of view, if you can save into a physical file and it works fine, then the product is working correctly.

Thanks!
Zachary Yates
Posted: Thursday, October 24, 2013 1:01:40 PM
Rank: Newbie
Groups: Member

Joined: 10/24/2013
Posts: 1
Hi Ross,

You may have solved your problem by now, but in case others need help, you need to flush the output stream and seek it back to the beginning. Here's an example:

Code: Visual Basic.NET
Response.Clear()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment; filename=test.pdf")
pdoc.Save(Response.OutputStream)

Response.OutputStream.Flush()
Response.OutputStream.Seek(0, SeekOrigin.Begin)

Response.End()


I didn't test that code, but that's the general idea. Hope that helps!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.