|
Thanks for jmgdoc jeunice and all other guys on this forum, after study all your guys
suggestion and google, I made a new version, it works but still need improvement
The complete source code as:
#!/usr/bin/perl
use lib "/home/littles/.perl/module/lib/perl5/site_perl/5.8.5";
use OpenOffice::OODoc;
use OpenOffice::OODoc::File;
use OpenOffice::OODoc::Styles;
use OpenOffice::OODoc::Document;
use OpenOffice::OODoc::Text;
use OpenOffice::OODoc::Manifest;
use OpenOffice::OODoc::Meta;
use OpenOffice::OODoc::Image;
use OpenOffice::OODoc::XPath;
use Data::Dumper;
my $document;
my $content;
my @styles;
my $style;
# I seperate document, content and style to make code more readable
$document = ooDocument
(
file => 'test.odt',
create => 'text'
)
or print " can not create $filename! \n";
# connect a style-focused document interface
$style = ooDocument
(
file => 'test.odt',
member => 'styles',
)
or print " can not open test.odt styles ! \n";
# before we use font, declare it
$style->importFontDeclaration
(
'<style:font-face '.'style:name="Comic Sans MS" '.'svg:font-family="Comic Sans MS"/>'
);
$style->importFontDeclaration
(
'<style:font-face '. 'style:name="Nimbus Roman No9 L" '. 'svg:font-family="Nimbus Roman No9 L
+" />'
);
$style->importFontDeclaration
(
'<style:font-face '.'style:name="Courier" '.'svg:font-family="Courier" />'
);
# chinese support
$style->importFontDeclaration
(
'<style:font-face '.'style:name="AR PL SungtiL GB" '.'svg:font-family="AR PL SungtiL GB" />'
);
# update 'Text body' paragraph and text properties
$style->updateStyle
(
"Text_20_body",
family=>'paragraph',
parent => "Standard",
properties =>
{
'area' => 'paragraph',
'fo:margin-left'=>"0in",
'fo:margin-right'=>"0in",
'fo:margin-top'=>"0.05in",
'fo:margin-bottom'=>"0.05in",
'fo:line-height'=>"0.1575in",
'fo:text-align'=>"justify",
'fo:text-indent'=>"0in",
'style:justify-single-word'=>"true",
'style:auto-text-indent'=>"false",
'style:shadow' => "none"
}
)
or print " can createStyle ! $LINE\n";
$style->updateStyle
(
"Text_20_body",
properties =>
{
'area' => 'text',
'fo:font-size' => "10pt",
'style:font-name' => 'Nimbus Roman No9 L',
'fo:font-size-asian' => "10pt",
'style:font-name-asian' => 'AR PL SungtiL GB'
}
)
############################################################
# Quotations
############################################################
$style->createStyle
(
'Quotations',
family=>'paragraph',
parent => "Standard",
properties =>
{
'area' => 'paragraph',
'fo:margin-left'=>"0.2in",
'fo:margin-right'=>"0.2in",
'fo:margin-top'=>"0in",
'fo:margin-bottom'=>"0in",
'fo:padding'=>"0.0201in",
'fo:border'=>"0.0008in solid #000000",
'fo:line-height'=>"0.12in",
'fo:text-align'=>"justify",
'fo:text-indent'=>"0in",
'style:auto-text-indent'=>"false",
'style:auto-text-indent'=>"false",
'fo:background-color'=>"#e6e6e6",
'style:join-border'=>"true", # merge border
'style:justify-single-word'=>"true",
'style:shadow' => "none"
}
)
or print " can createStyle ! \n";
$style->updateStyle
(
'Quotations',
properties =>
{
'area' => 'text',
'fo:font-size' => "9pt",
'style:font-name' => 'Courier',
'fo:font-size-asian' => "9pt",
'style:font-name-asian' => 'AR PL SungtiL GB'
}
)
or print " can updateStyle $LINE!\n" ;
$style->save("test.odt");
###################################################################
# connect a content-focused document interface
$content = ooDocument
(
file => 'test.odt',
member => 'content'
)
or print " can not open test.odt content ! \n";
$content->appendParagraph
(
text => 'Text body content Text body content Text body content Text body content Text body cont
+ent Text body content Text body content Text body content Text body content Text body content Text
+ body content Text body content Text body content Text body content Text body content Text body co
+ntent Text body content Text body content Text body content Text body content Text body content',
style => 'Text body'
);
$content->appendParagraph
(
text => 'Quotations body content Quotations body content Quotations body content Quotations bod
+y content Quotations body content Quotations body content Quotations body content Quotations body
+content Quotations body content Quotations body content Quotations body content Quotations body co
+ntent Quotations body content Quotations body content Quotations body content Quotations body cont
+ent ',
style => 'Quotations'
);
$content->save("test.odt");
Inside source code, I update 'Text body' or 'Text_20_body',
but for Quotations, I cant update it, I can't find it's display name,
So I just create it myself, I mainly use this style for my source code
in report.
Need your suggestion, I will check OO specification to find Quotations'
display name to improvement this little script file.
|