今天發現用 docbook2rtf 做出來的 RTF 檔不支援內嵌圖片,google 了一下,發現了有個 Perl script 可以做這樣的轉換:RE: Embedding graphics in RTF
有需要的自行剪下程式存檔執行即可:
# Perl
# $Header: /usr/local/cvs/test/dde/publish/Scripts/word-update-all.pl,v 1.3 1999/06/17 15:21:58 Andrei Exp $
my $no_list_file = 0;
while ( $#ARGV > 0 )
{
$_ = $ARGV[0];
SWITCH: {
/^\-\?$/ && do { usage (); return -1; };
/^\-f$/ && do { shift; $list_file = shift; last SWITCH; };
/^\-f\-$/ && do { shift; $no_list_file = 1; last SWITCH; };
/^\-i$/ && do { shift; $in_path = shift; last SWITCH; };
/^\-o$/ && do { shift; $out_path = shift; last SWITCH; };
/^\-v$/ && do { shift; $visible = 1; last SWITCH; };
usage ();
print "Unknown command line argument. aborting\n";
return -2;
}
};
print "\nWORD-UPDATE-ALL.PL WORKING ENVIRONMENT\n";
print "------------------------------------------------------------\n";
print "list_file : $list_file\n";
print "in_path : $in_path\n";
print "out_path : $out_path\n\n";
# WORD Application initialization
#_________________________________
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Word';
@storytypes = ( 4, 3, 8, 6, 11, 10, 2, 1, 9, 7, 5 );
my $Word = Win32::OLE->new('Word.Application', 'Quit');
return -5 if (!$Word);
$Word->{'Visible'} = 1 if ($visible);
if (!$no_list_file)
{
if (!$list_file or !$in_path or !$out_path)
{
$Word->Quit();
return -3;
};
if ( !(open LISTFILE, "<$list_file"))
{
print "word-update-all Can't open list file!";
$Word->Quit();
return -4;
}
while (<LISTFILE>)
{
chomp;
(my $file, my $junk) = split("#");
my $src = "$in_path\\$file.rtf";
my $tgt = "$out_path\\$file.rtf.doc";
print "saving $src -> $tgt\n";
my $Doc = $Word->Documents->Open($src);
if(!$Doc)
{
print STDERR "Can not Open $src!\n";
}
$Doc->Repaginate();
$Stories = $Doc->StoryRanges;
for $s ( @storytypes )
{
eval
{
$Story = $Stories->Item($s);
if ($Story)
{
$Story->Fields->Update();
$Story->Fields->Unlink();
}
};
}
$Doc->SaveAs($tgt, 0);
$Doc->Close();
}
close (LISTFILE);
}
else
{
if (!$in_path or !$out_path)
{
$Word->Quit();
return -3;
}
print "saving $in_path -> $out_path\n";
my $Doc = $Word->Documents->Open($in_path);
if(!$Doc)
{
print STDERR "Can not Open $in_path!\n";
}
$Doc->Repaginate();
$Stories = $Doc->StoryRanges;
for $s ( @storytypes )
{
eval
{
$Story = $Stories->Item($s);
if ($Story)
{
$Story->Fields->Update();
$Story->Fields->Unlink();
}
};
}
$Doc->SaveAs($out_path, 0);
$Doc->Close();
}
$Word->Quit();
return 0;
sub usage
{
print "Usage: word-update-all.pl -f <list file> -i <input path> -o <output path> [-v]\n\n";
print "Usage (no listfile): word-update-all.pl -f- -i <input file> -o <output file> [-v]\n\n";
print " -v make word visible\n\n";
print " exit codes:\n";
print " -1 usage shown\n";
print " -2 unknown argument\n";
print " -3 missing argument\n";
print " -4 can't open list file\n";
print " -5 can't open MS Word\n\n";
return;
}