Skip to content

Instantly share code, notes, and snippets.

@zr-tex8r
Created October 16, 2014 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zr-tex8r/138b07c6d71e31aa5334 to your computer and use it in GitHub Desktop.
Save zr-tex8r/138b07c6d71e31aa5334 to your computer and use it in GitHub Desktop.
バッチで作る、劣化版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
Copy link
Author

“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