PDA

View Full Version : Converting Word document to HTML with ASP


yokelrobin
11-15-2002, 03:04 PM
Hi people :)

I'm designing a site with ASP that will run off an in-house server (it's essentially a very basic intranet demo), and I need to convert the Word documents into HTML, so they display as a web page, rather than as a Word document.

Any ideas?

Thanks

whammy
11-17-2002, 12:59 AM
Hmm, you can just save them as .html from Word (and then what I do is view the source, and save that under another name, so I can safely delete all the garbage files that are produced that way).

However that's gonna give you some pretty ugly code. But it works.

dominicall
11-17-2002, 09:34 AM
A couple of other options are:

[list=1]
If you are using Dreamweaver you can save the Word doc as an html file from Word then load it into Dreamweaver. It has a nice 'Clean up Word HTML' function that tidies up the rubbish that M$ consider to be good HTML when saving a Word doc as html.
Alternatively, the better option is to convert the Word docs to Acrobat (pdf) files. That way they will be platform and browser independent. So long as the user has a pdf file reader (which just about everyone will have whichever OS/platform they're using) then they will be able to view the documents. This would be the much better option.
[/list=1]
The second method is a great way of building a document library for an intranet - have done it a number of times myself.

Dominic :D

Roelf
11-17-2002, 01:15 PM
I think he knows the save as html option in word. I think he wants to convert documents on the fly, automated. Maybe if Word is installed on the server, you can use the activeX word.application object. you can then open a document, save as html and close the word instance again. You can do this programatically in an asp file.get the name of the document, open, save as html with a predefined nam, and redirect to that html file. I can give you some code to play with tomorrow, if no one else has beaten me to it.

whammy
11-17-2002, 01:58 PM
That sounds cool, Roelf. Hey, you don't know of any cool ActiveX for printing labels directly from an Access (or better yet, SQL Server) db, do ya? ;)

yokelrobin
11-17-2002, 05:54 PM
Thanks for all the replies.

Roelf - that's exactly the sort of thing I'm looking for.

I'm presenting the demo to the client tomorrow (Monday) so that I can make adjustments in time for the proper presentation on Tuesday, so anything you can suggest along the lines you've mentioned would be fantastic.

Thanks again.

Roelf
11-17-2002, 07:11 PM
This function should do something, it is written for client side processing, so you may have to change the new activeXObject part a bit, like: Server.CreateObject("Word.Application") or so. I dont have a server here at the moment so i cannot test it for you. Then if the object is created, play around with the vba-code and -documentation to get the desired results.

As i said, tomorrow morning (7.00 am, dutch time, so one hour ahead at UK) i can do something more for you

<script language="Javascript">
function openword(documentname) {
var wrdApp = new ActiveXObject("Word.Application");
wrdApp.Visible = true;
var wrdDoc = wrdApp.documents.open(documentname);
}
</script>

Roelf
11-18-2002, 08:12 AM
Here is something to experiment with:


Include this function in a file like: openworddocument.asp
add the filename of the file to open as a querystringparameter: openworddocument.asp?File=thefiletoconvert.doc

in the asp file get the filename with:
var indocument = Request.Querystring("File");

call the function:

saveashtml(indocument, "thenameofthehtmlfile.html")

Response.Redirect("thenameofthehtmlfile.html");


<script language="Javascript" runat="server">
function saveashtml(indocumentname, outdocumentname) {
var wrdApp = Server.CreateObject("Word.Application");
var wrdDoc = wrdApp.Documents.Open(documentname);
wrdDoc.SaveAs(outdocumentname, 8); // 8 represents the html fileformat
wrdDoc.Close(0);
wrdApp.Quit();
}
</script>


make sure buffering is on, otherwise the redirect function will not work

play a little with the location of the files and the filenames to pass to the function. It should work if all the files are in the same folder

Roelf
11-18-2002, 09:37 AM
One little thing in above post is about user settings. the word instance which is created, can only function if MSword is started once within this account, so you have to log in as the anonymous internet user once and then start MSword, or you have to adjust the settings for this website in IIS, so the directory security settings are set so the user used for anonymous access has to be a known user on the server which has also started MSword once. Maybe this will give some security issues, but the automatic conversion of a worddocument on the server works fine with the above function.

Greets,
Roelf

yokelrobin
11-18-2002, 03:38 PM
That's great - thanks for your help.

Did the presentation today, and explained what we will be able to do - they were most happy. Should hear later this week if it's all going to go ahead, but I'll probably use it for something else anyway :)

Will report back with any glitches, bugs etc - not that I'm saying anything about your code ;)

Thanks again.

Roelf
11-18-2002, 04:35 PM
i've got it working perfectly on my machine special attention to the (determination of the) location of the files is neccesary, but with all the right settings, it works. Post a message or contact me on msn if you have any problems with it

Roelf
11-21-2002, 11:41 AM
Did you get it working??

yokelrobin
11-21-2002, 11:58 AM
I've had someone start work for me this week, so it's been a little hectic this week as you can imagine :)

I'll see what I can do probably over the weekend and let you know, all being well.

Cheers :thumbsup: