Solved

Can't call method "Documents" on unblessed reference

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Studying Angular for employability 5 86
AutoHotkey ActiveX Component Error 8 85
How does Redux fit into React? 3 79
read an xml file in perl 2 30
This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

786 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