Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
バッチで作る、劣化版pdfcrop
@echo off
setlocal
set FROM=%~n1
set TO=%~n2
set TPX=_tcpc
if not exist %FROM%.pdf exit /B
if "%TO%"=="" exit /B
if exist %TO%.pdf del %TO%.pdf
if exist %TO%.pdf del exit /B
gswin32c -dBATCH -dNOPAUSE -q -sDEVICE=bbox %FROM%.pdf 2>%TPX%1.tex
echo {\catcode37=13 \catcode13=12 \def^^^^25^^^^25#1: #2^^^^M{\gdef\do{\proc[#2]}}\input _tcpc1.tex\relax}{}^
\def\proc[#1 #2 #3 #4]{\pdfhorigin-#1bp \pdfvorigin#2bp \pdfpagewidth=\dimexpr#3bp-#1bp\relax\pdfpageheight\dimexpr#4bp-#2bp\relax}\do^
\setbox0=\hbox{\pdfximage mediabox{%FROM%.pdf}\pdfrefximage\pdflastximage}^
\ht0=\pdfpageheight \shipout\box0\relax \end >%TPX%2.tex
pdftex -no-shell-escape -batchmode %TPX%2.tex
if not exist %TPX%2.pdf exit /B
ren %TPX%2.pdf %TO%.pdf
del %TPX%1.tex %TPX%2.tex %TPX%2.log
@zr-tex8r

This comment has been minimized.

Copy link
Owner Author

zr-tex8r commented Oct 16, 2014

“Perl無しで”pdfcrop(のオプション無し)と同じことをする。
Ghostscript(gswin32cに固定)とpdfTeXは相変わらず必要。

tcpdfcrop in.pdf out.pdf

ディレクトリ指定不可でカレントディレクトリを仮定する。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.