comparison src/kaigo/Nk/fw4.pl @ 41:34a474fb83c3

add perori/porori/nk.
author pyon@macmini
date Wed, 04 Mar 2020 23:46:59 +0900
parents
children
comparison
equal deleted inserted replaced
40:c6df3bae683e 41:34a474fb83c3
1 ###########################################################
2 ## 入力ファイルを 4分割割付する
3 ## Last Change: 2020-01-21 火 14:34:27.
4 ###########################################################
5
6 use PDF::API2;
7
8 my ($in_file, $out_file) = ($ARGV[0], $ARGV[1]);
9 if ($in_file eq '' || $out_file eq '') {
10 print "bad arguments.\n";
11 exit;
12 }
13 my $tmpdir = $ARGV[2];
14 $tmpdir = '.' if $tmpdir eq '';
15
16 ## 入力ファイルの後半を上下反転させ 前半の下部に印字
17 my $in_odd = 0; # 奇数?
18
19 # 後半のページ(回転付き)
20 my $in_pdf = PDF::API2->open($in_file);
21 $in_odd = 1 if $in_pdf->pages % 2 == 1;
22
23 my $n = int($in_pdf->pages / 2) + 1;
24 $n++ if $in_odd;
25 my $lh_pdf = PDF::API2->new();
26 for my $p ( $n..$in_pdf->pages ) {
27 my $page = $lh_pdf->import_page($in_pdf, $p);
28 $page->rotate(180);
29 }
30 $lh_pdf->saveas("$tmpdir/lasthalf.pdf");
31 $lh_pdf->end;
32
33 # 移動
34 $lh_pdf = PDF::API2->open("$tmpdir/lasthalf.pdf");
35 my $lhm_pdf = PDF::API2->new();
36 for my $p ( 1..$lh_pdf->pages ) {
37 my $page = $lhm_pdf->page();
38 $page->mediabox('B5');
39 my $gfx = $page->gfx();
40 my $xo = $lhm_pdf->importPageIntoForm($lh_pdf, $p);
41 $gfx->formimage($xo, -230, 330, 1.0);
42 }
43 $lhm_pdf->saveas("$tmpdir/lasthalfmove.pdf");
44 $lhm_pdf->end;
45
46 # 割付
47 my $page;
48 my $new2_pdf = PDF::API2->new();
49 $lhm_pdf = PDF::API2->open("$tmpdir/lasthalfmove.pdf");
50 for my $p ( 1..$n-1 ) {
51 $page = $new2_pdf->page();
52 $page->mediabox('B5');
53
54 my $gfx = $page->gfx();
55 my $xo1 = $new2_pdf->importPageIntoForm($in_pdf, $p);
56 $gfx->formimage($xo1, -30, 0, 1.0);
57
58 last if $p == $n-1 && $in_odd;
59 my $xo2 = $new2_pdf->importPageIntoForm($lhm_pdf, $p);
60 $gfx->formimage($xo2, 0, -350, 1.0);
61 }
62
63 $new2_pdf->saveas("$tmpdir/2.pdf");
64 $new2_pdf->end;
65
66 ## 入力ファイルの後半を前半の右側に印字
67 $in_odd = 0; # 奇数?
68
69 # 後半のページ(回転なし)
70 $in_pdf = PDF::API2->open("$tmpdir/2.pdf");
71 $in_odd = 1 if $in_pdf->pages % 2 == 1;
72
73 $n = int($in_pdf->pages / 2) + 1;
74 $n++ if $in_odd;
75 $lh_pdf = PDF::API2->new();
76 for my $p ( $n..$in_pdf->pages ) {
77 my $page = $lh_pdf->import_page($in_pdf, $p);
78 #$page->rotate(180);
79 }
80 $lh_pdf->saveas("$tmpdir/lasthalf2.pdf");
81 $lh_pdf->end;
82
83 # 移動
84 $lh_pdf = PDF::API2->open("$tmpdir/lasthalf2.pdf");
85 $lhm_pdf = PDF::API2->new();
86 for my $p ( 1..$lh_pdf->pages ) {
87 my $page = $lhm_pdf->page();
88 $page->mediabox('B5');
89 my $gfx = $page->gfx();
90 my $xo = $lhm_pdf->importPageIntoForm($lh_pdf, $p);
91 $gfx->formimage($xo, 130, 0, 1.0);
92 }
93 $lhm_pdf->saveas("$tmpdir/lasthalf2move.pdf");
94 $lhm_pdf->end;
95
96 # 割付
97 my $new4_pdf = PDF::API2->new();
98 $lhm_pdf = PDF::API2->open("$tmpdir/lasthalf2move.pdf");
99 for my $p ( 1..$n-1 ) {
100 $page = $new4_pdf->page();
101 $page->mediabox('B5');
102
103 my $gfx = $page->gfx();
104 my $xo1 = $new4_pdf->importPageIntoForm($in_pdf, $p);
105 $gfx->formimage($xo1, 0, 0, 0.98);
106
107 last if $p == $n-1 && $in_odd;
108 my $xo2 = $new4_pdf->importPageIntoForm($lhm_pdf, $p);
109 $gfx->formimage($xo2, 125, 0, 0.98);
110 #$gfx->formimage($xo2, 122, 0, 0.98);
111 }
112
113 $new4_pdf->saveas($out_file);
114 $new4_pdf->end;
115