如何使用 OpenOffice::OODoc 将文本标题添加到图像?
我有以下代码创建一个带有标题和图片的 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();
How can I add a text title to the picture?当我在 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>
我认为它会创建一个框架,然后将图像和标题文本放入其中。我现在迷路了。我在文档中也找不到有关向框架添加元素的内容。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 perl 创建的 xml 会很有趣,但除此之外,您可以在写出之前使用 Xpath 模块修改 XML。但实际上,我们需要查看基本输出才能了解出了什么问题。例如,框架嵌套可能是错误的。
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.