LoginSignup
0
1

More than 5 years have passed since last update.

moodleからフッター付のまとめpdfを作成

Last updated at Posted at 2017-05-11

注意

v2の自記事があります.
moodleからヘッダー付のまとめpdfを作成 (v2)
http://qiita.com/keitasumiya/items/665453b54a9ffb4cfdaf

はじめに

open sourceのmoodleという授業支援システムからダウンロードした提出物のファイルをフッター付でpdfにまとめるtipsです.
出来具合はちょっと不格好です.

念のためいっておきますが, 下記の学生番号等はもちろんダミーの適当なものにしてあります.
本記事内のダミーならば動くようにはしてありますが, 場合によっては必要に応じて変更してください.

また, pdftkというcommandを使用していますので, 未installであれば
http://qiita.com/keitasumiya/items/83756caf2865291707fb
等を参考にinstallしてください.

任意ファイルをpdfに変換するためにはacrobat
Acrobat Pro DC 2015.006.30306
を使用しています.
commandでいければいいんですが...
どなたかご存知でしたら教えていただけると嬉しいです.

git

準備(ダウンロード)

課題, 評定, 評定操作, 全ての提出をダウンロードする

でfileをダウンロード.
スクリーンショット 2017-05-11 15.56.29.png

課題, 評定, 評定操作, 評定表を表示する, 評定者レポート, テキストファイル

で評定者リストのcsvをダウンロード.
スクリーンショット 2017-05-11 15.59.51.png

初期設定

ダウンロードしてきたファイルを下記のように配置

対象のfileの拡張子は何でも良い

現在のdirectoryは

$ pwd
/Users/hogeuser/Downloads/pdf_test/editted

にいると仮定している.

$ tree
.
├── file
│   ├── Sato\ Jiro_123102_assignsubmission_file_課?\214.pdf
│   ├── Yamada\ Taro_123001_assignsubmission_file_abc?\217?\201?課?\214.docx
│   └── 山?\234?\ ?\211?\203\216_123023_assignsubmission_onlinetext_onlinetext.html
└── students
    └── 987654_2017\ ?\225?\232-20170510_0831-comma_separated.csv

スクリーンショット 2017-05-11 13.50.00.png

csvの中身:

987654_2017_評定-20170510_0831-comma_separated.csv
名,姓,IDナンバー,所属組織,部署,メールアドレス,"課題a (実データ)","課題b (実データ)","課題c (実データ)","コース合計 (実データ)",このコースからの最新ダウンロード
Taro,Yamada,,,,1ab9999t@hogehoge.jp,-,-,-,-,1234567890
Jiro,Sato,,,,1hg9980j@hogehoge.jp,-,-,-,-,1234567890
Naoko,Kimura,,,,1cd9997n@hogehoge.jp,-,-,-,-,1234567890
三郎,山本,,,,1ef9990s@hogehoge.jp,-,-,-,-,1234567890

commands

csvをstudent.txtにして, 1行目のlabelを消す

$ cd students/

$ sed -e '1d' *.csv > students.txt
$ tree ..
..
├── file
│   ├── Sato\ Jiro_123102_assignsubmission_file_課?\214.pdf
│   ├── Yamada\ Taro_123001_assignsubmission_file_abc?\217?\201?課?\214.docx
│   └── 山?\234?\ ?\211?\203\216_123023_assignsubmission_onlinetext_onlinetext.html
└── students
    ├── 987654_2017\ ?\225?\232-20170510_0831-comma_separated.csv
    └── students.txt

スクリーンショット 2017-05-11 13.54.09.png

students.txt
Taro,Yamada,,,,1ab9999t@hogehoge.jp,-,-,-,-,1234567890
Jiro,Sato,,,,1hg9980j@hogehoge.jp,-,-,-,-,1234567890
Naoko,Kimura,,,,1ef9997n@hogehoge.jp,-,-,-,-,1234567890
三郎,山本,,,,1ef9990s@hogehoge.jp,-,-,-,-,1234567890

student情報の整理

$ cat students.txt | awk -F',| ' '{print $2"_"$1"_"substr($6,2,6)}' > students_edited.txt
students_edited.txt
Yamada_Taro_ab9999
Sato_Jiro_hg9980
Kimura_Naoko_ef9997
山本_三郎_ef9990

スペースの削除

$ cd ../file/

$ ls | awk '{a=$0; gsub(" ","_",a); print "mv \""$0"\"",a}' | sh
$ tree ..
..

├── file
│   ├── Sato_Jiro_123102_assignsubmission_file_課?\214.pdf
│   ├── Yamada_Taro_123001_assignsubmission_file_abc?\217?\201?課?\214.docx
│   └── 山?\234?_?\211?\203\216_123023_assignsubmission_onlinetext_onlinetext.html
└── students
    ├── 987654_2017\ ?\225?\232-20170510_0831-comma_separated.csv
    ├── students.txt
    └── students_edited.txt

fileの名前の変更

$ ls | sed 's/\./zzzz/g' | awk -F'_|zzzz| ' '{a=$0; gsub("zzzz",".",a); print "mv",a,$1"_"$2"."$NF}' | sh
$ tree ..
..
├── file
│   ├── Sato_Jiro.pdf
│   ├── Yamada_Taro.docx
│   └── 山?\234?_?\211?\203\216.html
└── students
    ├── 987654_2017\ ?\225?\232-20170510_0831-comma_separated.csv
    ├── students.txt
    └── students_edited.txt

file名に学生番号を追加

$ for i in `ls`; do echo $i" "`grep ${i%.*} ../students/students_edited.txt` | sed 's/\./ /g' |awk -F' |_' '{print "mv "$1"_"$2"."$3" "$6"_"$1$2"."$3}' | sh; done
$ tree ..
..
├── file
│   ├── ab9999_YamadaTaro.docx
│   ├── ef9990_山?\234??\211?\203\216.html
│   └── hg9980_SatoJiro.pdf
└── students
    ├── 987654_2017\ ?\225?\232-20170510_0831-comma_separated.csv
    ├── students.txt
    └── students_edited.txt

acrobatでfile内のファイルを個別にpdf化

ツール
pdfを作成
複数のファイル
複数のpdfファイルを作成
次へ
file内のファイルをドラック&ドロップ
OK
OK

スクリーンショット 2017-05-11 14.35.55.png

pdfを別のdirectoryに移す

$ mkdir ../pdf

$ cp *.pdf ../pdf/
$ tree ..
..
├── file
│   ├── ab9999_YamadaTaro.docx
│   ├── ab9999_YamadaTaro.pdf
│   ├── ef9990_山?\234??\211?\203\216.html
│   ├── ef9990_山?\234??\211?\203\216.pdf
│   └── hg9980_SatoJiro.pdf
├── pdf
│   ├── ab9999_YamadaTaro.pdf
│   ├── ef9990_山?\234??\211?\203\216.pdf
│   └── hg9980_SatoJiro.pdf
└── students
    ├── 987654_2017\ ?\225?\232-20170510_0831-comma_separated.csv
    ├── students.txt
    └── students_edited.txt

フッター用のtxtの作成

$ cd ../pdf/

$ ls | awk -F'_| ' '{print "touch","____________________________________________________________________________"$1".txt"}' | sh

$ mkdir ../txt

$ ls | grep .txt | awk '{print "mv",$0,"../txt"}' | sh
$ tree ..
..
├── file
│   ├── ab9999_YamadaTaro.docx
│   ├── ab9999_YamadaTaro.pdf
│   ├── ef9990_山?\234??\211?\203\216.html
│   ├── ef9990_山?\234??\211?\203\216.pdf
│   └── hg9980_SatoJiro.pdf
├── pdf
│   ├── ab9999_YamadaTaro.pdf
│   ├── ef9990_山?\234??\211?\203\216.pdf
│   └── hg9980_SatoJiro.pdf
├── students
│   ├── 987654_2017\ ?\225?\232-20170510_0831-comma_separated.csv
│   ├── students.txt
│   └── students_edited.txt
└── txt
    ├── ____________________________________________________________________________ab9999.txt
    ├── ____________________________________________________________________________ef9990.txt
    └── ____________________________________________________________________________hg9980.txt

acrobatでtxt内のファイルを個別にpdf化

ツール
pdfを作成
複数のファイル
複数のpdfファイルを作成
次へ
txt内のファイルをドラック&ドロップ
OK
OK

フッター用pdfを移す

$ mkdir ../txt_pdf

$ cd ../txt

$ ls | grep .pdf | awk '{print "mv",$0,"../txt_pdf"}' | sh
$ tree ..
..
├── file
│   ├── ab9999_YamadaTaro.docx
│   ├── ab9999_YamadaTaro.pdf
│   ├── ef9990_山?\234??\211?\203\216.html
│   ├── ef9990_山?\234??\211?\203\216.pdf
│   └── hg9980_SatoJiro.pdf
├── pdf
│   ├── ab9999_YamadaTaro.pdf
│   ├── ef9990_山?\234??\211?\203\216.pdf
│   └── hg9980_SatoJiro.pdf
├── students
│   ├── 987654_2017\ ?\225?\232-20170510_0831-comma_separated.csv
│   ├── students.txt
│   └── students_edited.txt
├── txt
│   ├── ____________________________________________________________________________ab9999.txt
│   ├── ____________________________________________________________________________ef9990.txt
│   └── ____________________________________________________________________________hg9980.txt
└── txt_pdf
    ├── ____________________________________________________________________________ab9999.pdf
    ├── ____________________________________________________________________________ef9990.pdf
    └── ____________________________________________________________________________hg9980.pdf

フッターpdfと目的のファイルを重ねる

$ cd ../pdf

$ mkdir ../output_pdf

$ ls | awk -F'_| ' '{print "pdftk",$0,"background ../txt_pdf/____________________________________________________________________________"$1".pdf","output ../output_pdf/"$1".pdf"}' | sh
$ tree ..
..
├── file
│   ├── ab9999_YamadaTaro.docx
│   ├── ab9999_YamadaTaro.pdf
│   ├── ef9990_山?\234??\211?\203\216.html
│   ├── ef9990_山?\234??\211?\203\216.pdf
│   └── hg9980_SatoJiro.pdf
├── output_pdf
│   ├── ab9999.pdf
│   ├── ef9990.pdf
│   └── hg9980.pdf
├── pdf
│   ├── ab9999_YamadaTaro.pdf
│   ├── ef9990_山?\234??\211?\203\216.pdf
│   └── hg9980_SatoJiro.pdf
├── students
│   ├── 987654_2017\ ?\225?\232-20170510_0831-comma_separated.csv
│   ├── students.txt
│   └── students_edited.txt
├── txt
│   ├── ____________________________________________________________________________ab9999.txt
│   ├── ____________________________________________________________________________ef9990.txt
│   └── ____________________________________________________________________________hg9980.txt
└── txt_pdf
    ├── ____________________________________________________________________________ab9999.pdf
    ├── ____________________________________________________________________________ef9990.pdf
    └── ____________________________________________________________________________hg9980.pdf

最後の重ねるコマンドは, 本当はフッターpdfを上からstampしたい:

$ ls | awk -F'_| ' '{print "pdftk",$0,"stamp ../txt_pdf/____________________________________________________________________________"$1".pdf","output ../output_pdf/"$1".pdf"}' | sh

ただしこうすると, txtから作成したフッターpdfに白背景があるらしく, すべてフッターpdfに上書きされてしまうのが難点.
フッターpdfの作成方法を見直す必要がある.

結果のpdfをmergeする

$ cd ../output

$ pdftk *.pdf output ../output.pdf

この結合作業はacrobatの

ツール
pdfを作成
複数のファイル
ファイルを結合
次へ
txt内のファイルをドラック&ドロップ
ファイルを結合

でも良い.

$ tree ..
..
├── file
│   ├── ab9999_YamadaTaro.docx
│   ├── ab9999_YamadaTaro.pdf
│   ├── ef9990_山?\234??\211?\203\216.html
│   ├── ef9990_山?\234??\211?\203\216.pdf
│   └── hg9980_SatoJiro.pdf
├── output.pdf
├── output_pdf
│   ├── ab9999.pdf
│   ├── ef9990.pdf
│   └── hg9980.pdf
├── pdf
│   ├── ab9999_YamadaTaro.pdf
│   ├── ef9990_山?\234??\211?\203\216.pdf
│   └── hg9980_SatoJiro.pdf
├── students
│   ├── 987654_2017\ ?\225?\232-20170510_0831-comma_separated.csv
│   ├── students.txt
│   └── students_edited.txt
├── txt
│   ├── ____________________________________________________________________________ab9999.txt
│   ├── ____________________________________________________________________________ef9990.txt
│   └── ____________________________________________________________________________hg9980.txt
└── txt_pdf
    ├── ____________________________________________________________________________ab9999.pdf
    ├── ____________________________________________________________________________ef9990.pdf
    └── ____________________________________________________________________________hg9980.pdf

このoutput.pdfがフッター付の完成ファイルです.

完成物

スクリーンショット 2017-05-11 16.12.45.png
スクリーンショット 2017-05-11 16.14.46.png

まとめ

初期設定

$ pwd
/Users/hogeuser/Downloads/pdf_test/editted
$ tree
.
├── file
│   ├── Sato\ Jiro_123102_assignsubmission_file_課?\214.pdf
│   ├── Yamada\ Taro_123001_assignsubmission_file_abc?\217?\201?課?\214.docx
│   └── 山?\234?\ ?\211?\203\216_123023_assignsubmission_onlinetext_onlinetext.html
└── students
    └── 987654_2017\ ?\225?\232-20170510_0831-comma_separated.csv

手順

cd students/
sed -e '1d' *.csv > students.txt

cat students.txt | awk -F',| ' '{print $2"_"$1"_"substr($6,2,6)}' > students_edited.txt

cd ../file/
ls | awk '{a=$0; gsub(" ","_",a); print "mv \""$0"\"",a}' | sh

ls | sed 's/\./zzzz/g' | awk -F'_|zzzz| ' '{a=$0; gsub("zzzz",".",a); print "mv",a,$1"_"$2"."$NF}' | sh

for i in `ls`; do echo $i" "`grep ${i%.*} ../students/students_edited.txt` | sed 's/\./ /g' |awk -F' |_' '{print "mv "$1"_"$2"."$3" "$6"_"$1$2"."$3}' | sh; done

acrobatでfile内のファイルを個別にpdf化

mkdir ../pdf
cp *.pdf ../pdf/

cd ../pdf/
ls | awk -F'_| ' '{print "touch","____________________________________________________________________________"$1".txt"}' | sh
mkdir ../txt
ls | grep .txt | awk '{print "mv",$0,"../txt"}' | sh

acrobatでtxt内のファイルを個別にpdf化

mkdir ../txt_pdf
cd ../txt
ls | grep .pdf | awk '{print "mv",$0,"../txt_pdf"}' | sh

cd ../pdf
mkdir ../output_pdf
ls | awk -F'_| ' '{print "pdftk",$0,"background ../txt_pdf/____________________________________________________________________________"$1".pdf","output ../output_pdf/"$1".pdf"}' | sh

cd ../output_pdf
pdftk *.pdf output ../output.pdf

refs

1行消す
http://takuya-1st.hatenablog.jp/entry/2014/08/07/012422

acrobatでのファイル結合
https://helpx.adobe.com/jp/acrobat/using/merging-files-single-pdf.html

acrobatでのヘッター, フッター
https://helpx.adobe.com/jp/acrobat/using/add-headers-footers-pdfs.html

iphotoをつかったファイル名付加印刷
https://discussionsjapan.apple.com/thread/10085126?tstart=0

pdftk 気をつけること
http://qiita.com/keitasumiya/items/83756caf2865291707fb

pdftk
http://nwpct1.hatenablog.com/entry/2013/12/14/192914
https://www.pdflabs.com/tools/pdftk-server/
http://www.slab.ces.kyutech.ac.jp/~saitoh/ja/pdftk.html

空ファイルを作る
http://qiita.com/kaw/items/3bbd6c2da1dde92bd8e5

コマンド: 過去の自分のを見て思い出す用
http://qiita.com/keitasumiya/items/7df5014a8c00c64ceda3
http://qiita.com/keitasumiya/items/7e63fffab0ebf7516317

awk
https://codezine.jp/article/detail/7912
http://qiita.com/sand_bash/items/3d746c7e292908c6167e

拡張子取り出し
http://d.hatena.ne.jp/zariganitosh/20100921/get_file_name_ext_dir
http://pgman.exblog.jp/14865819/
http://qiita.com/mriho/items/b30b3a33e8d2e25e94a8

sed
http://qiita.com/takc923/items/bdce8c1a2126cac52492

grep
https://hydrocul.github.io/wiki/commands/grep.html

imagemagick
http://qiita.com/hsagae/items/1b72fb9f3d6024ba46f0
http://www.imagemagick.org/Usage/annotating/

acrobat commandline
https://www.lifedesignedit.com/use_adobe_pdf_command_line_options

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1