diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/kaigo/Nk/fw4.pl	Wed Mar 04 23:46:59 2020 +0900
@@ -0,0 +1,115 @@
+###########################################################
+## 入力ファイルを 4分割割付する
+##                   Last Change: 2020-01-21 火 14:34:27.
+###########################################################
+
+use PDF::API2;
+
+my ($in_file, $out_file) = ($ARGV[0], $ARGV[1]);
+if ($in_file eq '' || $out_file eq '') {
+	print "bad arguments.\n";
+	exit;
+}
+my $tmpdir = $ARGV[2];
+$tmpdir = '.' if $tmpdir eq '';
+
+## 入力ファイルの後半を上下反転させ 前半の下部に印字
+my $in_odd = 0;	# 奇数?
+
+# 後半のページ(回転付き)
+my $in_pdf = PDF::API2->open($in_file);
+$in_odd = 1 if $in_pdf->pages % 2 == 1;
+
+my $n = int($in_pdf->pages / 2) + 1;
+$n++ if $in_odd;
+my $lh_pdf = PDF::API2->new();
+for my $p ( $n..$in_pdf->pages ) {
+	my $page = $lh_pdf->import_page($in_pdf, $p);
+	$page->rotate(180);
+}
+$lh_pdf->saveas("$tmpdir/lasthalf.pdf");
+$lh_pdf->end;
+
+# 移動
+$lh_pdf = PDF::API2->open("$tmpdir/lasthalf.pdf");
+my $lhm_pdf = PDF::API2->new();
+for my $p ( 1..$lh_pdf->pages ) {
+	my $page = $lhm_pdf->page();
+	$page->mediabox('B5');
+	my $gfx = $page->gfx();
+	my $xo = $lhm_pdf->importPageIntoForm($lh_pdf, $p);
+	$gfx->formimage($xo, -230, 330, 1.0);
+}
+$lhm_pdf->saveas("$tmpdir/lasthalfmove.pdf");
+$lhm_pdf->end;
+
+# 割付
+my $page;
+my $new2_pdf = PDF::API2->new();
+$lhm_pdf = PDF::API2->open("$tmpdir/lasthalfmove.pdf");
+for my $p ( 1..$n-1 ) {
+	$page = $new2_pdf->page();
+	$page->mediabox('B5');
+
+	my $gfx = $page->gfx();
+	my $xo1 = $new2_pdf->importPageIntoForm($in_pdf, $p);
+	$gfx->formimage($xo1, -30, 0, 1.0);
+
+	last if $p == $n-1 && $in_odd;
+	my $xo2 = $new2_pdf->importPageIntoForm($lhm_pdf, $p);
+	$gfx->formimage($xo2, 0, -350, 1.0);
+}
+
+$new2_pdf->saveas("$tmpdir/2.pdf");
+$new2_pdf->end;
+
+## 入力ファイルの後半を前半の右側に印字
+$in_odd = 0;	# 奇数?
+
+# 後半のページ(回転なし)
+$in_pdf = PDF::API2->open("$tmpdir/2.pdf");
+$in_odd = 1 if $in_pdf->pages % 2 == 1;
+
+$n = int($in_pdf->pages / 2) + 1;
+$n++ if $in_odd;
+$lh_pdf = PDF::API2->new();
+for my $p ( $n..$in_pdf->pages ) {
+	my $page = $lh_pdf->import_page($in_pdf, $p);
+	#$page->rotate(180);
+}
+$lh_pdf->saveas("$tmpdir/lasthalf2.pdf");
+$lh_pdf->end;
+
+# 移動
+$lh_pdf = PDF::API2->open("$tmpdir/lasthalf2.pdf");
+$lhm_pdf = PDF::API2->new();
+for my $p ( 1..$lh_pdf->pages ) {
+	my $page = $lhm_pdf->page();
+	$page->mediabox('B5');
+	my $gfx = $page->gfx();
+	my $xo = $lhm_pdf->importPageIntoForm($lh_pdf, $p);
+	$gfx->formimage($xo, 130, 0, 1.0);
+}
+$lhm_pdf->saveas("$tmpdir/lasthalf2move.pdf");
+$lhm_pdf->end;
+
+# 割付
+my $new4_pdf = PDF::API2->new();
+$lhm_pdf = PDF::API2->open("$tmpdir/lasthalf2move.pdf");
+for my $p ( 1..$n-1 ) {
+	$page = $new4_pdf->page();
+	$page->mediabox('B5');
+
+	my $gfx = $page->gfx();
+	my $xo1 = $new4_pdf->importPageIntoForm($in_pdf, $p);
+	$gfx->formimage($xo1, 0, 0, 0.98);
+
+	last if $p == $n-1 && $in_odd;
+	my $xo2 = $new4_pdf->importPageIntoForm($lhm_pdf, $p);
+	$gfx->formimage($xo2, 125, 0, 0.98);
+	#$gfx->formimage($xo2, 122, 0, 0.98);
+}
+
+$new4_pdf->saveas($out_file);
+$new4_pdf->end;
+