Monday, July 20, 2009

Displaying a PDF within CFDIV

I saw a curious question on the adobe forums about displaying a pdf inside a cfdiv tag. When you do this, the pdf is not rendered and instead you just see the bytes of file. I believe this happens because a cfdiv is not a separate window. So you are essentially trying to change the headers mid-stream, which does not work. (I remember there was a good thread on this topic somewhere in the old adobe forums. I am not sure if it is still around.)

Now I do not know if there is a better method, but what does seem to work is embedding the pdf with either <object> or <embed>, depending on your needs. Though not highly tested, it worked for me with Safari, Internet Explorer 8 and FF 3.5. (Naturally this assumes the user's browser is configured to actually display pdf's ;).

<!--- MAIN PAGE --->
<h1>PDF within CFDiv</h1>
<cfdiv bind="url:viewer.cfm" />

<!--- VIEWER PAGE --->
<object type="application/pdf" data="myFile1.pdf" width="400" height="300">


  © Blogger templates The Professional Template by 2008

Header image adapted from atomicjeep