Solved

Can't call method "Documents" on unblessed reference

Posted on 2008-10-21
5
1,214 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now