OSDN Git Service

サイドバイサイドでの表示に切り替えられるようにした。
[fswiki/fswiki.git] / tools / wiki2pdf.pl
1 #!/usr/local/bin/perl
2 ############################################################
3 #
4 # Wiki¥Õ¥©¡¼¥Þ¥Ã¥È¤«¤éPDF¤òÀ¸À®¤¹¤ë¥¹¥¯¥ê¥×¥È
5 #
6 ############################################################
7 use lib "$ENV{'FSWIKI_HOME'}/lib","$ENV{'FSWIKI_HOME'}/";
8 use plugin::pdf::PDFParser;
9 use Wiki;
10 use Util;
11 use Jcode;
12 use Cwd;
13
14 #===========================================================
15 # °ú¿ô¤¬Â­¤ê¤Ê¤¤
16 #===========================================================
17 if($#ARGV < 1){
18         die "wiki2pdf.pl sourcefile savefile\n";
19 }
20
21 #===========================================================
22 # ÊÑ¿ô¤Î½àÈ÷
23 #===========================================================
24 my $from    = $ARGV[0];
25 my $to      = $ARGV[1];
26 my $current = cwd();
27 chdir($ENV{'FSWIKI_HOME'});
28
29 my $url = $from;
30 $url =~ s/\?.*$//;
31 my $wiki = Wiki->new(CGI->new($url));
32
33 #===========================================================
34 # Wiki¥½¡¼¥¹¤ò¼èÆÀ
35 #===========================================================
36 my $source = "";
37 if(index($from,"http://")==0 || index($from,"https://")==0){
38         # HTTP·Ðͳ¤Ç¥½¡¼¥¹¤ò¼èÆÀ
39         $source = &Util::get_response($wiki,$from);
40 } else {
41         # ¥í¡¼¥«¥ë¥Õ¥¡¥¤¥ë¤«¤é¥½¡¼¥¹¤ò¼èÆÀ
42         chdir($current);
43         open(DATA,$from) or die "File Open Error :$from\n";
44         while(<DATA>){
45                 $source .= $_;
46         }
47         close(DATA);
48         chdir($ENV{'FSWIKI_HOME'});
49 }
50 &Jcode::convert(\$source,"euc");
51
52 #===========================================================
53 # PDFÀ¸À®
54 #===========================================================
55 my $parser = plugin::pdf::PDFParser->new($wiki,$from);
56 $parser->parse($source);
57
58 chdir($current);
59 $parser->save_file($to);
60
61 #===========================================================
62 # CGI.pm¤Î¥â¥Ã¥¯¥ª¥Ö¥¸¥§¥¯¥È
63 #===========================================================
64 package CGI;
65
66 sub new {
67         my $class = shift;
68         my $self  = {};
69         $self->{url} = shift;
70         return bless $self, $class;
71 }
72
73 sub url {
74         my $self = shift;
75         return $self;
76 }
77
78 sub get_session {
79         return undef;
80 }