accend Posted May 27, 2014 Author Share Posted May 27, 2014 (edited) I'll go back through the threads again and see what has happened. It did work though when I put the pdf on the root level and pulled it in directly by hardcoding the path into the object. Very strange, but will go through it all again and see if anything i have done is wrong. The trouble is its pretty simple. <?php session_start(); require_once('../auth.php'); include "../config.php"; error_reporting(E_ALL); ini_set('display_errors','On'); if(isset($_GET['pdf'])) { $stock_Id=$_GET['pdf']; $a=mysql_query("select Document from Documents where ID=$stock_Id") or die (mysql_error()); while($s=mysql_fetch_assoc($a)){ $cdocdocb=$s["Document"]; } } $file = "$cdocdocb"; header('Content-type: application/pdf'); header('Content-Disposition: inline; filename="$file"'); $filename=file_get_contents($file); $code=<<<heredocs <!DOCTYPE html> <html> <head> <title>pdf in a page</title> <style type='text/css'> #pdf { position:relative; float:left; width: 300px; height: 300px; margin: 1%; // border: 2px solid red; } #pdf p { padding: 10px; } #pdf object { display: block; border: solid 3px red; } </style> </head> <body> <!-- begin DIV to hold the PDF --> <!-- begin DIV to hold the PDF --> <!-- begin DIV to hold the PDF --> <center> Version 5 <form method='POST'> Click here to close this and go back <input type='submit' name='btn' value='Return'> </form> </center> <br><br> <div id="pdf"> heredocs; echo $code; echo "<object data='" .$filename . "#scrollbar=1' type='application/pdf' width='100%' height='100%'><p>It appears you don't have a PDF plugin for this browser. No biggie... you can <a href='$filename'>click here to download the PDF file.</a></p></object>"; //toolbar=1&navpanes=0& echo "</div></body></html>"; exit(); Edited May 27, 2014 by accend Quote Link to comment https://forums.phpfreaks.com/topic/288647-embed-pdf-in-page-but-need-html-to-be-on-the-page-also/page/2/#findComment-1480999 Share on other sites More sharing options...
accend Posted May 27, 2014 Author Share Posted May 27, 2014 (edited) If I comment the headers out, I see the html fine, red border around the div etc but nothing loads inside it, except for a load of code associated with the actual pdf, so the header translates it, and its def needed. Put the headers back, pdf takes over the full page and the object has no effect on it what so ever, the headers take over to display the pdf in full. I'm sorry this is still going on... Edited May 27, 2014 by accend Quote Link to comment https://forums.phpfreaks.com/topic/288647-embed-pdf-in-page-but-need-html-to-be-on-the-page-also/page/2/#findComment-1481000 Share on other sites More sharing options...
ginerjm Posted May 27, 2014 Share Posted May 27, 2014 1 - you need to use something other than the MySQL_* functions since they are deprecated. 2 - you need to either use the newer database functions that support prepared queries or sanitize your input filename before using in your query. 3 - why do you use $filename when you already have a perfectly good variable in $cdocdocb? 4 - if you put out a header that says the upcoming output is a pdf, why would you expect html to be recognized? 5 - if you are seeing the html but no pdf, then I suspect that the filename is either invalid or unreachable. View the source of your page as it is being displayed and show us the line where the img tag is. You do realize that you CANNOT reference a file that is outside of your web tree in html? Quote Link to comment https://forums.phpfreaks.com/topic/288647-embed-pdf-in-page-but-need-html-to-be-on-the-page-also/page/2/#findComment-1481010 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.