views:

399

answers:

3

I have an ASP.NET web application.I have some PDF files in my server .I want to show those to the user via browser in a new window.how to embed PDF in a browser ? i want the save option to be available for the user to save the PDF .How to go ahead

+1  A: 

take a look at

http://pdfobject.com/

<html> 
<head> 
<script type="text/javascript" src="/scripts/pdfobject.js"></script> 
<script type="text/javascript"> 

window.onload = function (){

var success = new PDFObject({ url: "/pdf/sample.pdf" }).embed("pdf");

};

</script> 
</head> 

    <body> 

    <div id="pdf">It appears you don't have Adobe Reader 
    or PDF support in this web browser.
    <a href="/pdf/sample.pdf">Click here to download the PDF</a></div> 

    </body> 

</html>
Josh
A: 

PDF files opened in the browser can be susceptible to XSS, so it is usually best to configure the server so that, when a user requests a PDF, it is opened in it's native application e.g. Adobe Reader.

To configure IIS, open up IIS Manager and:

  1. Right-click the folder on your site where the PDF files are kept and select 'Properties'
  2. Go the the HTTP Headers tab
  3. Click the 'File Types' button under the MIME Map section
  4. Click 'New Type'
  5. Add '.pdf' as the extension and 'appliction/octet-stream' as the Content Type
  6. Click Ok and apply the changes

Now when the user clicks a link to a PDF they should be promted with the 'Open or Save' dialog box that you are after.

Ian Oxley
A: 

I've faced the same problem and a guy from Adobe has an (old) blog post about it link text

It works fine with IE, FF, Chrome with the default Adobe Reader plugin.

Now my only issue left is to display a nice loading thingy while the plugin retrieves the PDF file that is generated on-the-fly.

R4cOON