I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2011-02-11 03:12:09.81107-08 by oakbox
Created files incompatible with OpenOffice 3.2
For the last couple of years, this wasn't a killer problem because my Debian servers were still ticking along on the OO 2.4 branch. That is no longer the case, Debian has moved Open Office to 3.2 and now this little problem has the potential to force me into a rewrite of 5 years of coding.
The problem:
An .odt file created using this module will give a warning when opened with Open Office 3.2. "This file is corrupt, do you want me to fix it?"

When I am using X directly, I can just click 'yes' and everything is okay. The structure of the document is not harmed, or even visibly changed from the way it appeared in OO 2.4.

The BIG problem is that I am not using X, I am running this on a production web server and there is no way (that I can think of or want to contemplate) to click that little 'yes' button programmatically so that the file can be converted to a PDF.

1) Anyone else experiencing this problem? I will be happy to post a link to an example .odt file. I HOPE this is just me, that means there is something I can change, but this error is occuring on 3 separate machines.
2) Is there any way to fix this?

Thank you,
Richard Still (oakbox)
Direct Responses: 13193 | 13195 | Write a response
Posted on 2011-02-11 03:54:17.210034-08 by jmgdoc in response to 13191
Re: Created files incompatible with OpenOffice 3.2

OODoc worked for me with every version of OpenOffice, including 3.2 and 3.3.
You should run the oodoc_test installation test script provided with the OODoc distribution and have a look through OpenOffice at the generated document (odftest.odt).
Direct Responses: 13194 | Write a response
Posted on 2011-02-11 04:52:10.164543-08 by oakbox in response to 13193
Re: Created files incompatible with OpenOffice 3.2

oodoc_test does produce a file that can be opened in 3.2 without error.

Unfortunately, a document created with some of my scripts continue to fail in 3.2 and can be opened in 2.4 without error.

I will take apart the offending document and look for where, specifically, it is failing.

-oakbox
Direct Responses: Write a response
Posted on 2011-02-11 05:54:25.691594-08 by oakbox in response to 13191
Re: Created files incompatible with OpenOffice 3.2

Found it! I get the errors whenever I try to import an image into the document.

So, my modified question is,"Has anyone else experienced errors when importing images into an OpenOffice document?"

my ($s, $usec) = gettimeofday; # using Time::HighRes to create a unique name my $time = $s . $usec; my $testimage = "/tmp/file.png"; my $table = $document->getTable("blockgraphic"); my $tablecopy = $document->replicateElement($table, 'body'); my $par = $document->getCellParagraph($tablecopy, 0, 0); $document->createImageElement("$time", size =>"13.76,9.53", attachment => $par, import => $testimage, style => "Graphics", );

- oakbox

Direct Responses: 13196 | Write a response
Posted on 2011-02-11 07:07:49.281558-08 by jmgdoc in response to 13195
Re: Created files incompatible with OpenOffice 3.2

Looks strange. I pasted you code unchanged in the program below.
I used a source file containing nothing but an empty table named "blockgraphic".
Then OpenOffice doesn't complain with the resulting file. (I currently use OOo 3.3.0 build 9567 from the official OOo distribution).
However, when you import an image through createImageElement it's a good idea to update the file manifest accordingly. In your script, a "file.png" external resource is physically imported but not declared in the manifest, so the resulting ODT file is not strictly OpenDocument-compliant, and OpenOffice could legitimately warn (while it doesn't in my installation). The two lines before the save() instruction in my example show a way to set the appropriate image/png entry (the imageLink method retrieves the internal path of the image file in the ODT file and the user must provide the MIME type).
Then if OOo complains again even if your manifest is OK, I really don't see where is the issue.
use strict; use Time::HiRes qw(gettimeofday); use OpenOffice::OODoc; my $document = odfDocument(file => "/tmp/source.odt", readable_XML => 1); #--- my ($s, $usec) = gettimeofday; # using Time::HighRes to create a unique name my $time = $s . $usec; my $testimage = "/tmp/file.png"; my $table = $document->getTable("blockgraphic"); my $tablecopy = $document->replicateElement($table, 'body'); my $par = $document->getCellParagraph($tablecopy, 0, 0); $document->createImageElement("$time", size =>"13.76,9.53", attachment => $par, import => $testimage, style => "Graphics", ); #--- my $manifest = odfManifest(container => $document); $manifest->setEntry($document->imageLink($time), "image/png"); $document->save("/tmp/target.odt");
Direct Responses: 13197 | Write a response
Posted on 2011-02-11 07:57:55.889714-08 by oakbox in response to 13196
Re: Created files incompatible with OpenOffice 3.2

That was the answer, I have never touched the Manifest. That still means a lot of re-writing, but at least I won't be stuck in OO 2.4 forever :)

Your code was close, but the odfManifest call would not operate on the container directly. I had to save the document and then reopen the manifest, make changes, and save the .odt file again.

# stuff happens $document->createImageElement("$time", size =>"13.76,9.53", attachment => $par, import => $testimage, style => "Graphics", ); # more stuff happens # create the .odt file $document->save(); # Now, re-open that file's manifest my $manifest = OpenOffice::OODoc::odfManifest(file => $odtfile); $manifest->setEntry($document->imageLink($time), "image/png"); # and save it back $manifest->save();

And it works! I can now add images into my reports again without OpenOffice 3.2 complaining. Considering the fact that most of my reports are imported images, this was a real problem for me.

Thank you, Jean-Marie, for your help and great module!

- oakbox (Richard Still)

Direct Responses: 13198 | Write a response
Posted on 2011-02-11 08:45:54.764415-08 by jmgdoc in response to 13197
Re: Created files incompatible with OpenOffice 3.2

Good news... However you should never have to save, reload and save a file to update the document content and the manifest separately. It undoubtedly works but it's counter-performing because the physical file is saved twice. When several document parts are connected to the same container, the save() method of one of the parts makes all the changes persistent. In the example below, $meta and $manifest are connected to the same container as $document, and the last instruction saves all. Of course, the 'container' parameter of each secondary part must be set to the primary document object and *not* to the filename!
my $document = odfDocument(file => "myfile.odt"); my $meta = odfMeta(container => $document); my $manifest = odfManifest(container => $document); # ...process the various parts $document->save();
Direct Responses: 13202 | Write a response
Posted on 2011-02-15 04:51:44.330366-08 by sarahbrown in response to 13198
Re: Created files incompatible with OpenOffice 3.2
Direct Responses: 13204 | Write a response
Posted on 2011-02-15 23:56:50.658391-08 by gerrifoxe45 in response to 13202
Re: Created files incompatible with OpenOffice 3.2
http://www.rattan-hoefner.de/
Direct Responses: Write a response