一种解决方法是拆分图像生成和PDF转换。首先将图像转换convert
为A4 @ 300dpi(即3508x2479),然后使用sam2p将其转换为PDF,然后使用sam2p_pdf_scale将其转换为A4。
convert -rotate "90>" -scale 3508x2479 -border 64x64 -bordercolor white in.png out.png
sam2p out.png out.pdf
sam2p_pdf_scale 595 842 out.pdf
编辑:更完整的脚本:
#!/bin/sh
A4_WIDTH=2479
A4_HEIGHT=3508
H_MARGIN=64
V_MARGIN=64
WIDTH=$((${A4_WIDTH} - ${H_MARGIN} * 2))
HEIGHT=$((${A4_HEIGHT} - ${V_MARGIN} * 2))
for i in "$@"; do
TMP="/tmp/$(uuidgen).png"
echo "$i"
convert \
-rotate "90>" \
-scale "${WIDTH}x${HEIGHT}" \
-border "${H_MARGIN}x${V_MARGIN}" -bordercolor white \
-gravity center \
-extent "${A4_WIDTH}x${A4_HEIGHT}" \
-gravity center \
-font helvetica -pointsize 80 \
-fill white -draw \
"push graphic-context
translate $((${A4_WIDTH}/2 - 160)), 0
rotate 90
text -2,-2 '$i'
text -2,2 '$i'
text 2,-2 '$i'
text 2,2 '$i'
pop graphic-context
" \
-fill black -draw \
"push graphic-context
translate $((${A4_WIDTH}/2 - 160)), 0
rotate 90
text 0,0 '$i'
pop graphic-context
" \
"$i" "$TMP"
sam2p "$TMP" "${i}.pdf"
sam2p_pdf_scale 595 842 "${i}.pdf"
done
# EOF #