简体   繁体   中英

Display PDF - Application Page SharePoint

I am working on a Custom WebPart, for which I need an application page to render a PDF file.

I am currently using following link http://support.microsoft.com/kb/306654

It works fine in ASP.NET, but gives a blank page in SharePoint.

Here's the code: (PDF file is in same directory)

        Response.ClearContent();
        Response.ClearHeaders();
        //Set the appropriate ContentType.
        Response.ContentType = "Application/pdf";
        //Get the physical path to the file.
        string FilePath = MapPath("Test.pdf");
        //Write the file directly to the HTTP content output stream.
        Response.WriteFile(FilePath);
        Response.Flush();
        Response.End();

Working on it for last few hrs, making me crazy...any ideas?

A few ideas:

  1. If the file is in the SharePoint directories, why not just redirect to a URL for it?

  2. If you use Fiddler (or Firebug) to look at the HTTP traffic -- do you see the content-type change? What is the content (is it a PDF?)

  3. The main differences between SharePoint and ASP.NET (assuming that you are getting to the file correctly) is that the page life-cycle is slightly different and the security model. You might want to look at how Reponse.End() works to make sure it isn't different in SharePoint. You can run SharePoint in verbose logging and then use .NET Reflector on the SharePoint dlls (with the logs as a guide) to see if there's some weird way of handling this. The SharePoint dlls have pretty liberal log calls. More info here: http://www.andrewconnell.com/blog/archive/2008/06/11/SharePoint-Debugging-and-Logging-Tips-and-Tricks.aspx

  4. Have you considered rasterizing the PDF and just showing it inline in the page? This is what we do in a project my company is working on to view PDF and other documents in SharePoint ( Vizit ). You still have to solve your problem of reading the file, but instead of responding with the PDF, you respond with a PNG and request inside of an <img> tag.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM