Skip to content

Instantly share code, notes, and snippets.

@ytnobody
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ytnobody/e109da2730218cefc97f to your computer and use it in GitHub Desktop.
Save ytnobody/e109da2730218cefc97f to your computer and use it in GitHub Desktop.
mishima.pm #1 向けの仕込み
#!/usr/bin/env perl
use strict;
use warnings;
use Furl;
use File::Temp 'tempdir';
use File::Spec;
use File::Slurp;
use Vector::QRCode::IntoPDF;
### PDF保存先指定。指定がなければ、"./sushi-qr.pdf" になる。
use constant DEST_PATH => File::Spec->catfile(qw| . sushi-qr.pdf |);
### 作業用ディレクトリを作る。スクリプト終了時に削除される。
my $workdir = tempdir(CLEANUP => 1);
### 適当なPDFをダウンロード
my $furl = Furl->new;
my $res = $furl->get('http://www.akindo-sushiro.co.jp/content/pdf/takeout/menu_single_east01.pdf');
die $res->status_line unless $res->is_success; # 失敗したらエラー
### ダウンロードしたPDFを保存
my $temp_file = File::Spec->catfile($workdir, 'source.pdf'); # 保存先
write_file($temp_file, $res->content);
### PDFの1ページ目に、10cm角のQRコードを貼り付ける
my $vector = Vector::QRCode::IntoPDF->new(pdf_file => $temp_file);
$vector->imprint(
page => 1, x => 200, y => 200,
size => 10, unit => 'cm',
text => 'http://www.slideshare.net/ytnobody/mishimapm-1',
);
### 出来上がったPDFを、最初に指定した場所に保存
$vector->save(DEST_PATH);
printf "へい、おまち!\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment