Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a text caption to an image with OpenOffice::OODoc?

I have the following code that creates an odf-document with a heading and a picture:

#!/usr/bin/perl 

use strict;
use warnings;
use OpenOffice::OODoc;

my $doc = odfDocument(
    file   => 'test.odt',
    create => 'text'
);

my $head = $doc->appendHeading(
    text  => "This is a Test",
    style => 'Heading 1'
);

my $style = $doc->createImageStyle("Photo");
my $image = $doc->createImageElement(
    'some picture',
    style      => 'Photo',
    attachment => $head,
    size       => '4cm, 12cm',
    link       => '/full/path/to/picture.png'
);

$doc->save();

How can I add a text caption to the picture? When I create a text caption in LibreOffice the part of the 'content.xml' where a caption is created looks like this.

<draw:frame draw:style-name="fr1" draw:name="Frame1" text:anchor-type="as-char" svg:y="0cm" svg:width="4.001cm" draw:z-index="0">
  <draw:text-box fo:min-height="12cm">
    <text:p text:style-name="Caption">
      <draw:frame draw:style-name="fr2" draw:name="Eiffel Tower" text:anchor-type="paragraph" svg:x="0.004cm" svg:y="0.002cm" svg:width="4.001cm" style:rel-width="100%" svg:height="12cm" style:rel-height="scale" draw:z-index="1">
        <draw:image xlink:href="full/path/to/picture.png" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
      </draw:frame>
      test caption
    </text:p>
  </draw:text-box>
</draw:frame> 

I think it creates a frame and then puts the image and the caption text inside of it. I am lost at this point. I couldn't find something about adding elements to frames in the documentation either.

like image 987
AlexTheBird Avatar asked Jun 19 '11 03:06

AlexTheBird


People also ask

How do I add text to a Picture in OpenOffice?

Re: inserting text If you want text above or below the image, select the image and do Insert > Caption. If you want text on top of the image, you can double-click the image, then type the text. You can change the format of the text from the Picture toolbar, using the "Character" button.

Is it possible to add text over an image in ooo4kids writer?

A handy solution is to specify that text should go through the image in Apache OpenOffice Writer. For that to be effective, though, the image should be set as the background. You may also need to increase transparency so it doesn't overpower the text overlay.

How do you add a caption for graphics in OpenOffice org from the menus?

Click Tools > Options. On the Options dialog box, click on the + sign next to OpenOffice.org Writer to show a list of options. Select AutoCaption. Now you can see several choices at the right of the dialog box for adding captions automatically.


1 Answers

It would be interesting to see the xml that the perl creates, but other than that, you can use the Xpath module to amend the XML before writing it out. But really, we need to see the basic output to see what's going wrong. For example, maybe the frame nesting is wrong.

like image 104
AlwaysLearning Avatar answered Oct 18 '22 15:10

AlwaysLearning