File Coverage

blib/lib/WebEditor/OldFeatures/MakePDF.pm
Criterion Covered Total %
statement 12 42 28.5
branch 0 10 0.0
condition n/a
subroutine 4 6 66.6
pod 0 2 0.0
total 16 60 26.6


line stmt bran cond sub pod time code
1             # -*- perl -*-
2              
3             #
4             # $Id: MakePDF.pm,v 1.4 2004/03/08 10:43:59 eserte Exp $
5             # Author: Slaven Rezic
6             #
7             # Copyright (C) 2004 Slaven Rezic. All rights reserved.
8             # This package is free software; you can redistribute it and/or
9             # modify it under the same terms as Perl itself.
10             #
11             # Mail: slaven@rezic.de
12             # WWW: http://www.rezic.de/eserte/
13             #
14              
15             package WebEditor::OldFeatures::MakePDF;
16              
17             =head1 NAME
18              
19             WebEditor::OldFeatures::MakePDF - create a PDF file from the site
20              
21             =head1 SYNOPSIS
22              
23             use WebEditor::OldFeatures::MakePDF;
24             WebEditor::OldFeatures::MakePDF::makepdf($webeditor_oldcontroller_object, %args);
25             WebEditor::OldFeatures::MakePDF::makepdf_send($webeditor_oldcontroller_object, %args);
26              
27             =head1 DESCRIPTION
28              
29             This module uses the L module in
30             conjunction with B from the B distribution to
31             create PDF output from a web.editor site.
32              
33             C and C pass all arguments to C and
34             C, respectively.
35              
36             =head1 AUTHOR
37              
38             Slaven Rezic
39              
40             =cut
41              
42 1     1   1669 use strict;
  1         3  
  1         45  
43 1     1   7 use vars qw($VERSION);
  1         2  
  1         94  
44             $VERSION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/);
45              
46 1     1   5 use File::Temp qw(tempfile);
  1         3  
  1         66  
47              
48 1     1   7 use WebEditor::OldFeatures::MakePS;
  1         3  
  1         468  
49              
50             sub makepdf {
51 0     0 0   my($self, %args) = @_;
52              
53 0           my $debug = $args{-debug};
54              
55 0           my($psfh,$pstmp) = tempfile(SUFFIX => ".ps",
56             UNLINK => !$debug);
57 0           my($pdffh,$pdftmp) = tempfile(SUFFIX => ".pdf",
58             UNLINK => !$debug);
59             {
60 0           local $args{-o} = $pstmp;
  0            
61 0           WebEditor::OldFeatures::MakePS::makeps($self, %args);
62             }
63              
64 0           my @cmd = ("ps2pdf");
65 0           push @cmd, "-dCompatibilityLevel=1.2"; # or 1.3 or 1.4 ...
66 0           push @cmd, "-dPDFSETTINGS=/printer";
67 0           push @cmd, $pstmp, $pdftmp;
68              
69 0 0         warn "@cmd\n" if $debug;
70 0 0         system(@cmd) and die "Error while doing @cmd";
71              
72 0           my $pdf;
73              
74 0 0         if (!defined $args{-o}) {
75 0 0         open(FH, $pdftmp) or die "Can't open $pdftmp: $!";
76 0           local $/ = undef;
77 0           $pdf = ;
78 0           close FH;
79 0           close $pdffh;
80             }
81              
82 0 0         unless ($debug) {
83 0           unlink $pstmp;
84 0           unlink $pdftmp;
85             }
86              
87 0           $pdf;
88             }
89              
90             sub makepdf_send {
91 0     0 0   my($self, %args) = @_;
92              
93 0           my $pdf = makepdf($self, %args);
94              
95 0           my $q = CGI->new;
96 0           print $q->header("application/pdf");
97 0           print $pdf;
98 0           return 1;
99             }
100              
101             1;