Solved

Can't call method "Documents" on unblessed reference

Posted on 2008-10-21
5
1,220 Views
Last Modified: 2013-12-25
Hi,

I have a cgi script that I run on two web servers that uses Word OLE to open up a word doc, convert it to rtf and then we run some Omnimark on it.

It runs fine via the browser on these two web servers.

I have just tried to run this on our 3rd disaster recovery server and it gives me the following error:

[Tue Oct 21 15:29:57 2008] [error] [client 217.154.147.226] Can't call method "Documents" on unblessed reference at D:/Program Files/Apache Group/Apache2/cgi-bin/upload/ole.cgi line 41, <DATA> line 164.\r


Line 41 is:

$WORD->Documents->Open($filein) or print  "WARNING: Unable to open document " . Win32::OLE->LastError();

Now. If I run this script via the command line it works, but if I run it via a browser it doesn't. AS I said, on the other two servers it runs fine either via command line or the browser and I have run out of ideas!

I have stripped the script down to the bare basics for testing:
#!D:\Perl\bin\perl.exe
 
use strict;
use warnings;
 
use Win32::FileOp;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Word';
 
sub ConvertToRTF;
sub CheckOLE;
 
my $filein;
my $fileout;
my $WORD;
 
 
ConvertToRTF();
 
#-------------------------------------------
sub CheckOLE {
#-------------------------------------------
	if (Win32::OLE->LastError()) {
		print "OLE error !!! \n";
		my $err = Win32::OLE->LastError();
		print $err."\n";
		exit;
	}
}
 
#-------------------------------------------
sub ConvertToRTF {
#-------------------------------------------
 
my $filein = 'D:\\RTFtoXML\\rtf\\Test.doc';
my $fileout = 'D:\\RTFtoXML\\rtf\\Test.rtf';
print "Content-type: text/html \n\n";			# print the http header
	print "The file out is $fileout<br>";
$WORD = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application', 'Quit');
   $WORD->{'Visible'} = 1;         # if you want to see what's going on
	$WORD->Documents->Open($filein) or print  "WARNING: Unable to open document " . Win32::OLE->LastError();
	CheckOLE();
	 $WORD->ActiveDocument->SaveAs({
		FileName	=> $fileout,
		FileFormat	=> wdFormatDocument,     # .doc format
		FileFormat	=> wdFormatRTF,          # .rtf format       
		LockComments=> 0,
		Password 	=>"",
		AddToRecentFiles=> 0,
		EmbedTrueTypeFonts => 0,
		SaveNativePictureFormat => 0,			});
	CheckOLE();
	$WORD->ActiveDocument->Close;
	undef $WORD;
	print "<p>Finished RTF conversion, please wait...<br><br><p>";
 
}

Open in new window

0
Comment
Question by:Hedley Phillips
  • 3
  • 2
5 Comments
 
LVL 39

Assisted Solution

by:Adam314
Adam314 earned 250 total points
ID: 22768407
Is Word installed on this third server?

The problem is here:
    $WORD = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application', 'Quit');
The $WORD is not being set to an object.  You could add this:
    die "Could not create WORD object\n" unless $WORD;

0
 
LVL 14

Author Comment

by:Hedley Phillips
ID: 22768434
Adam,

thanks for your reply.

Word is installed on this server and if I run this script from the command line I see it opening up and then closing and I get an rtf file (I have $WORD->{'Visible'}  set to 1 so it is visible).

It is only when it is run via the browser that it fails saying I haven't been to church.
0
 
LVL 39

Expert Comment

by:Adam314
ID: 22768527
Does the web server user have permission to start word?
Is there anything in your error log?
0
 
LVL 14

Accepted Solution

by:
Hedley Phillips earned 0 total points
ID: 22784624
Fixed it!

I rebooted the server and it works fine.

Don't know why that would stop it running from the browser but allow it on the command line but there we are.

0
 
LVL 39

Expert Comment

by:Adam314
ID: 22787751
The tried and true "reboot" solution... used to be very common, but still has it's place.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question