WebEditor/OldFeatures/MakePDF.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« WebEditor/OldFeatures/AdminHtdig.pm ↑ Summary WebEditor/OldFeatures/XMenus.pm »
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<WebEditor::OldFeatures::MakePS> module in
30 conjunction with B<ps2pdf> from the B<ghostscript> distribution to
31 create PDF output from a web.editor site.
32  
33 C<makepdf> and C<makepdf_send> pass all arguments to C<makeps> and
34 C<makeps_send>, respectively.
35  
36 =head1 AUTHOR
37  
38 Slaven Rezic
39  
40 =cut
41  
42 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
44 $VERSION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/);
45  
46 1 ▶use File::Temp qw(tempfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 0 ▶use WebEditor::OldFeatures::MakePS;
Subroutine BEGIN: called CC=1 SCAR=2.6
49  
50 sub makepdf {
51 my($self, %args) = @_;
52  
53 my $debug = $args{-debug};
54  
55 my($psfh,$pstmp) = tempfile(SUFFIX => ".ps",
56 UNLINK => !$debug);
57 my($pdffh,$pdftmp) = tempfile(SUFFIX => ".pdf",
58 UNLINK => !$debug);
59 {
60 local $args{-o} = $pstmp;
61 WebEditor::OldFeatures::MakePS::makeps($self, %args);
62 }
63  
64 my @cmd = ("ps2pdf");
65 push @cmd, "-dCompatibilityLevel=1.2"; # or 1.3 or 1.4 ...
66 push @cmd, "-dPDFSETTINGS=/printer";
67 push @cmd, $pstmp, $pdftmp;
68  
69 warn "@cmd\n" if $debug;
70 system(@cmd) and die "Error while doing @cmd";
71  
72 my $pdf;
73  
74 if (!defined $args{-o}) {
75 open(FH, $pdftmp) or die "Can't open $pdftmp: $!";
76 local $/ = undef;
77 $pdf = <FH>;
78 close FH;
79 close $pdffh;
80 }
81  
82 unless ($debug) {
83 unlink $pstmp;
84 unlink $pdftmp;
85 }
86  
87 $pdf;
88 }
89  
90 sub makepdf_send {
91 my($self, %args) = @_;
92  
93 my $pdf = makepdf($self, %args);
94  
95 my $q = CGI->new;
96 print $q->header("application/pdf");
97 print $pdf;
98 return 1;
99 }
100  
101 1;
« WebEditor/OldFeatures/AdminHtdig.pm ↑ Summary WebEditor/OldFeatures/XMenus.pm »