I am taking my first steps from Base Camp 1 of the Catalyst learning
curve. I am trying to add PDF capability to the standard Books app of
the tutorial. The PDF view appears to be running but is not returning
any content.

As per the C::V::P::R docs, I have:

In ~/Catalyst/MyApp, run  script/myapp_create.pl view PDF::Reuse PDF::Reuse

In ~/Catalyst/MyApp/lib/MyApp.pm, added:

# Configure PDF generator view
__PACKAGE__->config('View::PDF::Reuse' => {
   INCLUDE_PATH => __PACKAGE__->path_to('root','src','books')
                   });

In ~/Catalyst/MyApp/lib/MyApp/Controller/Books.pm, added:

sub pdf :Local {
   my ($self, $c) = @_;
   my $log = $c->log;
   $log->debug('*** in sub pdf ***');
   # Retrieve all of the book records as book model objects and store
   # in the stash where they can be accessed by the TT template that
   # will generate the PDF
   $c->stash(books => [$c->model('DB::Book')->all]);

   # Set PDF parameters
   $c->stash->{fontname} = 'Helvetica-Bold';
   $c->stash->{fontsize} = '20';

   # Set the TT template to use and go. (Overriddeen during debug for
simplicity)
   #$c->stash->{pdf_template} = 'list_pdf.tt2';
   $c->stash->{pdf_template} = 'hello_pdf.tt2';
   $c->stash->{pdf_filename}    = 'booklist.pdf';

   $log->debug('*** forwarding to View::PDF::Reuse ***');
   $c->forward('View::PDF::Reuse');
}

In ~/Catalyst/MyApp/root/src/books/hello_pdf.tt2 :

[% pdf.prFile() %]
[% pdf.prText(100,100,'Hello, World') %]
[% pdf.prEnd %]

I tried adding
[%# check the template is being read %]
[% pdf.junk-should-fail %]
[%# that line makes no difference %]

but there was no change to the output, which seems odd. I do think the
template is being read because I can break the view by using prLog -
see addendum below.

The controller is involed form the book listing page in
~/Catalyst/MyApp/root/src/books/list.tt2 thus:
[% # A link for a PDF of the booklist %]
<p><a href="[% c.uri_for(c.controller.action_for('pdf')) %]">PDF list</a></p>

In all cases I see this in the server log:

[debug] "GET" request for "books/pdf" from "81.109.243.248"
[debug] Path is "books/pdf"
[debug] Found sessionid "652adf37e1e9e9254463c75c63f2530fc1ff2b93" in cookie
[debug] Restored session "652adf37e1e9e9254463c75c63f2530fc1ff2b93"
[debug] *** in sub pdf ***
[debug] *** forwarding to View::PDF::Reuse ***
[debug] Rendering template "SCALAR(0xbf2b210)"
[debug] Response Code: 200; Content-Type: application/pdf; Content-Length: 546
[info] Request took 0.033116s (30.197/s)
.------------------------------------------------------------+-----------.
| Action                                                     | Time      |
+------------------------------------------------------------+-----------+
| /auto                                                      | 0.000291s |
| /books/pdf                                                 | 0.027157s |
|  -> MyApp::View::PDF::Reuse->process                       | 0.024822s |
| /end                                                       | 0.000182s |
'------------------------------------------------------------+-----------'

The size (546) is always the same.
The data returned is recognised by the browser as a PDF file which it
shows as an empty page. Examining the PDF file I see

victor@pan2:/tmp$ ls -l booklist.pdf
-r-------- 1 victor victor 546 2011-03-02 17:23 booklist.pdf

victor@pan2:/tmp$ file booklist.pdf
booklist.pdf: PDF document, version 1.4

victor@pan2:/tmp$ head -1 booklist.pdf
%PDF-1.4

victor@pan2:/tmp$ tail -n 1 !$
tail -n 1 booklist.pdf
%%EOF

I am evidently missing something very basic and obvious ;-( but not to
me) and am struggling to get into this to see what's going wrong.
Normal debug methods do not seem to apply in Catalyst land!

Any suggestions very much appreciated. Please let me know if there is
any other information I can provide. Thanks!!

Addendum - I also tried adding to the hello_pdf.tt2 template some log requests:

[% pdf.prLogDir('/tmp') %]
[% pdf.prLog('call prFile') %]
etc., but got this runtime error:

Couldn't render template "undef error -  You have to give a directory
for the logfiles first : prLogDir <dir> , aborts
 More information might be found in error.log       [.. it wasn't]
 at /usr/local/lib/perl/5.10.1/Template/Plugin/Procedural.pm line 55"

But I think this is a different issue.

_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/

Reply via email to