Tech Off Thread

28 posts

ASPX page to stream a PDF

Back to Forum: Tech Off
  • User profile image
    Red5

    Harlequin wrote:
    
    Red5 wrote:
    MyFileStream.Read(Buffer, 0, CInt(FileSize - 1))


    Try this for your Read:
    MyFileStream.Read(Buffer, 0, 65536)


    Sorry, that has no effect.  I tried it just in case you were seeing something I did not.

    A PDF larger than 65,536 bytes would only be partially loaded.  It is not uncommon to have PDF larger than this in our application.

    I would also need to adjust the prevous line that creates the size of the Buffer() byte variable.

    Why did you pick 65,536 when Int.MaxValue is considerably larger?

  • User profile image
    zee01pk

    Hello friends,
                      iam also going through similar kind of problem
    When i try to open a pdf file in IE, it just appears blank
    while in Firefox pdf file open successfully

    I want to know why its not opening with IE.

    Here is my code

    Response.AddHeader("Content-Disposition", "inline;filename=File.pdf");

    Response.ContentType = "application/pdf";

    Response.WriteFile(@"c:/pb-1.pdf");

     Note : If i use 

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

    it opens the pdf file not inside IE but in Acrobat reader

    iam using IE 6.0.2900 SP2 and WinXP SP2 and Acrobat reader 6

  • User profile image
    Matthew van Eerde

    What if you don't put any Content-Disposition header at all?

  • User profile image
    zman13

    I had a similar problem this week where pdf's would  no longer render after the latest Microsoft security update was installed. People @ work who had not applied the patch did not have the problem, but a co-workwer of mine who did apply it had the same problem (although it worked fine for us in firefox).
    The newsest fix may have been trying to address this issue acrobat found recently:

    http://www.networkcomputing.com/channels/security/showArticle.jhtml?articleID=196601020

    suffice it to say installing Acrobat reader 8 fixed my issue (and my coworkers too)

  • User profile image
    Red5

    Matthew van Eerde wrote:
    What if you don't put any Content-Disposition header at all?


    Removing this causes the page that did work to fail.

    zman13 wrote:
    I had a similar problem this week where pdf's would  no longer render after the latest Microsoft security update was installed. People @ work who had not applied the patch did not have the problem, but a co-workwer of mine who did apply it had the same problem (although it worked fine for us in firefox).
    The newsest fix may have been trying to address this issue acrobat found recently:

    http://www.networkcomputing.com/channels/security/showArticle.jhtml?articleID=196601020

    suffice it to say installing Acrobat reader 8 fixed my issue (and my coworkers too)



    That just might explain a few things.  On my other box, which is identical, I have Adobe 8.0 with no problems when attaching to the website that has this code.
    We've been waiting to upgrade our company's Adobe Reader software for awhile now. 
    I might make the push to do this sooner than later.

  • User profile image
    zee01pk

    yes in Acrobat Reader 8 the problem is solved.. but in my case it must work on all versions of Reader as  my application will be used by several users from their home..

    Beside restricting them to download latest version of Acrobat Reader 8.. is there any other way to solve the problem????

  • User profile image
    kriskdf

    In your second page, do you write anything to the response before trying to write the PDF?  It is possible that part of the response gets to the client before you call the ClearContent, etc and this may screw up how the client interprets the results (for example, it gets a header with a text content type or something).  For example, if you do a response.write(""); I'm pretty certain you can't do a response.redirect() and expect it to work.

    You could also try to comment out everything except your conditional statement and the code that writes out the pdf (or comment out everything except the code that writes the pdf).  Slowly add code back in until it stops working and you have your problem area.

  • User profile image
    Red5

    kriskdf wrote:
    In your second page, do you write anything to the response before trying to write the PDF?  It is possible that part of the response gets to the client before you call the ClearContent, etc and this may screw up how the client interprets the results (for example, it gets a header with a text content type or something).  For example, if you do a response.write(""); I'm pretty certain you can't do a response.redirect() and expect it to work..

    Negative. I do not write anything to the response.   No Response.Redirect anywhere.  The user lands at these pages via a standard html  a href= anchor.

    kriskdf wrote:
    You could also try to comment out everything except your conditional statement and the code that writes out the pdf (or comment out everything except the code that writes the pdf).  Slowly add code back in until it stops working and you have your problem area.

    I've tried every variation you suggested and a few more.
    It is a lot less painful and less expensive to just have the users download Reader 7.0 or 8.0.  I guess 8.0 might be the only availble version from Adobe now.  I can get away with this considering my user base, but your results may vary.

  • User profile image
    Red5

    A useful link as long as we're on this topic:

    http://tiberi.us/view_article.aspx?article_id=31

  • User profile image
    ei99070

    I don't know if anyone has found a solution for this, but I'm using the following:

    Response.AppendHeader("Accept-Ranges", "none")

    This has solved the PDF streaming problem for me!!!

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.