[Catalyst-commits] r11266 - in Catalyst-View-PDF-API2/trunk: .
lib/Catalyst/Helper/View/PDF lib/Catalyst/View/PDF t
t/lib/TestApp/Controller
ferz at dev.catalyst.perl.org
ferz at dev.catalyst.perl.org
Fri Aug 28 15:41:34 GMT 2009
Author: ferz
Date: 2009-08-28 15:41:34 +0000 (Fri, 28 Aug 2009)
New Revision: 11266
Modified:
Catalyst-View-PDF-API2/trunk/Makefile.PL
Catalyst-View-PDF-API2/trunk/lib/Catalyst/Helper/View/PDF/API2.pm
Catalyst-View-PDF-API2/trunk/lib/Catalyst/View/PDF/API2.pm
Catalyst-View-PDF-API2/trunk/t/01-livetest.t
Catalyst-View-PDF-API2/trunk/t/lib/TestApp/Controller/Root.pm
Log:
It still fails 1/4 tests.
Modified: Catalyst-View-PDF-API2/trunk/Makefile.PL
===================================================================
--- Catalyst-View-PDF-API2/trunk/Makefile.PL 2009-08-28 13:23:16 UTC (rev 11265)
+++ Catalyst-View-PDF-API2/trunk/Makefile.PL 2009-08-28 15:41:34 UTC (rev 11266)
@@ -14,6 +14,7 @@
'PDF::API2' => 0,
'File::chdir' => 0,
'Template::Plugin::Procedural' => 0,
+ 'Test::File::Contents' => 0,
'parent' => 0,
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
Modified: Catalyst-View-PDF-API2/trunk/lib/Catalyst/Helper/View/PDF/API2.pm
===================================================================
--- Catalyst-View-PDF-API2/trunk/lib/Catalyst/Helper/View/PDF/API2.pm 2009-08-28 13:23:16 UTC (rev 11265)
+++ Catalyst-View-PDF-API2/trunk/lib/Catalyst/Helper/View/PDF/API2.pm 2009-08-28 15:41:34 UTC (rev 11266)
@@ -15,7 +15,7 @@
Then in MyApp.pm, add a configuration item for the View::PDF::API2 include path:
__PACKAGE__->config('View::PDF::API2' => {
- INCLUDE_PATH => __PACKAGE__->path_to('root','templates')
+ INCLUDE_PATH => __PACKAGE__->path_to('root','pdf_templates')
});
=head1 DESCRIPTION
Modified: Catalyst-View-PDF-API2/trunk/lib/Catalyst/View/PDF/API2.pm
===================================================================
--- Catalyst-View-PDF-API2/trunk/lib/Catalyst/View/PDF/API2.pm 2009-08-28 13:23:16 UTC (rev 11265)
+++ Catalyst-View-PDF-API2/trunk/lib/Catalyst/View/PDF/API2.pm 2009-08-28 15:41:34 UTC (rev 11266)
@@ -29,7 +29,7 @@
In MyApp.pm, add a configuration item for the template include path:
__PACKAGE__->config('View::PDF' => {
- INCLUDE_PATH => __PACKAGE__->path_to('root','templates')
+ INCLUDE_PATH => __PACKAGE__->path_to('root','pdf_templates')
});
In your controller:
@@ -39,11 +39,8 @@
In F<root/templates/hello_pdf.tt>:
- [% pdf.prFont('Helvetica-Bold') %]
- [% pdf.prFontSize(20) %]
- [% pdf.prText(100,100,'Hello, World!') %]
+ [% pdf.corefont('Helvetica-Bold') %]
-
=head1 DESCRIPTION
Catalyst::View::PDF::API2 provides the facility to generate PDF files from
@@ -58,15 +55,20 @@
For example, to print the text I<Hello, World> at PDF coordinates 100,100,
use the following directive in your template:
- [% pdf.prText(100,100,'Hello, World') %]
+ [% f1 = pdf->corefont('Helvetica') %]
+ [% page = pdf.page %]
+ [% page.mediabox(595,842) %]
+ [% text = page.text %]
+ [% text.textlabel(50,800,$f1,20,'Hello, World',-hspace=>75) %]
+
Data held in the stash can be printed as follows:
$c->stash->{list} = ['one', 'two', 'three', 'four'];
[% y = 500 %]
[% FOREACH item IN list %]
- [% pdf.prText(100,y,item) %]
+ [% page.textlabel(100,y,$f1,20,item) %] ###### to fix
[% y = y - 13 %]
[% END %]
@@ -74,7 +76,7 @@
[% USE format %]
[% currency = format('£%.2f') %]
- [% pdf.prText(100,100,currency(10)) %]
+ [% page.textlabel(100,100,$f1,20,currency(10)) %]
=head2 Using existing PDF documents
@@ -85,9 +87,8 @@
blank receipt in Microsoft Word, convert this to PDF, then use PDF::API2
to add in details such as the order number and customer address.
- [% pdf.prForm('customer_receipt.pdf') %]
- [% pdf.prText(123,643,order.number) %]
- [% pdf.prText(299,643,order.date) %]
+ [% page.textlabel(123,643,$f1,12,order.number) %]
+ [% page.textlabel(299,643,$f1,12,order.date) %]
Note that the PDF document loaded by C<pdf.prForm> must be in the same
directory as your Template Toolkit template.
@@ -151,13 +152,10 @@
[% PROCESS $pdf_template %]
EOT
- my $tempfile = tmpnam();
+ # my $tempfile = tmpnam();
+ # $pdf = PDF::API2->open($tempfile);
#
- # $pdf = PDF::API2->new;
- # $pdf = PDF::API2->open('some.pdf');
-
- # prInitVars();
- # prFile($tempfile);
+ my $pdf = PDF::API2->new;
SEARCH: foreach my $path (@{$self->config->{INCLUDE_PATH}}) {
if (-e catfile($path,$c->stash->{pdf_template})) {
@@ -167,16 +165,9 @@
}
}
- prEnd();
-
- my $pdf;
- local $/ = undef;
- open PDF,'<',$tempfile;
- $pdf = (<PDF>);
- close PDF;
- unlink $tempfile;
-
- return $pdf;
+ my $pdfout = $pdf->stringify;
+ $pdf->end;
+ return $pdfout;
}
=head1 AUTHOR
Modified: Catalyst-View-PDF-API2/trunk/t/01-livetest.t
===================================================================
--- Catalyst-View-PDF-API2/trunk/t/01-livetest.t 2009-08-28 13:23:16 UTC (rev 11265)
+++ Catalyst-View-PDF-API2/trunk/t/01-livetest.t 2009-08-28 15:41:34 UTC (rev 11266)
@@ -2,7 +2,7 @@
use strict;
use warnings;
-use Test::More tests => 9;
+use Test::More tests => 4;
# setup library path
use FindBin qw($Bin);
Modified: Catalyst-View-PDF-API2/trunk/t/lib/TestApp/Controller/Root.pm
===================================================================
--- Catalyst-View-PDF-API2/trunk/t/lib/TestApp/Controller/Root.pm 2009-08-28 13:23:16 UTC (rev 11265)
+++ Catalyst-View-PDF-API2/trunk/t/lib/TestApp/Controller/Root.pm 2009-08-28 15:41:34 UTC (rev 11266)
@@ -8,76 +8,21 @@
use TestApp::View::PDF::API2;
-# your actions replace this one
sub main :Path { $_[1]->res->body('<h1>It works</h1>') }
sub pdf_test : Global {
my ($self, $c) = @_;
-
$c->stash( {
data => "This is a test page",
- pdf_template=>'test_page.tt2',
-
- };
+ pdf_template=>'test_pdf.tt2',
+ pdf_filename=>'test_pdf.pdf',
+ });
- my $view = new TestApp::View::Download::Plain;
+ my $view = new TestApp::View::PDF::API2;
$c->res->body(''.$view->render($c,'',$c->stash));
}
-sub _generate_csv_test_data {
- my ($self, $c) = @_;
- my $data = {
- 'array' => [
- ['a','b','c','d'],
- ['1','2','3','4'],
- [' ',"\n","\t",'!'],
- ['@',',','"',"'"]
- ],
- 'content' => '',
- };
-
- my $csv = Text::CSV->new ({
- quote_char => '"',
- escape_char => '"',
- sep_char => ',',
- eol => "\n",
- binary => 1,
- allow_loose_quotes => 1,
- allow_loose_escapes => 1,
- allow_whitespace => 1,
- });
-
- foreach my $row(@{$data->{'array'}}) {
- $csv->combine(@{$row});
- $data->{'content'} .= $csv->string();
- }
-
- return $data;
-}
-
-sub _generate_plain_test_data {
- my ($self, $c) = @_;
-
- my $content =<<"TEST";
-Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vestibulum tempus augue interdum neque. Curabitur ac libero. Aliquam faucibus mi a lectus. Sed et elit. Etiam volutpat suscipit quam. Phasellus sit am
-et odio. Sed faucibus magna quis diam. Nulla facilisi. Vivamus id erat porttitor elit aliquam ornare. Integer tincidunt varius lacus. Pellentesque sit amet mauris id ligula faucibus semper. Maecenas eros. Cur
-abitur hendrerit ligula ac nulla. Mauris dolor eros, pellentesque vel, varius porttitor, convallis non, lectus.
-
-Curabitur lacinia laoreet felis. Vivamus a urna. Aenean adipiscing aliquam velit. Aliquam varius bibendum nulla. Praesent quis tortor nec nisi scelerisque facilisis. Cras tristique. Phasellus mi libero, vulpu
-tate ac, hendrerit ac, iaculis at, elit. Pellentesque ac ante sit amet orci viverra condimentum. Fusce aliquam semper justo. Integer tincidunt. Pellentesque habitant morbi tristique senectus et netus et males
-uada fames ac turpis egestas. Nullam id lectus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Curabitur ut felis non mauris auctor viverra. Fusce dignissim. Morbi qui
-s magna.
-
-Proin scelerisque, lacus blandit consequat sodales, augue ligula laoreet quam, condimentum pretium velit diam eget lorem. Suspendisse potenti. Nam rhoncus mi vitae tortor. Sed eget neque. Fusce sagittis. Null
-a rutrum nibh et justo. Suspendisse dolor libero, rhoncus a, pretium id, feugiat eget, velit. Aenean accumsan. Nunc vel nulla. Mauris semper consectetuer velit. Vivamus semper. Nulla fermentum sapien nec feli
-s. Aenean iaculis felis nec ipsum. Aliquam tristique. Nam ut quam. Suspendisse ornare tristique arcu. Morbi pellentesque dolor eget lorem. Morbi ac nunc euismod lorem porttitor hendrerit. Lorem ipsum dolor si
-t amet, consectetuer adipiscing elit.
-TEST
-
- return $content;
-}
-
1;
More information about the Catalyst-commits
mailing list