Docclient.pm
Client module for remote MS format conversions
Synopsis
my $docclient = new Docclient( 'host' => 'machine.domain.cz', 'port' => 6745, ) or die $Docclient::errstr; my $filename = 'word.doc'; open FILE, $filename or die "Error reading $filename: $!\n"; binmode FILE; $docclient->put_file(*FILE); close FILE; $docclient->convert('doc', 'txt') or die $docclient->errstr; my $text = $docclient->get_to_scalar; $docclient->finished;
Description
Docclient is a client part of a tool that makes it easy to send a Word or Excel document to a Win* machine, open the module with a native application and convert it using that proprietary software to readable form, then deliver the converted document back to the client machine. On the server machine, a Docserver application (usually docserver.pl program) has to be running.
From the comment line, you probably want to use the docclient.pl script, but in case you want to write your own conversion tool or want to use this inside of a bigger application, here's how:
Methods
- new
-
First you create new Docclient object. You tell it what server machine and port to use and it tries to connect to the server. Parameters are passed as hash and are host for the server machine name and port for TCP port the server is running on. The dafault is stored in Docclient/Config.pm file, so you can have site-wide defaults and only specify these parameters when you have to achieve something special.
If the new method fails (usually becaue it was not able to connect to the server), it returns undef and the error message is stored in the $Docclient::errstr string.
After you've got your Docclient object, you can call methods on it. You need to send your input document to the server, then run a conversion or series of conversions and then retrieve the result back from server.
- put_scalar
-
If you've got the doc document in a perl scalar (because you've read it from the CGI upload or so), you can call put_scalar with one parameter being the document, and this method sends the document to the server. If there is a error during the tramsmit, it can be retrieved via $docclient->errstr method.
- put_file
-
If you have the file on the disk (not read to perl scalar yet, just a filehandle), you can use put_file with the filehandle as an argument. It sends the data to the server just as put_scalar would.
- convert
-
When you've got the input data on the server, you want to call convert which will actually initiate the conversion on the server machine. The convert method accepts two parameters, input_format and output_format. You need to tell the convertor what format you think the file is in and in what format you expect it back.
Possible values for input_format are doc, xls or csv, for output_format you can use txt, rft, doc6, doc95, html, ps and ps1 for Word documents and txt, csv, prn, xls5, xls95, html, ps and ps1 for Excel documents. Please note that availability of individual formats depends on the versions of the MS software on the server. For example, if you have old versions, they may not support the formats, or if you don't have PostScript printer driver installed, you won't be able to produce PostScript output.
Upon error, convert returns false and error message can be fetched using $docclient->errstr method.
- get_to_scalar
-
After the conversion was successfully finished, you retrieve the result to a scalar by calling get_to_scalar method (without any parameters).
- get_to_file
-
You may prefer to directly send the result to output file, use get_to_file with a filehandle parameter.
- finished
-
After you've done with the file, call finished to clean after yourself on the server side.
After you've sent the file to the server (using put_file or put_scalar methods), you can call convert (and subsequent get_to_* methods) with various parameters many times to get different output formats for single file. Method finished deletes the temporary file on the server.
Version
This documentation is believed to describe reasonably accurately version 1.0 of Docclient.
Author
(c) 1998--2002 Jan Pazdziora, jpx (dash) perl (at) adelton (dot) com, http://www.adelton.com/perl/
All rights reserved. This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See also
docclient(1), docserver(1), Docserver(3), Win32::OLE(3), Win32::API(3)