in reply to Re: Search OpenOffice document for title and author
in thread Search OpenOffice document for title and author [Solved]
The meta data doesn't show the title which is a paragraph with the style of 'Title' or Psomething.
I installed ODF::lpOD once I figured out that lpOD starts with lower case L. It's documentation is voluminous and not much better than OpenOffice::OODoc's.
However I did get it to work!
#!/usr/bin/perl -w use strict; use ODF::lpOD; my $file = $ARGV[0]; die "You must supply an odf file name\n" unless $file; my $doc = odf_document->get($file) or die "Can't load $file\n$!\n"; my $context = $doc->body; my $meta = $doc->meta; # Doesn't do what I wanted my $title = $meta->get_title; print "Title: $title\n" if $title; # shows Title: c if at all my $p = $context->get_paragraph(style=>'Title', content=>'ODF',positio +n=>0); if ($p) {print $p->get_text()."\n";} else {print "Not found\n";} # prints Not found #this works my ($i,$ps,$style,$pStyle); for ($i = 0; $i < 6; $i++) { $p = $context->get_paragraph(position=>$i); if ($p) { print "Paragraph $i"; $ps = $p->get_style(); if ($ps) { if ($ps =~ m/^P\d+$/) { # Check for internal styles $style = $doc->get_style('paragraph',$ps) || ''; $pStyle = $style->get_parent_style if $style; $ps = $pStyle if $pStyle; # This gets the real name } print " Style: $ps\n"; } else {print "No Style\n";} my $data = $p->get_text(recursive=>1); if ($data) {print "$data\n";} else {print "--No data\n";} } else { print "Paragraph $i not found\n"; } }
Thanks Ken
—Bob
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Search OpenOffice document for title and author
by jinnicky (Sexton) on Feb 26, 2016 at 02:33 UTC |