【问题标题】:How to add a text caption to an image with OpenOffice::OODoc?如何使用 OpenOffice::OODoc 为图像添加文本标题?
【发布时间】:2011-06-19 03:11:52
【问题描述】:

我有以下代码创建带有标题和图片的 odf 文档:

#!/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();

如何为图片添加文字说明?当我在 LibreOffice 中创建文本标题时,创建标题的“content.xml”部分如下所示。

<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> 

我认为它会创建一个框架,然后将图像和标题文本放入其中。我在这一点上迷路了。我在文档中也找不到有关向框架添加元素的内容。

【问题讨论】:

    标签: perl openoffice.org odf libreoffice


    【解决方案1】:

    看看 perl 创建的 xml 会很有趣,但除此之外,您可以使用 Xpath 模块在写出 XML 之前对其进行修改。但实际上,我们需要查看基本输出以了解发生了什么问题。例如,可能是框架嵌套错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-04
      • 1970-01-01
      • 2023-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-28
      相关资源
      最近更新 更多