views:

384

answers:

3

Is there any way I can direct display PDF files in modal boxes?

I am using CodeIgniter PHP framework and jQuery as JavaScript framework.


UPDATE: I read on net that this is possible by loading it in iframe, and Adobe PDF will render it, but many seems to oppose, so is there any way I can convert those PDFs to images?

+3  A: 

Short answer: No.

Longer answer: Usually, PDF documents are not rendered by the browser directly, but rather by some specialized PDF reader. As soon as the browser sees a content type of application/pdf, it passes the response along to the reader. Nothing you would do in your HTTP headers, HTML or JavaScript would make it across the gap between the browser and that other program, and the PDF format itself contains no switch to enable any kind of modal user interface.

Update: Rendering the PDF as an image would allow you to display the graphical content of the document in a more modal fashion. You still are not able to block the user from closing the browser, but you would be able to "lock down" anything else on your page while the image is displayed.

Related: How do I convert a PDF document to a preview image in PHP?

Jørn Schou-Rode
Can I convert it to image for viewing?
Shishant
Yes its for a quick view mostly according to my app usage the pdf wont be needed whole time and image will help quick the user task, and I will provide a link to download the pdf.
Shishant
@Shishant: Yes, you can render your PDF page to images and display those in a sort of modal UI (see my updated answer and the link provided herein).
Jørn Schou-Rode
@rkulla: it does not defeat the purpose of having a PDF. The only way to display a PDF is to render it as an image of some sort. That's exactly what Adobe Reader does.
Rowan
A: 

That's a bad idea. Always let the user set their browser to how they want to handle PDF files. So just create a link to the pdf. Modal windows aren't for that purpose anyway.

rkulla
+1  A: 

If you really want to, you can just embed it as a normal object. For example:

<object type="application/pdf" data="embeddedfile.pdf" width="500" height="650">

Arda Xi