Displaying a PDF file

Displaying a PDF file

am 14.09.2006 14:33:45 von Ron Piggott

--=-XSk8Ey/vsTyKTy7IJVHO
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

I am creating a submit button on the fly. The purpose of this is to
open up a new browser window and then display the contents of a PDF
file.

The code for this button reads:


onclick="window.open('index.php?request=view_prayer_ministry _document&document_reference=1','prayer_ministry_document_vi ewer','width=800,height=600,toolbars=no,resizable=yes,scroll bars=yes');">

The window name is prayer_ministry_document_viewer
I am trying to access document_reference 1 which is in a mySQL table.

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM prayer_ministry_documents WHERE reference = '$document_reference'";
$document_result=mysql_query($query);
mysql_close();

$document_file_name = mysql_result($document_result,0,"document_file_name");

#now here I start to get the contents of the PDF file to display

$lineArray = file($document_file_name);

// make an empty variable first
$document_contents_to_display = "";

// concat all array element
foreach($lineArray as $eachLine) {
$eachLine = wordwrap($eachLine);
$document_contents_to_display .= $eachLine;
}

#when I try to display it the PDF it displays it as text with the various ASCII characters ---
#what I am doing wrong / what is the correct way to do this
#I know I could simply specify the file name / path following the window.open ... but I am trying to see if I am able to accomplish the same results this way.

echo $document_contents_to_display;

?>



Ron

--=-XSk8Ey/vsTyKTy7IJVHO--

RE: Displaying a PDF file

am 14.09.2006 15:31:19 von Bastien Koert

I think you need to add a content-type of application/pdf to the code to
tell the browser that its a pdf coming down

// We'll be outputting a PDF
header('Content-type: application/pdf');


Bastien


>From: "Ron Piggott (PHP)"
>Reply-To: ron.php@actsministries.org
>To: PHP DB
>Subject: [PHP-DB] Displaying a PDF file
>Date: Thu, 14 Sep 2006 08:33:45 -0400
>
>I am creating a submit button on the fly. The purpose of this is to
>open up a new browser window and then display the contents of a PDF
>file.
>
>The code for this button reads:
>
> >
>onclick="window.open('index.php?request=view_prayer_ministr y_document&document_reference=1','prayer_ministry_document_v iewer','width=800,height=600,toolbars=no,resizable=yes,scrol lbars=yes');">
>
>The window name is prayer_ministry_document_viewer
>I am trying to access document_reference 1 which is in a mySQL table.
>
>mysql_connect(localhost,$username,$password);
>@mysql_select_db($database) or die( "Unable to select database");
>$query="SELECT * FROM prayer_ministry_documents WHERE reference =
>'$document_reference'";
>$document_result=mysql_query($query);
>mysql_close();
>
>$document_file_name =
>mysql_result($document_result,0,"document_file_name");
>
>#now here I start to get the contents of the PDF file to display
>
>$lineArray = file($document_file_name);
>
>// make an empty variable first
>$document_contents_to_display = "";
>
>// concat all array element
>foreach($lineArray as $eachLine) {
>$eachLine = wordwrap($eachLine);
>$document_contents_to_display .= $eachLine;
>}
>
>#when I try to display it the PDF it displays it as text with the various
>ASCII characters ---
>#what I am doing wrong / what is the correct way to do this
>#I know I could simply specify the file name / path following the
>window.open ... but I am trying to see if I am able to accomplish the same
>results this way.
>
>echo $document_contents_to_display;
>
>?>
>
>
>
>Ron

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Displaying a PDF file

am 14.09.2006 18:20:44 von Miles Thompson

At 09:33 AM 9/14/2006, Ron Piggott (PHP) wrote:

>I am creating a submit button on the fly. The purpose of this is to
>open up a new browser window and then display the contents of a PDF
>file.
>
>The code for this button reads:
>
> >
>onclick="window.open('index.php?request=view_prayer_ministr y_document&document_reference=1','prayer_ministry_document_v iewer','width=800,height=600,toolbars=no,resizable=yes,scrol lbars=yes');">
>
>The window name is prayer_ministry_document_viewer
>I am trying to access document_reference 1 which is in a mySQL table.
>
>mysql_connect(localhost,$username,$password);
>@mysql_select_db($database) or die( "Unable to select database");
>$query="SELECT * FROM prayer_ministry_documents WHERE reference =
>'$document_reference'";
>$document_result=mysql_query($query);
>mysql_close();
>
>$document_file_name = mysql_result($document_result,0,"document_file_name");
>
>#now here I start to get the contents of the PDF file to display
>
>$lineArray = file($document_file_name);
>
>// make an empty variable first
>$document_contents_to_display = "";
>
>// concat all array element
>foreach($lineArray as $eachLine) {
>$eachLine = wordwrap($eachLine);
>$document_contents_to_display .= $eachLine;
>}
>
>#when I try to display it the PDF it displays it as text with the various
>ASCII characters ---
>#what I am doing wrong / what is the correct way to do this
>#I know I could simply specify the file name / path following the
>window.open ... but I am trying to see if I am able to accomplish the same
>results this way.
>
>echo $document_contents_to_display;
>
>?>
>
>
>
>Ron


So Ron, why not just ...

as the action triggered on the button.

(Unless you're storing the .pdf in the database.)

Miles


--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.12.3/447 - Release Date: 9/13/2006

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php