Dear Monks,
I am trying to use OODoc to combine files into a single OpenOffice Writer document. I am successful in combining files but am rather lost when trying to manipulate the format of the odt file.
My two current problems are:
1) I always use the "old school" method of indenting subroutines and loops (three spaces for first indent, 6 for one more level of nesting, then 9, etc.). No matter how many leading spaces a source line has the output document only has a single leading space.
2) When I use my full set of files the output document has paragraph numbering turned on. It is not a huge task to turn it off inside OO Writer, but it would be nicer if it did not get turned on.
To illustrate the spaces problem I started with a fake data file named 1.php. (Overall I am working with some perl, some php and some odt files)
# This is a fake program/data file
subroutine_1
{
# there are three spaces in front of this pound sign
}
For my second fake program/data file I just changed the "1" in both the file name and subroutine name to "2".
My sample code is here:
#!/usr/bin/perl
# FILE: /WIP/perl_try_OODoc/perl_monks_03.pl
# apt-get install liboffice-oodoc-perl (Ubuntu 9.04) or equivalent req
+uired.
use warnings;
use strict;
use OpenOffice::OODoc;
my ($i, $my_text);
my @Fnames = ('/var/www/php/1.php', '/var/www/php/2.php'); # files to
+read into document
my $x = "cp /home/my_name/util/oo-macro/blank_seed.odt /home/my_name/u
+til/oo-macro/test.odt";
system($x); # copy from seed file to output document file
my $doc_out = odfDocument(file => '/home/my_name/util/oo-macro/test.od
+t'); # setup output
# ====== add files into output document ======
foreach(@Fnames) # process each php file
{
open(FI, "<$_");
my @code_lines = <FI>; # read all the php code from a single file
close FI;
$my_text = ""; # init
for($i = 0; $i <= $#code_lines; $i++)
{
$my_text .= $code_lines[$i];
#$my_text =~ s/\r/\r\n/g; # didn't help, didn't hurt
}
$doc_out -> appendParagraph(text => $my_text,
style => "Default"); # write a full php
+ file to odt
}
$doc_out -> save; # done
When I run the above sample code with perl or php files the code runs without reported error. When I open up the odt file there is only one space at the beginning of any line that started with one or more spaces.
When I copy the odt file to a temporary directory, unzip it and
look inside the content.xml file I can see that the 3 spaces are there. I can't find any way in OO Writer to turn off the contraction of these spaces so I am totally stuck. Since I would like my code to work for me and make my life easier I am also stuck on how to make my perl code correct this.
Overall, based upon current needs, I may be combining perl code, php code, text files or OO document files. Later I might throw spreadsheets into the mix too. My full size code example currently works with php and odt. I have a additional related problem there. The output document (combined odt files) has an additional left margin and all paragraphs have paragraph numbers. I have found the procedure to turn this off in OO Writer, but again I would prefer to have my perl code make "ready to use" files for me. So far I have not been able to find the answer to this one either.
Note that my large code file will, based upon file extension, use different code for odt files. I am using sample code from the internet that seems to combine the odt files properly. If this one posting doesn't solve both problems then I will repost with sample code for odt files. My guess is that this contraction of spaces problem will expose me to a wide variety of formatting power that will solve many style and formatting issues.
Any suggestions would be appreciated.
Thanks,
Bruce