Jump to content

embed pdf in page but need html to be on the page also


accend

Recommended Posts

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 by accend
Link to comment
Share on other sites

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 by accend
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.