Bagi siapa pun yang ingin mengambil 1 atau 2 pg pdf dan mengubahnya menjadi pdf dengan 2 salinan yang berdampingan dalam tampilan lanskap ( bagus untuk mencetak brosur ), lakukan:
Ubah input pdf 1 atau 2 pg menjadi output yang berisi duplikat halaman-halaman tersebut (1-pg pdf -> 2-pg pdf, 2-pg pdf -> 4-pg pdf, dll):
pdfunite in.pdf in.pdf out.pdf
Gabungkan pdf duplikat-salinan itu menjadi pdf 2-halaman-per-sisi-dalam-lanskap-tampilan, untuk mencetak brosur misalnya:
pdfnup out.pdf
Atau semua dalam satu baris:
pdfunite in.pdf in.pdf out.pdf && pdfnup out.pdf
Perhatikan bahwa out.pdf
adalah masukan untuk pdfnup
. File keluaran yang dihasilkan pdfnup
akan disebut " out-nup.pdf ".
Juga, perhatikan output dari pdfnup
perintah dan Anda akan melihat bentuk verbose dari perintah itu benar-benar berjalan, yang memberi Anda beberapa wawasan tentang opsi yang dapat Anda berikan. Rupanya pdfnup
menggunakan di pdfjam
bawah tenda:
pdfjam: Panggilan efektif untuk menjalankan pdfjam ini:
/usr/bin/pdfjam --suffix nup --nup '2x1' --landscape -- out.pdf -
Contoh:
PDF asli (1 pg biasa dalam tampilan Potret), " in.pdf ":
Final PDF (2 pgs berdampingan dalam tampilan Lansekap), " out-nup.pdf ":
- sekarang dapat dipotong menjadi dua bagian tengah untuk dibagikan sebagai selebaran
Fungsi Bash sederhana: make_flyer
Salin dan tempel fungsi bash ini ke bagian bawah file "~ / .bashrc" Anda untuk mendapatkan akses ke perintah sederhana dan mudah digunakan make flyer
:
# Description: outputs a landscape-oriented flyer pdf ("my/pdf/input--flyer.pdf") for each 1 or more pg input pdf ("my/pdf/input.pdf")
# - 1-pg input PDFs are converted to a 1-sided landscape, printable flyer that you cut down the center to make
# 2 flyers
# - 2-pg input PDFs are converted to a 2-sided landscape, printable flyer (flip on short edge when printing
# double-sided), and also cut down the middle to make 2 flyers
# - **3+ pg input PDFs**: using `pdfnup` directly in this case would make more sense, since this function will
# otherwise unneccessarily create 2 copies
# - 3 and 4-pg input PDFs are converted to a single piece of paper, double-sided, flipped on short edge, x 2 copies.
# No cutting is necessary
# - 5+ pg input PDFs simply require half as much paper to print is all since you get 2 pages per side of paper;
# they do NOT print like booklets, but rather just as a landscape-printed, flipped-on-short-edge bundle of pages
# (like a deck of slides). You get *2 copies* per print though, so just print half the pages.
make_flyer() {
num_args=$# # see: https://stackoverflow.com/questions/4423306/how-do-i-find-the-number-of-arguments-passed-to-a-bash-script/4423321#4423321
suffix="flyer"
loop_cnt=0
for inputpdf in "$@"
do
((loop_cnt++))
echo "==== CONVERTING PDF $loop_cnt OF $num_args ===="
echo " INPUT: \"$inputpdf\""
# Strip off the .pdf extension from the input path, while retaining the rest of the path
# - See: https://stackoverflow.com/questions/12152626/how-can-i-remove-the-extension-of-a-filename-in-a-shell-script/32584935#32584935
input_path_base="$(echo "$inputpdf" | rev | cut -f 2- -d '.' | rev)"
input_file_base="$(basename "$inputpdf" .pdf)"
temp_pdf="${input_path_base}-.pdf" # is "input_path_base-.pdf"
echo " OUTPUT: \"$(pwd)/${input_file_base}--${suffix}.pdf\""
# Convert a single 1-pg pdf into a temporary 2-pg pdf
pdfunite "$inputpdf" "$inputpdf" "$temp_pdf"
# Lay out the temporary 2-pg pdf into a side-by-side 1-sided flyer to print; creates "input_path_base--flyer.pdf"
# Note that `pdfnup` places the output from this operation in the location from where you call this script
# (ie: in your `pwd` [Present Working Directory])!--NOT the location where temp_pdf is located!
pdfnup "$temp_pdf" --suffix $suffix
# Delete the temporary 2-pg pdf, called "input_path_base-.pdf", thereby leaving only the original
# "input_path_base.pdf" and the new "input_path_base--flyer.pdf"
rm "$temp_pdf"
done
}
alias make_flyer_help='echo -e "Ex usage: make_flyer \"path/to/inputpdf.pdf\" - Creates a landscape-side-by-side flyer version called \"inputpdf--flyer.pdf\"\n *in your pwd* from a 1 or 2 pg input pdf called \"path/to/inputpdf.pdf\". Accepts multiple arguments. Ex:\n make_flyer \"path/to/inputpdf1.pdf\" \"path/to/inputpdf2.pdf\""'
Contoh penggunaan:
make_flyer "path/to/inputpdf1.pdf" "path/to/inputpdf2.pdf"
Lihat Info bantuan:
make_flyer_help
Keluaran:
$ make_flyer_help
Ex usage: make_flyer "path/to/inputpdf.pdf" - Creates a landscape-side-by-side flyer version called "inputpdf--flyer.pdf"
*in your pwd* from a 1 or 2 pg input pdf called "path/to/inputpdf.pdf". Accepts multiple arguments. Ex:
make_flyer "path/to/inputpdf1.pdf" "path/to/inputpdf2.pdf"
Referensi:
- https://superuser.com/a/948095/425838
- https://stackoverflow.com/a/11280219/4561887
Terkait:
- https://askubuntu.com/questions/214538/printing-in-booklet-format/1095789#1095789
Referensi Bash:
- Bash Cara meneruskan argumen ke fungsi bash: https://bash.cyberciti.biz/guide/Pass_arguments_into_a_function
- Bash Concatenate string: https://linuxize.com/post/bash-concatenate-strings/
- Bash mengeksekusi cmd yang disimpan sebagai string! https://stackoverflow.com/questions/2005192/how-to-execute-a-bash-command-stored-as-a-string-with-quotes-and-asterisk
- Bash iterate atas semua input ke cmd: https://stackoverflow.com/questions/255898/how-to-iterate-over-arguments-in-a-bash-script/255913#255913
- Bash passing parameter berfungsi: https://stackoverflow.com/questions/6212219/passing-parameters-to-a-bash-function/6212408#6212408
- Bagaimana cara mengubah pdf 1-pg menjadi brosur [ans saya sendiri!]: Bagaimana cara mengubah 1 halaman PDF menjadi 2 halaman per lembar PDF?