|
Revision 1721
(checked in by miyagawa, 2 years ago)
|
Publish::PDF accepts filename parameter
|
- 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 |
use Plagger::Util; |
|---|
| 8 |
|
|---|
| 9 |
sub register { |
|---|
| 10 |
my($self, $context) = @_; |
|---|
| 11 |
$context->register_hook( |
|---|
| 12 |
$self, |
|---|
| 13 |
'publish.feed' => \&feed, |
|---|
| 14 |
); |
|---|
| 15 |
} |
|---|
| 16 |
|
|---|
| 17 |
sub feed { |
|---|
| 18 |
my($self, $context, $args) = @_; |
|---|
| 19 |
|
|---|
| 20 |
my $dir = $self->conf->{dir}; |
|---|
| 21 |
unless (-e $dir && -d _) { |
|---|
| 22 |
mkdir $dir, 0755 or $context->error("mkdir $dir: $!"); |
|---|
| 23 |
} |
|---|
| 24 |
|
|---|
| 25 |
my $file = Plagger::Util::filename_for($args->{feed}, $self->conf->{filename} || '%i.pdf'); |
|---|
| 26 |
my $path = File::Spec->catfile($dir, $file); |
|---|
| 27 |
my $body = $self->templatize('html.tt', $args); |
|---|
| 28 |
utf8::encode($body); |
|---|
| 29 |
|
|---|
| 30 |
$context->log(info => "Writing PDF to $path"); |
|---|
| 31 |
|
|---|
| 32 |
my $pdf = PDF::FromHTML->new; |
|---|
| 33 |
$pdf->load_file(\$body); |
|---|
| 34 |
$pdf->convert(); |
|---|
| 35 |
$pdf->write_file($path); |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
1; |
|---|
| 39 |
|
|---|
| 40 |
__END__ |
|---|
| 41 |
|
|---|
| 42 |
=head1 NAME |
|---|
| 43 |
|
|---|
| 44 |
Plagger::Plugin::Publish::PDF - Publish feeds as PDF |
|---|
| 45 |
|
|---|
| 46 |
=head1 SYNOPSIS |
|---|
| 47 |
|
|---|
| 48 |
- module: Publish::PDF |
|---|
| 49 |
config: |
|---|
| 50 |
dir: /var/web/pdfs |
|---|
| 51 |
|
|---|
| 52 |
=head1 DESCRIPTION |
|---|
| 53 |
|
|---|
| 54 |
This plugin creates PDF files which you can be view and print with |
|---|
| 55 |
Adobe Reader. |
|---|
| 56 |
|
|---|
| 57 |
=head1 AUTHOR |
|---|
| 58 |
|
|---|
| 59 |
Tatsuhiko Miyagawa |
|---|
| 60 |
|
|---|
| 61 |
=head1 SEE ALSO |
|---|
| 62 |
|
|---|
| 63 |
L<Plagger>, L<PDF::FromHTML> |
|---|
| 64 |
|
|---|
| 65 |
=cut |
|---|