[Dancer-users] Generating PDF with Template-Plugin-Latex fails inside route handler

Mike Mandel mandel at stud.fh-hannover.de
Sat Jan 8 00:38:30 CET 2011


>> Hello,
>>
>> I want to generate a pdf with Template-Plugin-Latex where the user fills
>> out a html form and
>> the app sends back a pdf.
>>
>> Outside the route handler create_pdf() works and the pdf is generated,
>> but inside the route handler create_pdf() fails:
>>
>> latex error - pdflatex exited with errors:
>>
>> -----
>> Minimal example:
>>
>> #!/usr/bin/perl
>> use Dancer;
>> use Template::Latex;
>>
>> sub create_pdf {
>>    my $tt = Template::Latex->new({
>>                                INCLUDE_PATH =>
>> '/path/to/my/app/public/latex',
>>                                OUTPUT_PATH => '/path/to/my/app/public/pdf',
>>                                LATEX_FORMAT => 'pdf',
>>                                });
>>
>>    $tt->process('test.tt', {name => 'Dancer'}, 'test.pdf', binmode =>
>> 1)  || die $tt->error();
>> };
>>
>> # works
>> create_pdf();
>>
>> get '/' => sub {
>>    return 'Hello Dancer';
>> };
>>
>> get '/create_pdf' => sub {
>>    # works not
>>    create_pdf();
>> };
>>
>> get '/download/:file' => sub {
>>    send_file('/pdf/'.params->{file});
>> };
>>
>> dance();
>>
>> ----
>> My template test.tt
>>
>> [% USE Latex %]
>> [% FILTER latex('pdf') %]
>> \documentclass[version=last]{scrartcl}
>> \begin{document}
>> Hello [% name %]
>> \end{document}
>> [% END %]
>>
>> Any suggestions what could be wrong?
>>
>> Thanks a lot,
>>
>> Mike
>> _______________________________________________
>> Dancer-users mailing list
>> Dancer-users at perldancer.org
>> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
>>     
Hello,

I tracked it down a little bit, and found out, that the return code
of the system() function is different inside a route handler than outside.
Could please someone test this?
------------------------------
#!/usr/bin/perl
use Dancer;

my $rc = system("/usr/bin/pdflatex -v");
#my $rc = system("/usr/bin/gcc -v");
print "\$rc: $rc\n";                  # $rc = 0

get '/system' => sub {
    $rc = system("/usr/bin/pdflatex -v");
    #$rc = system("gcc -v");
    '$rc = ' . $rc;                       # $rc = -1, should be 0
};

dance();
-----------------------------

Thanks,

Mike


More information about the Dancer-users mailing list