holli has asked for the wisdom of the Perl Monks concerning the following question:

Lately I am playing with the Template Toolkit. My task is to create XSL-FO using the toolkit and create PDF out of it's output via Apache's FOP.

I have a working solution but it looks clumsy to me. There should be a better way.
#!perl my $t=Template->new ( INCLUDE_PATH => 'c:/', COMPILE_DIR =>"c:/tt", FILTERS => { fop => sub { open OUT, ">tmpf"; print OUT @_; close OUT; $_ = `fop -fo tmpf -pdf test.pdf`; unlink "tmpf"; return $_; } } ); #....
The template:
[%- FILTER fop -%] <?xml version="1.0" encoding="iso-8859-1"?> <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> [%# do stuff %] [% END %]


holli, /regexed monk/

Replies are listed 'Best First'.
Re: Template Toolkit: Better way to call FOP
by runrig (Abbot) on Jul 14, 2005 at 17:39 UTC
    Since fop is all java (and there's a fop.jar), it should be possible to use Inline::Java to call the fop API directly instead of using the fop commandline utility, where you may be able to pass in a file handle (there is a "embedding" doc in the FOP distribution). There is also XML::ApacheFOP, but I don't think it accepts STDIN or other filehandles as input arguments...it might be worthwhile to research seeing if that could be made to work.
Re: Template Toolkit: Better way to call FOP
by blazar (Canon) on Jul 14, 2005 at 16:50 UTC
    IIUC and if fop accepts output from STDIN, then you may be interested in IPC::Open2.