Hi Folks,
I wrote this code about a month ago. It provides a simple C
interface to a remote AbiWord process that is robust and be used
to convert doc,rtf,OOo, wpd,abw and many other formats documents
to *.txt and to make png images of the first page of the
document.
Please let me know how I can make this easier for you guys to use.
(Short of writing a C# patch)
The complete C program and header file is given as an attachment here.
> CVS:*
* The function is fault tolerant and will report if a requested
* file is not capable of being coverted.
*
* It will also restart AbiWord if it does crash on the next invocation
* of convertFileToText.
*
* Inputs: inFile - The path to the word processor file to be converted.
* outFile - The path to the file containing the plain text of the
* word processor file.
* The function blocks until the conversion is complete or until
* the conversion fails.
*
* It returns 0 upon a successful conversion
* and -1 if the conversion fails.
*/
int convertFileToText(const char * inFile, const char * outFile)
{
/*
* The function is fault tolerant and will report if a requested
* file is not capable of being coverted.
*
* It will also restart AbiWord if it does crash on the next invocation
* of convertFileToText.
*
* Inputs: inFile - The path to the word processor file to be converted.
* outFile - The path to the PNG image of the first page of the doc
* iWidth - width in pixels of the document.
* iHeight - height in pixels of the document.
* The function blocks until the conversion is complete or until
* the conversion fails.
*
* It returns 0 upon a successful conversion
* and -1 if the conversion fails.
*/
int convertFileToPNG(const char * inFile, const char * outFile, int
iWidth, int iHeight)
> ----------------------------------------------------------------------
CVS: Enter Log. Lines beginning with `CVS:' are removed automatically
CVS:
> CVS: Committing in .
> CVS:
> CVS: Modified Files:
> CVS: ConvertToText.c ConvertToText.h xp/AbiCommand.cpp
> CVS:
> ----------------------------------------------------------------------
AbiCommand New feature previewpng, ConvertToPNG server implementation.
>
>
> CVS:
> ----------------------------------------------------------------------
CVS: Enter Log. Lines beginning with `CVS:' are removed automatically
CVS:
> CVS: Committing in .
> CVS:
> CVS: Modified Files:
> CVS: src/af/gr/unix/gr_UnixGraphics.cpp
> CVS: src/af/gr/unix/gr_UnixGraphics.h
> CVS: src/af/gr/unix/gr_UnixImage.cpp src/af/gr/unix/gr_UnixImage.h CVS:
> src/wp/ap/unix/ap_UnixApp.cpp src/wp/ap/unix/ap_UnixApp.h
> CVS: src/wp/ap/xp/ap_Preview_Abi.cpp
> CVS:
> ----------------------------------------------------------------------
AbiWord side of previewpng. Particularly note new ap_UnixApp method,
makePngPreview(const char * pszInFile, const char * pszPNGFile,
UT_sint32 iWid\th, UT_sint32 iHeight
>
>
> OK this implements a feature, "previewpng" in AbiCommand plus a
> C-interface to an externally running AbiWord processes in
> ConvertToText.(h,c). The
> C interface is really simple:
>
> /*
> * The function is fault tolerant and will report if a requested * file
is not capable of being coverted.
> *
> * It will also restart AbiWord if it does crash on the next invocation *
> of convertFileToText.
> *
> * Inputs: inFile - The path to the word processor file to be converted. *
> outFile - The path to the PNG image of the first page of the doc
> * iWidth - width in pixels of the document.
> * iHeight - height in pixels of the document.
> * The function blocks until the conversion is complete or until * the
conversion fails.
> *
> * It returns 0 upon a successful conversion
> * and -1 if the conversion fails.
> */
> int convertFileToPNG(const char * inFile, const char * outFile, int
iWidth, int iHeight)
>
>
> This is useful for showing a preview of the document that you've found
and indexed in dashbaord via ConvertToText :-)
>
> To build this you need CVS AbiWord and CVS abiword-plugins
>
> ConvertToText.(h,c) is located in the abiword-plugins/tools/abicommand
directory. It's LGPL'd licensed but feel free to port to C# if you
prefer. The code pretty straight forward.
>
> Right now an entrie document is loaded and all the views are filled in
order to just get a preview of the first page. I'm pretty sure we don't
to do this. If I can work out a way to load just the first bit a
document, previews of huge documents should be the same speed as small
documents.
>
> I'll experiment with algorithims to do this but right now things work
and you can use this code to throw up a preview of a selected Word
Processor docs.
>
> Martin
>
>
--
Andrew Ruthven
Senior Systems Engineer, Actrix Networks Ltd --> www.actrix.gen.nz At
Actrix puck actrix gen nz
At Home: andrew etc gen nz
Attachment:
ConvertToText.c
Description: Binary data
Attachment:
ConvertToText.h
Description: Binary data