Is it really not possible to display a remote PDF in an iframe?
Results 1 to 6 of 6

Thread: Is it really not possible to display a remote PDF in an iframe?

  1. #1
    Senior Member
    Join Date
    Apr 2003
    Location
    Silver Lake
    Posts
    4,874

    Is it really not possible to display a remote PDF in an iframe?

    I have a mind-numbingly dull task that I'm trying to speed up by writing some PHP scripts that run on my localhost, fetch remote web pages, and distill certain info. Part of the process that I'm trying to expedite is to show some data extracted from an article abstract along with a PDF of the article. My script fetches the html from the abstract, looks for the values I'm after and shows them to me and I'd like to go ahead and show the PDF in a frame or iframe. It may sound trivial to click one more <a> link to open the PDF, but if I could save that one click, it will result in a great deal of time saved over the life of this project.

    The problem I have is that firefox blocks any attempt to show a remote PDF in an iframe. I've tried setting it as the iframe src attribute, i've tried loading it via Javascript either on page load or in response to user clicks, I've tried a meta redirect and nothing seems to work. Firefox always says:
    Quote Originally Posted by firefox
    Blocked loading mixed active content "http://example.com/path/to/remote/file.pdf"
    Line 0
    Is there no way to display both my distilled information and the pdf in a single window?
    IMPORTANT: STOP using the mysql extension. Use mysqli or pdo instead.
    World War One happened 100 years ago. Visit Old Grey Horror for the agony and irony.

  2. #2
    Senior Member
    Join Date
    Jul 2007
    Posts
    3,657
    You should be using
    HTML Code:
    <object type="application/pdf" data="url"></object>
    Possibly specifying width and height too since those will default to small values.

  3. #3
    Senior Member
    Join Date
    Apr 2003
    Location
    Silver Lake
    Posts
    4,874
    Thanks for your suggestion, but I tried this:
    HTML Code:
    <object type="application/pdf" data="http://example.com/pdf?res=blahblahblah" style="width:100%; height:800px;"></object>
    and it doesn't even result in a request to the remote site or a "blocked content" message.
    IMPORTANT: STOP using the mysql extension. Use mysqli or pdo instead.
    World War One happened 100 years ago. Visit Old Grey Horror for the agony and irony.

  4. #4
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,429
    Do you have this live somewhere we could view? Also, which browser are you using?

    You might have to include an <embed> tag inside the <object> for maximum browser compatibility. However, using Chrome, the <object>-only approach above appears to work just fine for me.

  5. #5
    Senior Member
    Join Date
    Jul 2007
    Posts
    3,657
    Did you also inspect the actual requests involved from your browser? Object works in both Chrome and FF. It does of course still require the browser to have capabilities for displaying pdfs. Else you'd need fallback content or nothing will show.

  6. #6
    Senior Member
    Join Date
    Apr 2003
    Location
    Silver Lake
    Posts
    4,874
    I'm using firefox on an Ubuntu workstation. I did inspect (using firebug) the requests sent and there appears to be only the request for the page itself -- the <object> tag doesn't result in any request at all. I've had no problem displaying these PDFs when accessing them directly in firefox.

    After some tinkering, I have isolated the problem. The page in which I want to show this pdf is hosted via HTTPS and the pdf link is not. It works fine when page is not hosted via HTTPS. In retrospect, this is not surprising that the browser would be annoying about HTTPS hosted pages. Kind of a relief actually.
    IMPORTANT: STOP using the mysql extension. Use mysqli or pdo instead.
    World War One happened 100 years ago. Visit Old Grey Horror for the agony and irony.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •