f



Help needed in migrating from Windows

The code snippet below prints out a bilingual dictionary of mine into 
MSWord. The dictionary entries are in an XML file that I edit with VIM. The 
Perl script parses the file, processes and sorts the data and puts it in a 
data structure of paragraphs composed of pieces of text with formatting 
instructions (I may add more options in the future). I can also print out 
plain text or html with similar routines. The Word output has the advantage 
of allowing me to add page numbers and insert an introduction etc easily.

I would like to migrate this to Linux (I have XP / SuSE 9.1 dual boot on my 
notebook) but am unsure of which program to replace Word with. OOo does not 
seem to automate as easily. I don't know which line to go down: TeX, PDF, a 
different Word processor? It would be easy to output XML and then use a 
'stylesheet' to get this to output PDF for instance if there was a program 
around to do this step. Any thoughts on what tools I should be considering?

Thanks,

Dave

sub word_print {
 use Win32::OLE;
 Win32::OLE->Option(CP => Win32::OLE::CP_UTF8());
 my $word = CreateObject Win32::OLE 'Word.Application' or die $!;
 $word->{'Visible'} = 1;
 my $document = $word->Documents->Add;
 my $selection = $word->Selection;
 $selection->Font->{Name} = "Gentium";
 my $i = 0;
 foreach my $para (@foutput) {
  $i++; last if $i == 50; # just a few for debugging
  foreach (@{$para}) {
    if (@{$_}[1] eq "") {
     $selection->TypeText(@{$_}[0]);
    }
    elsif (@{$_}[1] eq "b") {
     $selection->Font->{Bold} = 1;
     $selection->TypeText(@{$_}[0]);
     $selection->Font->{Bold} = 0;
    }
    elsif (@{$_}[1] eq "i") {
     $selection->Font->{Italic} = 1;
     $selection->TypeText(@{$_}[0]);
     $selection->Font->{Italic} = 0;
    }
    elsif (@{$_}[1] eq "s") {
     $selection->Font->{Superscript} = 1;
     $selection->TypeText(@{$_}[0]);
     $selection->Font->{Superscript} = 0;
    }
    else {
     die "Unknown formatting: " . @{$_}[1];
    }
   }
   $selection -> TypeParagraph;
  }
  $document->SaveAs("$outfile") or die "Could not save: " . 
Win32::OLE->LastError() . "\n";
  $word->Close;
}


0
6/5/2005 2:52:38 PM
comp.os.linux.misc 33599 articles. 1 followers. amosa69 (78) is leader. Post Follow

6 Replies
436 Views

Similar Articles

[PageSpeed] 54

"Dave" <daveandniki@ntlworld.com> writes:

> The code snippet below prints out a bilingual dictionary of mine into 
> MSWord. The dictionary entries are in an XML file that I edit with VIM. The 
> Perl script parses the file, processes and sorts the data and puts it in a 
> data structure of paragraphs composed of pieces of text with formatting 
> instructions (I may add more options in the future). I can also print out 
> plain text or html with similar routines. The Word output has the advantage 
> of allowing me to add page numbers and insert an introduction etc easily.
>
> I would like to migrate this to Linux (I have XP / SuSE 9.1 dual boot on my 
> notebook) but am unsure of which program to replace Word with. OOo does not 
> seem to automate as easily.

I don't have any experience with this but did you try typing

openoffice perl

into Google?
0
daneNO (319)
6/5/2005 6:27:09 PM
"Dan Espen" <daneNO@SPAM.mk.telcordia.com> wrote in message 
news:icr7fgfyma.fsf@mk.telcordia.com...
> "Dave" <daveandniki@ntlworld.com> writes:
>
>> The code snippet below prints out a bilingual dictionary of mine into
>> MSWord. The dictionary entries are in an XML file that I edit with VIM. 
>> The
>> Perl script parses the file, processes and sorts the data and puts it in 
>> a
>> data structure of paragraphs composed of pieces of text with formatting
>> instructions (I may add more options in the future). I can also print out
>> plain text or html with similar routines. The Word output has the 
>> advantage
>> of allowing me to add page numbers and insert an introduction etc easily.
>>
>> I would like to migrate this to Linux (I have XP / SuSE 9.1 dual boot on 
>> my
>> notebook) but am unsure of which program to replace Word with. OOo does 
>> not
>> seem to automate as easily.
>
> I don't have any experience with this but did you try typing
>
> openoffice perl
>
> into Google?

Yes and followed links for hours but with little useful result. I have 
looked into the OODoc module, but it does not seem to offer a way to do the 
formatting without hacking the low-level XPath stuff - and it is reputed to 
be very slow. I cannot find info on automation of Writer from Perl, and the 
stuff for other languages looks complex, thus I'm interested in other 
options.


0
6/6/2005 10:03:57 AM
Dave <daveandniki@ntlworld.com> wrote:
> The Word output has the advantage of allowing me to add page numbers
> and insert an introduction etc easily.

> I would like to migrate this to Linux (I have XP / SuSE 9.1 dual boot on my 
> notebook) but am unsure of which program to replace Word with. OOo does not 
> seem to automate as easily. I don't know which line to go down: TeX, PDF, a 
> different Word processor?

I don't know much about automating OpenOffice, so my tool of choice
would be LaTeX. In fact, you'll probably get away without learning too
much LaTeX to get this done. All you need would be a few header lines to
setup the document and dump in your data. Page numbering is automatic
(and configurable) and manually adding an introduction etc. is trivial.
Once you have your LaTeX code you can easily produce Postscript or PDF
output.

On the other hand, there may be an easy way to produce RTF files from
PERL. CPAN lists a Module called 'RTF-Writer' - maybe that does what you
need.

If you know Python there is yet another option: ReportLab allows you to
generate PDF files from Python scripts (never used this tool myself, but
have met enthusiastic users). Similar tools may be available for PERL as
well.

cu
	Philipp

-- 
Dr. Philipp Pagel                           Tel.  +49-89-3187-3675
Institute for Bioinformatics / MIPS         Fax.  +49-89-3187-3585
GSF - German National Research Center for Environment and Health
http://mips.gsf.de/staff/pagel
0
pDOTpagel (74)
6/6/2005 12:04:44 PM
"Dave" <daveandniki@ntlworld.com> writes:

> "Dan Espen" <daneNO@SPAM.mk.telcordia.com> wrote in message 
> news:icr7fgfyma.fsf@mk.telcordia.com...
>> "Dave" <daveandniki@ntlworld.com> writes:
>>
>>> The code snippet below prints out a bilingual dictionary of mine into
>>> MSWord. The dictionary entries are in an XML file that I edit with VIM. 
>>> The
>>> Perl script parses the file, processes and sorts the data and puts it in 
>>> a
>>> data structure of paragraphs composed of pieces of text with formatting
>>> instructions (I may add more options in the future). I can also print out
>>> plain text or html with similar routines. The Word output has the 
>>> advantage
>>> of allowing me to add page numbers and insert an introduction etc easily.
>>>
>>> I would like to migrate this to Linux (I have XP / SuSE 9.1 dual boot on 
>>> my
>>> notebook) but am unsure of which program to replace Word with. OOo does 
>>> not
>>> seem to automate as easily.
>>
>> I don't have any experience with this but did you try typing
>>
>> openoffice perl
>>
>> into Google?
>
> Yes and followed links for hours but with little useful result. I have 
> looked into the OODoc module, but it does not seem to offer a way to do the 
> formatting without hacking the low-level XPath stuff - and it is reputed to 
> be very slow. I cannot find info on automation of Writer from Perl, and the 
> stuff for other languages looks complex, thus I'm interested in other 
> options.

I see you are still not getting any expert help.
Sorry about that.  I've heard that the automation in Open Office
is far better than that for Word.  Sorry I don't have any first hand
experience with that.  I tend to avoid things that make paper.

Anyway, this link SEEMED to point to a Perl Open Office interface tool:

http://ooolib.sourceforge.net/
0
daneNO (319)
6/6/2005 12:14:41 PM
> I see you are still not getting any expert help.
> Sorry about that.  I've heard that the automation in Open Office
> is far better than that for Word.  Sorry I don't have any first hand
> experience with that.

I expect that not many people that frequent this group will.  Better
option would be to find a list or group for OO.  Maybe going to the
website would help.

This isn't off topic IMHO, it just isn't likely to be a topic widely
known about here.

0
nroberts1 (270)
6/6/2005 5:58:31 PM
This may no help, but, KWord is handy... I don't know if it has what
you want. Semiofftopic: Try wine and install MSWord ontop of that...

0
cpu.crazy (44)
6/6/2005 8:29:35 PM
Reply: