root/trunk/plagger/lib/Plagger/Plugin/Publish/PDF.pm

Revision 1173 (checked in by miyagawa, 14 years ago)

Merge from refactoring-planet. YAY!

  • Property svn:keywords set to Id Revision
Line 
1 package Plagger::Plugin::Publish::PDF;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use File::Spec;
6 use PDF::FromHTML;
7
8 sub register {
9     my($self, $context) = @_;
10     $context->register_hook(
11         $self,
12         'publish.feed' => \&feed,
13     );
14 }
15
16 sub feed {
17     my($self, $context, $args) = @_;
18
19     my $dir = $self->conf->{dir};
20     unless (-e $dir && -d _) {
21         mkdir $dir, 0755 or $context->error("mkdir $dir: $!");
22     }
23
24     my $file = File::Spec->catfile($dir, $args->{feed}->id . ".pdf");
25     my $body = $self->templatize('gmail_notify.tt', $args);
26     utf8::encode($body);
27
28     $context->log(info => "Writing PDF to $file");
29
30     my $pdf = PDF::FromHTML->new;
31     $pdf->load_file(\$body);
32     $pdf->convert();
33     $pdf->write_file($file);
34 }
35
36 1;
37
38 __END__
39
40 =head1 NAME
41
42 Plagger::Plugin::Publish::PDF - Publish feeds as PDF
43
44 =head1 SYNOPSIS
45
46   - module: Publish::PDF
47     config:
48       dir: /var/web/pdfs
49
50 =head1 DESCRIPTION
51
52 This plugin creates PDF files which you can be view and print with
53 Adobe Reader.
54
55 =head1 AUTHOR
56
57 Tatsuhiko Miyagawa
58
59 =head1 SEE ALSO
60
61 L<Plagger>, L<PDF::FromHTML>
62
63 =cut
Note: See TracBrowser for help on using the browser.