Page 1 of 1

Displaying a Microsoft Word Document in a web page.

Posted: Sun Sep 26, 2010 12:20 am
by JackD
I can get the Microsoft Word document to display on our web page, but it does not display cleanly and has all the formatting characters scattered across the screen. Is there a way to filter the document so the formating is applied and the document appears cleanly? If not, is there a way to do that with a PDF file? Here is the code we are using:

Code: Select all

<html>
<head>
<title>Open Document</title>
</head>
<body>
<DIV align="CENTER">
<?php
$Text='';
$Article=trim($_GET['file']);
if($Article != '') 
  { $Text=file_get_contents($Article);
    echo $Text;    
  } 
echo '<table BORDER="1" CELLSPACING="1" CELLPADDING="1" WIDTH="100%"><tr>';
echo '<TD WIDTH="10%" ALIGN="left" VALIGN="TOP">';
echo '<a href="doc.php?file=C:\myfiles\Cancer Part 2.doc" target=docwindow>Cancer Part 2</A><br>';
echo '<a href="doc.php?file=C:\myfiles\Cancer Part 2.doc" target=docwindow>Cancer Part 2</A><br>';
echo '<a href="doc.php?file=C:\myfiles\Cancer Part 3.doc" target=docwindow>Cancer Part 3</A>';
echo '<TD WIDTH="75%" ALIGN="CENTER" VALIGN="TOP">';
echo '<iframe name="docwindow" frameborder=6 width=800 height=600></iframe>';
echo '</CENTER></TD></TR></TABLE>';

?>
</DIV>
</body>
</html>

Re: Displaying a Microsoft Word Document in a web page.

Posted: Sun Sep 26, 2010 1:58 am
by requinix
If they're actual .doc files and not HTML with the wrong extension then you need to display the file contents and only the file contents. No extra HTML.

Code: Select all

<?php

if (the script should show a file) {
    header("Content-Type: application/msword");
    show file contents here
    exit;
}

show the HTML to let the user choose a file

?>

Re: Displaying a Microsoft Word Document in a web page.

Posted: Sun Sep 26, 2010 1:35 pm
by John Cartwright
tasairis wrote:If they're actual .doc files and not HTML with the wrong extension then you need to display the file contents and only the file contents. No extra HTML.

Code: Select all

<?php

if (the script should show a file) {
    header("Content-Type: application/msword");
    show file contents here
    exit;
}

show the HTML to let the user choose a file

?>
Which would only work if the enduser has Microsoft Word installed on his computer. If you want a universal solution, your best bet would be to convert your word documents to HTML format (Word can do this) and provide the original document for download.

Re: Displaying a Microsoft Word Document in a web page.

Posted: Sun Sep 26, 2010 8:33 pm
by JackD
The documents are actually Word .doc documents. Somewhere I had read that IE and Firefox knew how to correctly display such documents. I was just looking for the mechanism. If I have to convert them all of the time, why use Word? The browsers gripe when there are two consecutive blanks, periods, etc. in a sentence, or when you use an apostrope or quotes.

Re: Displaying a Microsoft Word Document in a web page.

Posted: Sun Sep 26, 2010 10:43 pm
by requinix
JackD wrote:Somewhere I had read that IE and Firefox knew how to correctly display such documents.
They only know if, as John said, the user has Word (or an appropriate viewer) installed on their machine. No browser comes with built-in support for it.

Re: Displaying a Microsoft Word Document in a web page.

Posted: Tue Jun 14, 2016 1:26 am
by Shellyyin
How about using a plugin? You can try Aceoffix. It can call the local MS Word to open in the web browsers.