Attempting to view pdf file though iframe using jQuery modal popup

13,114

Solution 1

I'm using MVC to output the pdf file, and to open instead of downloading, I used this:

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

For the sake of viewing it inside a dialog I choose to use an iframe inside a div, wich became my dialog:

<div class="dialog" style="display:none; overflow:scroll;">
    <iframe src="mypdf.pdf"></iframe>
</div>
...
$(".dialog").dialog();

Make sure that your dialog div has overflow set to something different than 'auto'. Otherwise it wont display on IE.

Take a look at this link, if you need an example: http://helpdesk.toitl.com/data/p/toitl.com/dv/dialog_with_pdf/

Solution 2

Some example code would be a big help.

I have done this using fancybox which has proved very flexible.

This link may prove useful, too. Populating Iframe with PDF - Using MVC [IE Issue]

Share:
13,114
Sai
Author by

Sai

Updated on June 04, 2022

Comments

  • Sai
    Sai almost 2 years

    I am trying to display a pdf file though iframe using jQuery modal popup, however, it's asking the user to download the file when the page loads instead of the pdf file being embedded inside the iframe when the modal dialog opens up.

    How can I get around this?

  • Sai
    Sai almost 13 years
    While that certainly could be the issue but I don't think that's the case here. Within the same application we have embedded pdf in a full page (not a modal) using iframe.
  • Evan
    Evan almost 13 years
    your probably going to want to convert the pdf like I said. you can just convert it to an image if that works for you.
  • Sai
    Sai almost 13 years
    I don't think the conversion idea will work. This is a gov't project and I can't let another application convert our pdf files without getting an approval. Also, I am not very confident they will approve it. Therefore, I'll just have to find a workaround.