Skip to content

Instantly share code, notes, and snippets.

@aminophen
Forked from zr-tex8r/tcpdfcrop.bat
Last active August 14, 2019 03:02
Show Gist options
  • Select an option

  • Save aminophen/fdc3dfa320d9f0c32aeb to your computer and use it in GitHub Desktop.

Select an option

Save aminophen/fdc3dfa320d9f0c32aeb to your computer and use it in GitHub Desktop.

Revisions

  1. aminophen revised this gist Aug 6, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions tcpdfcrop.bat
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    @echo off
    echo tcpdfcrop v0.9.3 (2015-07-25)
    echo tcpdfcrop v0.9.4 (2015-08-06)
    setlocal
    if /I "%1"=="/h" (
    if /I "%~1"=="/h" (
    set BBOX=HiResBoundingBox
    shift
    ) else (
  2. aminophen revised this gist Jul 25, 2015. 2 changed files with 25 additions and 83 deletions.
    41 changes: 25 additions & 16 deletions tcpdfcrop.bat
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,23 @@
    @echo off
    echo tcpdfcrop v0.9.2 (2015-04-10)
    echo tcpdfcrop v0.9.3 (2015-07-25)
    setlocal
    if /I "%1"=="/h" (
    set BBOX=HiResBoundingBox
    shift
    ) else (
    set BBOX=BoundingBox
    )
    set FROMDIR=%~dp1
    set FROM=%~n1
    set TODIR=%~dp2
    set TO=%~n2
    set RANGE=%~3
    set TPX=_tcpc
    set CROPTEMP=croptemp
    if "%FROM%"=="" echo Usage: tcpdfcrop in.pdf [out.pdf] [page-range] [left-margin] [top-margin] [right-margin] [bottom-margin]
    if "%FROM%"=="" (
    echo Usage: tcpdfcrop [/h] in.pdf [out.pdf] [page-range] [left-margin] [top-margin] [right-margin] [bottom-margin]
    echo Option /h uses HiResBoundingBox instead of BoundingBox.
    )
    if not exist "%FROMDIR%%FROM%.pdf" exit /B
    if not "%TEMP%"=="" cd "%TEMP%"
    copy "%FROMDIR%%FROM%.pdf" "%CROPTEMP%.pdf" 1>nul
    @@ -26,17 +35,17 @@ set /P VERSION=<"%CROPTEMP%-version.txt"
    set VERSION=%VERSION:*.=%
    del "%CROPTEMP%.xbb" "%CROPTEMP%-pages.txt" "%CROPTEMP%-version.txt"
    for /F "tokens=1,2 delims=-" %%m in ("%RANGE%") do (
    set FIRST=%%m
    set LAST=%%n
    set FIRST=%%m
    set LAST=%%n
    )
    if "%FIRST%"=="" set FIRST=1
    if "%FIRST%"=="*" set FIRST=1
    if "%LAST%"=="" (
    if "%RANGE%"=="" (
    set LAST=%NUM%
    ) else (
    set LAST=%FIRST%
    )
    if "%RANGE%"=="" (
    set LAST=%NUM%
    ) else (
    set LAST=%FIRST%
    )
    )
    if "%LAST%"=="*" set LAST=%NUM%
    set LMARGIN=%~4
    @@ -50,13 +59,13 @@ if "%BMARGIN%"=="" set BMARGIN=0
    echo \pdfoutput=1 >%TPX%n.tex
    echo \pdfminorversion=%VERSION% >>%TPX%n.tex
    for /L %%i in (%FIRST%,1,%LAST%) do (
    rungs -dBATCH -dNOPAUSE -q -sDEVICE=bbox -dFirstPage=%%i -dLastPage=%%i "%CROPTEMP%.pdf" 2>&1 | find "%%BoundingBox: " >%TPX%%%i.tex
    echo {\catcode37=13 \catcode13=12 \def^^^^25^^^^25#1: #2^^^^M{\gdef\do{\proc[#2]}}\input %TPX%%%i.tex\relax}{}^
    \def\proc[#1 #2 #3 #4]{\pdfhorigin-#1bp \pdfvorigin#2bp \pdfpagewidth=\dimexpr#3bp-#1bp\relax\pdfpageheight\dimexpr#4bp-#2bp\relax}\do^
    \advance\pdfhorigin by %LMARGIN%bp\relax \advance\pdfpagewidth by %LMARGIN%bp\relax \advance\pdfpagewidth by %RMARGIN%bp\relax^
    \advance\pdfvorigin by -%BMARGIN%bp\relax \advance\pdfpageheight by %BMARGIN%bp\relax \advance\pdfpageheight by %TMARGIN%bp\relax^
    \setbox0=\hbox{\pdfximage page %%i mediabox{%CROPTEMP%.pdf}\pdfrefximage\pdflastximage}^
    \ht0=\pdfpageheight \shipout\box0\relax >>%TPX%n.tex
    rungs -dBATCH -dNOPAUSE -q -sDEVICE=bbox -dFirstPage=%%i -dLastPage=%%i "%CROPTEMP%.pdf" 2>&1 | find "%%%BBOX%: " >%TPX%%%i.tex
    echo {\catcode37=13 \catcode13=12 \def^^^^25^^^^25#1: #2^^^^M{\gdef\do{\proc[#2]}}\input %TPX%%%i.tex\relax}{}^
    \def\proc[#1 #2 #3 #4]{\pdfhorigin-#1bp \pdfvorigin#2bp \pdfpagewidth=\dimexpr#3bp-#1bp\relax\pdfpageheight\dimexpr#4bp-#2bp\relax}\do^
    \advance\pdfhorigin by %LMARGIN%bp\relax \advance\pdfpagewidth by %LMARGIN%bp\relax \advance\pdfpagewidth by %RMARGIN%bp\relax^
    \advance\pdfvorigin by -%BMARGIN%bp\relax \advance\pdfpageheight by %BMARGIN%bp\relax \advance\pdfpageheight by %TMARGIN%bp\relax^
    \setbox0=\hbox{\pdfximage page %%i mediabox{%CROPTEMP%.pdf}\pdfrefximage\pdflastximage}^
    \ht0=\pdfpageheight \shipout\box0\relax >>%TPX%n.tex
    )
    echo \end >>%TPX%n.tex
    pdftex -no-shell-escape -interaction=batchmode %TPX%n.tex 1>nul
    67 changes: 0 additions & 67 deletions tcpdfcrophires.bat
    Original file line number Diff line number Diff line change
    @@ -1,67 +0,0 @@
    @echo off
    echo tcpdfcrop-hires v0.9.2 (2015-04-10)
    setlocal
    set FROMDIR=%~dp1
    set FROM=%~n1
    set TODIR=%~dp2
    set TO=%~n2
    set RANGE=%~3
    set TPX=_tcpc
    set CROPTEMP=croptemp
    if "%FROM%"=="" echo Usage: tcpdfcrop in.pdf [out.pdf] [page-range] [left-margin] [top-margin] [right-margin] [bottom-margin]
    if not exist "%FROMDIR%%FROM%.pdf" exit /B
    if not "%TEMP%"=="" cd "%TEMP%"
    copy "%FROMDIR%%FROM%.pdf" "%CROPTEMP%.pdf" 1>nul
    if "%TO%"=="" set TO=%FROM%-crop
    if "%TODIR%"=="" set TODIR=%FROMDIR%
    if "%TODIR%%TO%"=="%FROMDIR%%FROM%" set TO=%FROM%-crop
    if exist "%TODIR%%TO%.pdf" del "%TODIR%%TO%.pdf"
    if exist "%TODIR%%TO%.pdf" exit /B
    extractbb "%CROPTEMP%.pdf"
    type "%CROPTEMP%.xbb" | find "%%Pages: " > "%CROPTEMP%-pages.txt"
    set /P NUM=<"%CROPTEMP%-pages.txt"
    set NUM=%NUM:* =%
    type "%CROPTEMP%.xbb" | find "%%PDFVersion: " > "%CROPTEMP%-version.txt"
    set /P VERSION=<"%CROPTEMP%-version.txt"
    set VERSION=%VERSION:*.=%
    del "%CROPTEMP%.xbb" "%CROPTEMP%-pages.txt" "%CROPTEMP%-version.txt"
    for /F "tokens=1,2 delims=-" %%m in ("%RANGE%") do (
    set FIRST=%%m
    set LAST=%%n
    )
    if "%FIRST%"=="" set FIRST=1
    if "%FIRST%"=="*" set FIRST=1
    if "%LAST%"=="" (
    if "%RANGE%"=="" (
    set LAST=%NUM%
    ) else (
    set LAST=%FIRST%
    )
    )
    if "%LAST%"=="*" set LAST=%NUM%
    set LMARGIN=%~4
    set TMARGIN=%~5
    set RMARGIN=%~6
    set BMARGIN=%~7
    if "%LMARGIN%"=="" set LMARGIN=0
    if "%TMARGIN%"=="" set TMARGIN=0
    if "%RMARGIN%"=="" set RMARGIN=0
    if "%BMARGIN%"=="" set BMARGIN=0
    echo \pdfoutput=1 >%TPX%n.tex
    echo \pdfminorversion=%VERSION% >>%TPX%n.tex
    for /L %%i in (%FIRST%,1,%LAST%) do (
    rungs -dBATCH -dNOPAUSE -q -sDEVICE=bbox -dFirstPage=%%i -dLastPage=%%i "%CROPTEMP%.pdf" 2>&1 | find "%%HiResBoundingBox: " >%TPX%%%i.tex
    echo {\catcode37=13 \catcode13=12 \def^^^^25^^^^25#1: #2^^^^M{\gdef\do{\proc[#2]}}\input %TPX%%%i.tex\relax}{}^
    \def\proc[#1 #2 #3 #4]{\pdfhorigin-#1bp \pdfvorigin#2bp \pdfpagewidth=\dimexpr#3bp-#1bp\relax\pdfpageheight\dimexpr#4bp-#2bp\relax}\do^
    \advance\pdfhorigin by %LMARGIN%bp\relax \advance\pdfpagewidth by %LMARGIN%bp\relax \advance\pdfpagewidth by %RMARGIN%bp\relax^
    \advance\pdfvorigin by -%BMARGIN%bp\relax \advance\pdfpageheight by %BMARGIN%bp\relax \advance\pdfpageheight by %TMARGIN%bp\relax^
    \setbox0=\hbox{\pdfximage page %%i mediabox{%CROPTEMP%.pdf}\pdfrefximage\pdflastximage}^
    \ht0=\pdfpageheight \shipout\box0\relax >>%TPX%n.tex
    )
    echo \end >>%TPX%n.tex
    pdftex -no-shell-escape -interaction=batchmode %TPX%n.tex 1>nul
    for /L %%i in (%FIRST%,1,%LAST%) do del %TPX%%%i.tex
    del %TPX%n.tex %TPX%n.log %CROPTEMP%.pdf
    if not exist %TPX%n.pdf exit /B
    move "%TPX%n.pdf" "%TODIR%%TO%.pdf" 1>nul
    echo ==^> %FIRST%-%LAST% page(s) written on "%TODIR%%TO%.pdf".
  3. aminophen revised this gist Apr 10, 2015. 2 changed files with 3 additions and 3 deletions.
    2 changes: 1 addition & 1 deletion tcpdfcrop.bat
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    @echo off
    echo tcpdfcrop v0.9.1 (2015-04-10)
    echo tcpdfcrop v0.9.2 (2015-04-10)
    setlocal
    set FROMDIR=%~dp1
    set FROM=%~n1
    4 changes: 2 additions & 2 deletions tcpdfcrophires.bat
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    @echo off
    echo tcpdfcrop-hires v0.9.1 (2015-04-10)
    echo tcpdfcrop-hires v0.9.2 (2015-04-10)
    setlocal
    set FROMDIR=%~dp1
    set FROM=%~n1
    @@ -50,7 +50,7 @@ if "%BMARGIN%"=="" set BMARGIN=0
    echo \pdfoutput=1 >%TPX%n.tex
    echo \pdfminorversion=%VERSION% >>%TPX%n.tex
    for /L %%i in (%FIRST%,1,%LAST%) do (
    rungs -dBATCH -dNOPAUSE -q -sDEVICE=bbox -dFirstPage=%%i -dLastPage=%%i "%CROPTEMP%.pdf" 2>%TPX%%%i.tex
    rungs -dBATCH -dNOPAUSE -q -sDEVICE=bbox -dFirstPage=%%i -dLastPage=%%i "%CROPTEMP%.pdf" 2>&1 | find "%%HiResBoundingBox: " >%TPX%%%i.tex
    echo {\catcode37=13 \catcode13=12 \def^^^^25^^^^25#1: #2^^^^M{\gdef\do{\proc[#2]}}\input %TPX%%%i.tex\relax}{}^
    \def\proc[#1 #2 #3 #4]{\pdfhorigin-#1bp \pdfvorigin#2bp \pdfpagewidth=\dimexpr#3bp-#1bp\relax\pdfpageheight\dimexpr#4bp-#2bp\relax}\do^
    \advance\pdfhorigin by %LMARGIN%bp\relax \advance\pdfpagewidth by %LMARGIN%bp\relax \advance\pdfpagewidth by %RMARGIN%bp\relax^
  4. aminophen revised this gist Apr 10, 2015. 2 changed files with 44 additions and 36 deletions.
    40 changes: 22 additions & 18 deletions tcpdfcrop.bat
    Original file line number Diff line number Diff line change
    @@ -1,27 +1,30 @@
    @echo off
    echo tcpdfcrop v0.9 (2015-04-01)
    echo tcpdfcrop v0.9.1 (2015-04-10)
    setlocal
    set FROMDIR=%~dp1
    set TODIR=%~dp2
    set FROM=%~n1
    set TODIR=%~dp2
    set TO=%~n2
    set RANGE=%~3
    set TPX=_tcpc
    set CROPTEMP=croptemp
    if "%FROM%"=="" echo Usage: tcpdfcrop in.pdf [out.pdf] [page-range] [left-margin] [top-margin] [right-margin] [bottom-margin]
    if not "%FROMDIR%"=="" cd "%FROMDIR%"
    if not exist "%FROM%.pdf" exit /B
    if not exist "%FROMDIR%%FROM%.pdf" exit /B
    if not "%TEMP%"=="" cd "%TEMP%"
    copy "%FROMDIR%%FROM%.pdf" "%CROPTEMP%.pdf" 1>nul
    if "%TO%"=="" set TO=%FROM%-crop
    if "%TO%"=="%FROM%" set TO=%FROM%-crop
    if exist "%TO%.pdf" del "%TO%.pdf"
    if exist "%TO%.pdf" exit /B
    extractbb "%FROM%.pdf"
    type "%FROM%.xbb" | find "%%Pages: " > "%FROM%-pages.txt"
    set /P NUM=<"%FROM%-pages.txt"
    if "%TODIR%"=="" set TODIR=%FROMDIR%
    if "%TODIR%%TO%"=="%FROMDIR%%FROM%" set TO=%FROM%-crop
    if exist "%TODIR%%TO%.pdf" del "%TODIR%%TO%.pdf"
    if exist "%TODIR%%TO%.pdf" exit /B
    extractbb "%CROPTEMP%.pdf"
    type "%CROPTEMP%.xbb" | find "%%Pages: " > "%CROPTEMP%-pages.txt"
    set /P NUM=<"%CROPTEMP%-pages.txt"
    set NUM=%NUM:* =%
    type "%FROM%.xbb" | find "%%PDFVersion: " > "%FROM%-version.txt"
    set /P VERSION=<"%FROM%-version.txt"
    type "%CROPTEMP%.xbb" | find "%%PDFVersion: " > "%CROPTEMP%-version.txt"
    set /P VERSION=<"%CROPTEMP%-version.txt"
    set VERSION=%VERSION:*.=%
    del "%FROM%.xbb" "%FROM%-pages.txt" "%FROM%-version.txt"
    del "%CROPTEMP%.xbb" "%CROPTEMP%-pages.txt" "%CROPTEMP%-version.txt"
    for /F "tokens=1,2 delims=-" %%m in ("%RANGE%") do (
    set FIRST=%%m
    set LAST=%%n
    @@ -47,17 +50,18 @@ if "%BMARGIN%"=="" set BMARGIN=0
    echo \pdfoutput=1 >%TPX%n.tex
    echo \pdfminorversion=%VERSION% >>%TPX%n.tex
    for /L %%i in (%FIRST%,1,%LAST%) do (
    rungs -dBATCH -dNOPAUSE -q -sDEVICE=bbox -dFirstPage=%%i -dLastPage=%%i "%FROM%.pdf" 2>&1 | find "%%BoundingBox: " >%TPX%%%i.tex
    rungs -dBATCH -dNOPAUSE -q -sDEVICE=bbox -dFirstPage=%%i -dLastPage=%%i "%CROPTEMP%.pdf" 2>&1 | find "%%BoundingBox: " >%TPX%%%i.tex
    echo {\catcode37=13 \catcode13=12 \def^^^^25^^^^25#1: #2^^^^M{\gdef\do{\proc[#2]}}\input %TPX%%%i.tex\relax}{}^
    \def\proc[#1 #2 #3 #4]{\pdfhorigin-#1bp \pdfvorigin#2bp \pdfpagewidth=\dimexpr#3bp-#1bp\relax\pdfpageheight\dimexpr#4bp-#2bp\relax}\do^
    \advance\pdfhorigin by %LMARGIN%bp\relax \advance\pdfpagewidth by %LMARGIN%bp\relax \advance\pdfpagewidth by %RMARGIN%bp\relax^
    \advance\pdfvorigin by -%BMARGIN%bp\relax \advance\pdfpageheight by %BMARGIN%bp\relax \advance\pdfpageheight by %TMARGIN%bp\relax^
    \setbox0=\hbox{\pdfximage page %%i mediabox{%FROM%.pdf}\pdfrefximage\pdflastximage}^
    \setbox0=\hbox{\pdfximage page %%i mediabox{%CROPTEMP%.pdf}\pdfrefximage\pdflastximage}^
    \ht0=\pdfpageheight \shipout\box0\relax >>%TPX%n.tex
    )
    echo \end >>%TPX%n.tex
    pdftex -no-shell-escape -interaction=batchmode %TPX%n.tex
    pdftex -no-shell-escape -interaction=batchmode %TPX%n.tex 1>nul
    for /L %%i in (%FIRST%,1,%LAST%) do del %TPX%%%i.tex
    del %TPX%n.tex %TPX%n.log
    del %TPX%n.tex %TPX%n.log %CROPTEMP%.pdf
    if not exist %TPX%n.pdf exit /B
    move "%FROMDIR%%TPX%n.pdf" "%TODIR%%TO%.pdf"
    move "%TPX%n.pdf" "%TODIR%%TO%.pdf" 1>nul
    echo ==^> %FIRST%-%LAST% page(s) written on "%TODIR%%TO%.pdf".
    40 changes: 22 additions & 18 deletions tcpdfcrophires.bat
    Original file line number Diff line number Diff line change
    @@ -1,27 +1,30 @@
    @echo off
    echo tcpdfcrop-hires v0.8.2 (2015-03-31)
    echo tcpdfcrop-hires v0.9.1 (2015-04-10)
    setlocal
    set FROMDIR=%~dp1
    set TODIR=%~dp2
    set FROM=%~n1
    set TODIR=%~dp2
    set TO=%~n2
    set RANGE=%~3
    set TPX=_tcpc
    set CROPTEMP=croptemp
    if "%FROM%"=="" echo Usage: tcpdfcrop in.pdf [out.pdf] [page-range] [left-margin] [top-margin] [right-margin] [bottom-margin]
    if not "%FROMDIR%"=="" cd "%FROMDIR%"
    if not exist "%FROM%.pdf" exit /B
    if not exist "%FROMDIR%%FROM%.pdf" exit /B
    if not "%TEMP%"=="" cd "%TEMP%"
    copy "%FROMDIR%%FROM%.pdf" "%CROPTEMP%.pdf" 1>nul
    if "%TO%"=="" set TO=%FROM%-crop
    if "%TO%"=="%FROM%" set TO=%FROM%-crop
    if exist "%TO%.pdf" del "%TO%.pdf"
    if exist "%TO%.pdf" exit /B
    extractbb "%FROM%.pdf"
    type "%FROM%.xbb" | find "%%Pages: " > "%FROM%-pages.txt"
    set /P NUM=<"%FROM%-pages.txt"
    if "%TODIR%"=="" set TODIR=%FROMDIR%
    if "%TODIR%%TO%"=="%FROMDIR%%FROM%" set TO=%FROM%-crop
    if exist "%TODIR%%TO%.pdf" del "%TODIR%%TO%.pdf"
    if exist "%TODIR%%TO%.pdf" exit /B
    extractbb "%CROPTEMP%.pdf"
    type "%CROPTEMP%.xbb" | find "%%Pages: " > "%CROPTEMP%-pages.txt"
    set /P NUM=<"%CROPTEMP%-pages.txt"
    set NUM=%NUM:* =%
    type "%FROM%.xbb" | find "%%PDFVersion: " > "%FROM%-version.txt"
    set /P VERSION=<"%FROM%-version.txt"
    type "%CROPTEMP%.xbb" | find "%%PDFVersion: " > "%CROPTEMP%-version.txt"
    set /P VERSION=<"%CROPTEMP%-version.txt"
    set VERSION=%VERSION:*.=%
    del "%FROM%.xbb" "%FROM%-pages.txt" "%FROM%-version.txt"
    del "%CROPTEMP%.xbb" "%CROPTEMP%-pages.txt" "%CROPTEMP%-version.txt"
    for /F "tokens=1,2 delims=-" %%m in ("%RANGE%") do (
    set FIRST=%%m
    set LAST=%%n
    @@ -47,17 +50,18 @@ if "%BMARGIN%"=="" set BMARGIN=0
    echo \pdfoutput=1 >%TPX%n.tex
    echo \pdfminorversion=%VERSION% >>%TPX%n.tex
    for /L %%i in (%FIRST%,1,%LAST%) do (
    rungs -dBATCH -dNOPAUSE -q -sDEVICE=bbox -dFirstPage=%%i -dLastPage=%%i "%FROM%.pdf" 2>%TPX%%%i.tex
    rungs -dBATCH -dNOPAUSE -q -sDEVICE=bbox -dFirstPage=%%i -dLastPage=%%i "%CROPTEMP%.pdf" 2>%TPX%%%i.tex
    echo {\catcode37=13 \catcode13=12 \def^^^^25^^^^25#1: #2^^^^M{\gdef\do{\proc[#2]}}\input %TPX%%%i.tex\relax}{}^
    \def\proc[#1 #2 #3 #4]{\pdfhorigin-#1bp \pdfvorigin#2bp \pdfpagewidth=\dimexpr#3bp-#1bp\relax\pdfpageheight\dimexpr#4bp-#2bp\relax}\do^
    \advance\pdfhorigin by %LMARGIN%bp\relax \advance\pdfpagewidth by %LMARGIN%bp\relax \advance\pdfpagewidth by %RMARGIN%bp\relax^
    \advance\pdfvorigin by -%BMARGIN%bp\relax \advance\pdfpageheight by %BMARGIN%bp\relax \advance\pdfpageheight by %TMARGIN%bp\relax^
    \setbox0=\hbox{\pdfximage page %%i mediabox{%FROM%.pdf}\pdfrefximage\pdflastximage}^
    \setbox0=\hbox{\pdfximage page %%i mediabox{%CROPTEMP%.pdf}\pdfrefximage\pdflastximage}^
    \ht0=\pdfpageheight \shipout\box0\relax >>%TPX%n.tex
    )
    echo \end >>%TPX%n.tex
    pdftex -no-shell-escape -interaction=batchmode %TPX%n.tex
    pdftex -no-shell-escape -interaction=batchmode %TPX%n.tex 1>nul
    for /L %%i in (%FIRST%,1,%LAST%) do del %TPX%%%i.tex
    del %TPX%n.tex %TPX%n.log
    del %TPX%n.tex %TPX%n.log %CROPTEMP%.pdf
    if not exist %TPX%n.pdf exit /B
    move "%FROMDIR%%TPX%n.pdf" "%TODIR%%TO%.pdf"
    move "%TPX%n.pdf" "%TODIR%%TO%.pdf" 1>nul
    echo ==^> %FIRST%-%LAST% page(s) written on "%TODIR%%TO%.pdf".
  5. aminophen revised this gist Mar 31, 2015. 2 changed files with 65 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions tcpdfcrop.bat
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    @echo off
    echo tcpdfcrop v0.8.2 (2015-03-31)
    echo tcpdfcrop v0.9 (2015-04-01)
    setlocal
    set FROMDIR=%~dp1
    set TODIR=%~dp2
    @@ -47,7 +47,7 @@ if "%BMARGIN%"=="" set BMARGIN=0
    echo \pdfoutput=1 >%TPX%n.tex
    echo \pdfminorversion=%VERSION% >>%TPX%n.tex
    for /L %%i in (%FIRST%,1,%LAST%) do (
    rungs -dBATCH -dNOPAUSE -q -sDEVICE=bbox -dFirstPage=%%i -dLastPage=%%i "%FROM%.pdf" 2>%TPX%%%i.tex
    rungs -dBATCH -dNOPAUSE -q -sDEVICE=bbox -dFirstPage=%%i -dLastPage=%%i "%FROM%.pdf" 2>&1 | find "%%BoundingBox: " >%TPX%%%i.tex
    echo {\catcode37=13 \catcode13=12 \def^^^^25^^^^25#1: #2^^^^M{\gdef\do{\proc[#2]}}\input %TPX%%%i.tex\relax}{}^
    \def\proc[#1 #2 #3 #4]{\pdfhorigin-#1bp \pdfvorigin#2bp \pdfpagewidth=\dimexpr#3bp-#1bp\relax\pdfpageheight\dimexpr#4bp-#2bp\relax}\do^
    \advance\pdfhorigin by %LMARGIN%bp\relax \advance\pdfpagewidth by %LMARGIN%bp\relax \advance\pdfpagewidth by %RMARGIN%bp\relax^
    63 changes: 63 additions & 0 deletions tcpdfcrophires.bat
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,63 @@
    @echo off
    echo tcpdfcrop-hires v0.8.2 (2015-03-31)
    setlocal
    set FROMDIR=%~dp1
    set TODIR=%~dp2
    set FROM=%~n1
    set TO=%~n2
    set RANGE=%~3
    set TPX=_tcpc
    if "%FROM%"=="" echo Usage: tcpdfcrop in.pdf [out.pdf] [page-range] [left-margin] [top-margin] [right-margin] [bottom-margin]
    if not "%FROMDIR%"=="" cd "%FROMDIR%"
    if not exist "%FROM%.pdf" exit /B
    if "%TO%"=="" set TO=%FROM%-crop
    if "%TO%"=="%FROM%" set TO=%FROM%-crop
    if exist "%TO%.pdf" del "%TO%.pdf"
    if exist "%TO%.pdf" exit /B
    extractbb "%FROM%.pdf"
    type "%FROM%.xbb" | find "%%Pages: " > "%FROM%-pages.txt"
    set /P NUM=<"%FROM%-pages.txt"
    set NUM=%NUM:* =%
    type "%FROM%.xbb" | find "%%PDFVersion: " > "%FROM%-version.txt"
    set /P VERSION=<"%FROM%-version.txt"
    set VERSION=%VERSION:*.=%
    del "%FROM%.xbb" "%FROM%-pages.txt" "%FROM%-version.txt"
    for /F "tokens=1,2 delims=-" %%m in ("%RANGE%") do (
    set FIRST=%%m
    set LAST=%%n
    )
    if "%FIRST%"=="" set FIRST=1
    if "%FIRST%"=="*" set FIRST=1
    if "%LAST%"=="" (
    if "%RANGE%"=="" (
    set LAST=%NUM%
    ) else (
    set LAST=%FIRST%
    )
    )
    if "%LAST%"=="*" set LAST=%NUM%
    set LMARGIN=%~4
    set TMARGIN=%~5
    set RMARGIN=%~6
    set BMARGIN=%~7
    if "%LMARGIN%"=="" set LMARGIN=0
    if "%TMARGIN%"=="" set TMARGIN=0
    if "%RMARGIN%"=="" set RMARGIN=0
    if "%BMARGIN%"=="" set BMARGIN=0
    echo \pdfoutput=1 >%TPX%n.tex
    echo \pdfminorversion=%VERSION% >>%TPX%n.tex
    for /L %%i in (%FIRST%,1,%LAST%) do (
    rungs -dBATCH -dNOPAUSE -q -sDEVICE=bbox -dFirstPage=%%i -dLastPage=%%i "%FROM%.pdf" 2>%TPX%%%i.tex
    echo {\catcode37=13 \catcode13=12 \def^^^^25^^^^25#1: #2^^^^M{\gdef\do{\proc[#2]}}\input %TPX%%%i.tex\relax}{}^
    \def\proc[#1 #2 #3 #4]{\pdfhorigin-#1bp \pdfvorigin#2bp \pdfpagewidth=\dimexpr#3bp-#1bp\relax\pdfpageheight\dimexpr#4bp-#2bp\relax}\do^
    \advance\pdfhorigin by %LMARGIN%bp\relax \advance\pdfpagewidth by %LMARGIN%bp\relax \advance\pdfpagewidth by %RMARGIN%bp\relax^
    \advance\pdfvorigin by -%BMARGIN%bp\relax \advance\pdfpageheight by %BMARGIN%bp\relax \advance\pdfpageheight by %TMARGIN%bp\relax^
    \setbox0=\hbox{\pdfximage page %%i mediabox{%FROM%.pdf}\pdfrefximage\pdflastximage}^
    \ht0=\pdfpageheight \shipout\box0\relax >>%TPX%n.tex
    )
    echo \end >>%TPX%n.tex
    pdftex -no-shell-escape -interaction=batchmode %TPX%n.tex
    for /L %%i in (%FIRST%,1,%LAST%) do del %TPX%%%i.tex
    del %TPX%n.tex %TPX%n.log
    if not exist %TPX%n.pdf exit /B
    move "%FROMDIR%%TPX%n.pdf" "%TODIR%%TO%.pdf"
  6. aminophen revised this gist Mar 30, 2015. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions tcpdfcrop.bat
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    @echo off
    echo tcpdfcrop v0.8.1 (2015-03-25)
    echo tcpdfcrop v0.8.2 (2015-03-31)
    setlocal
    set FROMDIR=%~dp1
    set TODIR=%~dp2
    @@ -18,7 +18,10 @@ extractbb "%FROM%.pdf"
    type "%FROM%.xbb" | find "%%Pages: " > "%FROM%-pages.txt"
    set /P NUM=<"%FROM%-pages.txt"
    set NUM=%NUM:* =%
    del "%FROM%.xbb" "%FROM%-pages.txt"
    type "%FROM%.xbb" | find "%%PDFVersion: " > "%FROM%-version.txt"
    set /P VERSION=<"%FROM%-version.txt"
    set VERSION=%VERSION:*.=%
    del "%FROM%.xbb" "%FROM%-pages.txt" "%FROM%-version.txt"
    for /F "tokens=1,2 delims=-" %%m in ("%RANGE%") do (
    set FIRST=%%m
    set LAST=%%n
    @@ -42,6 +45,7 @@ if "%TMARGIN%"=="" set TMARGIN=0
    if "%RMARGIN%"=="" set RMARGIN=0
    if "%BMARGIN%"=="" set BMARGIN=0
    echo \pdfoutput=1 >%TPX%n.tex
    echo \pdfminorversion=%VERSION% >>%TPX%n.tex
    for /L %%i in (%FIRST%,1,%LAST%) do (
    rungs -dBATCH -dNOPAUSE -q -sDEVICE=bbox -dFirstPage=%%i -dLastPage=%%i "%FROM%.pdf" 2>%TPX%%%i.tex
    echo {\catcode37=13 \catcode13=12 \def^^^^25^^^^25#1: #2^^^^M{\gdef\do{\proc[#2]}}\input %TPX%%%i.tex\relax}{}^
  7. aminophen revised this gist Mar 25, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tcpdfcrop.bat
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    @echo off
    echo tcpdfcrop v0.8 (2015-03-23)
    echo tcpdfcrop v0.8.1 (2015-03-25)
    setlocal
    set FROMDIR=%~dp1
    set TODIR=%~dp2
  8. aminophen revised this gist Mar 25, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tcpdfcrop.bat
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ if "%TO%"=="%FROM%" set TO=%FROM%-crop
    if exist "%TO%.pdf" del "%TO%.pdf"
    if exist "%TO%.pdf" exit /B
    extractbb "%FROM%.pdf"
    type "%FROM%.xbb" | find "Pages" > "%FROM%-pages.txt"
    type "%FROM%.xbb" | find "%%Pages: " > "%FROM%-pages.txt"
    set /P NUM=<"%FROM%-pages.txt"
    set NUM=%NUM:* =%
    del "%FROM%.xbb" "%FROM%-pages.txt"
  9. aminophen revised this gist Mar 22, 2015. 1 changed file with 29 additions and 9 deletions.
    38 changes: 29 additions & 9 deletions tcpdfcrop.bat
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    @echo off
    echo tcpdfcrop v0.7.1 (2015-03-23)
    echo tcpdfcrop v0.8 (2015-03-23)
    setlocal
    set FROMDIR=%~dp1
    set TODIR=%~dp2
    set FROM=%~n1
    set TO=%~n2
    set RANGE=%3
    set RANGE=%~3
    set TPX=_tcpc
    if "%FROM%"=="" echo Usage: tcpdfcrop in.pdf [out.pdf] [page-range] [left-margin] [top-margin] [right-margin] [bottom-margin]
    if not "%FROMDIR%"=="" cd "%FROMDIR%"
    @@ -19,21 +19,41 @@ type "%FROM%.xbb" | find "Pages" > "%FROM%-pages.txt"
    set /P NUM=<"%FROM%-pages.txt"
    set NUM=%NUM:* =%
    del "%FROM%.xbb" "%FROM%-pages.txt"
    if "%NUM%"=="" set NUM=1
    if exist %TPX%n.tex del %TPX%n.tex
    for /F "tokens=1,2 delims=-" %%m in ("%RANGE%") do (
    set FIRST=%%m
    set LAST=%%n
    )
    if "%FIRST%"=="" set FIRST=1
    if "%FIRST%"=="*" set FIRST=1
    if "%LAST%"=="" (
    if "%RANGE%"=="" (
    set LAST=%NUM%
    ) else (
    set LAST=%FIRST%
    )
    )
    if "%LAST%"=="*" set LAST=%NUM%
    set LMARGIN=%~4
    set TMARGIN=%~5
    set RMARGIN=%~6
    set BMARGIN=%~7
    if "%LMARGIN%"=="" set LMARGIN=0
    if "%TMARGIN%"=="" set TMARGIN=0
    if "%RMARGIN%"=="" set RMARGIN=0
    if "%BMARGIN%"=="" set BMARGIN=0
    echo \pdfoutput=1 >%TPX%n.tex
    for /L %%i in (1,1,%NUM%) do (
    gswin32c -dBATCH -dNOPAUSE -q -sDEVICE=bbox -dFirstPage=%%i -dLastPage=%%i "%FROM%.pdf" 2>%TPX%%%i.tex
    for /L %%i in (%FIRST%,1,%LAST%) do (
    rungs -dBATCH -dNOPAUSE -q -sDEVICE=bbox -dFirstPage=%%i -dLastPage=%%i "%FROM%.pdf" 2>%TPX%%%i.tex
    echo {\catcode37=13 \catcode13=12 \def^^^^25^^^^25#1: #2^^^^M{\gdef\do{\proc[#2]}}\input %TPX%%%i.tex\relax}{}^
    \def\proc[#1 #2 #3 #4]{\pdfhorigin-#1bp \pdfvorigin#2bp \pdfpagewidth=\dimexpr#3bp-#1bp\relax\pdfpageheight\dimexpr#4bp-#2bp\relax}\do^
    \advance\pdfhorigin by %4bp\relax \advance\pdfpagewidth by %4bp\relax \advance\pdfpagewidth by %6bp\relax^
    \advance\pdfvorigin by -%7bp\relax \advance\pdfpageheight by %7bp\relax \advance\pdfpageheight by %5bp\relax^
    \advance\pdfhorigin by %LMARGIN%bp\relax \advance\pdfpagewidth by %LMARGIN%bp\relax \advance\pdfpagewidth by %RMARGIN%bp\relax^
    \advance\pdfvorigin by -%BMARGIN%bp\relax \advance\pdfpageheight by %BMARGIN%bp\relax \advance\pdfpageheight by %TMARGIN%bp\relax^
    \setbox0=\hbox{\pdfximage page %%i mediabox{%FROM%.pdf}\pdfrefximage\pdflastximage}^
    \ht0=\pdfpageheight \shipout\box0\relax >>%TPX%n.tex
    )
    echo \end >>%TPX%n.tex
    pdftex -no-shell-escape -interaction=batchmode %TPX%n.tex
    for /L %%i in (1,1,%NUM%) do del %TPX%%%i.tex
    for /L %%i in (%FIRST%,1,%LAST%) do del %TPX%%%i.tex
    del %TPX%n.tex %TPX%n.log
    if not exist %TPX%n.pdf exit /B
    move "%FROMDIR%%TPX%n.pdf" "%TODIR%%TO%.pdf"
  10. aminophen revised this gist Mar 22, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions tcpdfcrop.bat
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    @echo off
    echo tcpdfcrop v0.7 (2015-03-19)
    echo tcpdfcrop v0.7.1 (2015-03-23)
    setlocal
    set FROMDIR=%~dp1
    set TODIR=%~dp2
    @@ -8,7 +8,7 @@ set TO=%~n2
    set RANGE=%3
    set TPX=_tcpc
    if "%FROM%"=="" echo Usage: tcpdfcrop in.pdf [out.pdf] [page-range] [left-margin] [top-margin] [right-margin] [bottom-margin]
    cd "%FROMDIR%"
    if not "%FROMDIR%"=="" cd "%FROMDIR%"
    if not exist "%FROM%.pdf" exit /B
    if "%TO%"=="" set TO=%FROM%-crop
    if "%TO%"=="%FROM%" set TO=%FROM%-crop
  11. aminophen revised this gist Mar 21, 2015. 1 changed file with 15 additions and 5 deletions.
    20 changes: 15 additions & 5 deletions tcpdfcrop.bat
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,30 @@
    @echo off
    echo tcpdfcrop v0.6.1 (2015-03-15)
    echo tcpdfcrop v0.7 (2015-03-19)
    setlocal
    set FROMDIR=%~dp1
    set TODIR=%~dp2
    set FROM=%~n1
    set TO=%~n2
    set NUM=%3
    set RANGE=%3
    set TPX=_tcpc
    if "%FROM%"=="" echo Usage: tcpdfcrop in.pdf [out.pdf] [pagenum] [left-margin] [top-margin] [right-margin] [bottom-margin]
    if "%FROM%"=="" echo Usage: tcpdfcrop in.pdf [out.pdf] [page-range] [left-margin] [top-margin] [right-margin] [bottom-margin]
    cd "%FROMDIR%"
    if not exist "%FROM%.pdf" exit /B
    if "%TO%"=="" set TO=%FROM%-crop
    if "%TO%"=="%FROM%" set TO=%FROM%-crop
    if exist "%TO%.pdf" del "%TO%.pdf"
    if exist "%TO%.pdf" exit /B
    extractbb "%FROM%.pdf"
    type "%FROM%.xbb" | find "Pages" > "%FROM%-pages.txt"
    set /P NUM=<"%FROM%-pages.txt"
    set NUM=%NUM:* =%
    del "%FROM%.xbb" "%FROM%-pages.txt"
    if "%NUM%"=="" set NUM=1
    if exist %TPX%n.tex del %TPX%n.tex
    echo \pdfoutput=1 >%TPX%n.tex
    for /L %%i in (1,1,%NUM%) do (
    gswin32c -dBATCH -dNOPAUSE -q -sDEVICE=bbox -dFirstPage=%%i -dLastPage=%%i "%FROM%.pdf" 2>%TPX%%%i.tex
    echo {\catcode37=13 \catcode13=12 \def^^^^25^^^^25#1: #2^^^^M{\gdef\do{\proc[#2]}}\input _tcpc%%i.tex\relax}{}^
    echo {\catcode37=13 \catcode13=12 \def^^^^25^^^^25#1: #2^^^^M{\gdef\do{\proc[#2]}}\input %TPX%%%i.tex\relax}{}^
    \def\proc[#1 #2 #3 #4]{\pdfhorigin-#1bp \pdfvorigin#2bp \pdfpagewidth=\dimexpr#3bp-#1bp\relax\pdfpageheight\dimexpr#4bp-#2bp\relax}\do^
    \advance\pdfhorigin by %4bp\relax \advance\pdfpagewidth by %4bp\relax \advance\pdfpagewidth by %6bp\relax^
    \advance\pdfvorigin by -%7bp\relax \advance\pdfpageheight by %7bp\relax \advance\pdfpageheight by %5bp\relax^
    @@ -26,4 +36,4 @@ pdftex -no-shell-escape -interaction=batchmode %TPX%n.tex
    for /L %%i in (1,1,%NUM%) do del %TPX%%%i.tex
    del %TPX%n.tex %TPX%n.log
    if not exist %TPX%n.pdf exit /B
    ren %TPX%n.pdf "%TO%.pdf"
    move "%FROMDIR%%TPX%n.pdf" "%TODIR%%TO%.pdf"
  12. aminophen revised this gist Mar 15, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tcpdfcrop.bat
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ set FROM=%~n1
    set TO=%~n2
    set NUM=%3
    set TPX=_tcpc
    if "%FROM%"=="" echo Usage: tcpdfcrop in.pdf [out.pdf]
    if "%FROM%"=="" echo Usage: tcpdfcrop in.pdf [out.pdf] [pagenum] [left-margin] [top-margin] [right-margin] [bottom-margin]
    if not exist "%FROM%.pdf" exit /B
    if "%TO%"=="" set TO=%FROM%-crop
    if exist "%TO%.pdf" del "%TO%.pdf"
  13. aminophen revised this gist Mar 15, 2015. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions tcpdfcrop.bat
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    @echo off
    echo tcpdfcrop v0.6 (2015-03-15)
    echo tcpdfcrop v0.6.1 (2015-03-15)
    setlocal
    set FROM=%~n1
    set TO=%~n2
    @@ -11,9 +11,8 @@ if "%TO%"=="" set TO=%FROM%-crop
    if exist "%TO%.pdf" del "%TO%.pdf"
    if exist "%TO%.pdf" exit /B
    if "%NUM%"=="" set NUM=1
    if exist "%TPX%n.tex" del "%TPX%n.tex"
    if exist %TPX%n.tex del %TPX%n.tex
    for /L %%i in (1,1,%NUM%) do (
    if exist "%TPX%%%i.tex" del "%TPX%%%i.tex"
    gswin32c -dBATCH -dNOPAUSE -q -sDEVICE=bbox -dFirstPage=%%i -dLastPage=%%i "%FROM%.pdf" 2>%TPX%%%i.tex
    echo {\catcode37=13 \catcode13=12 \def^^^^25^^^^25#1: #2^^^^M{\gdef\do{\proc[#2]}}\input _tcpc%%i.tex\relax}{}^
    \def\proc[#1 #2 #3 #4]{\pdfhorigin-#1bp \pdfvorigin#2bp \pdfpagewidth=\dimexpr#3bp-#1bp\relax\pdfpageheight\dimexpr#4bp-#2bp\relax}\do^
  14. aminophen revised this gist Mar 15, 2015. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion tcpdfcrop.bat
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    @echo off
    echo tcpdfcrop v0.5 (2015-03-15)
    echo tcpdfcrop v0.6 (2015-03-15)
    setlocal
    set FROM=%~n1
    set TO=%~n2
    @@ -17,6 +17,8 @@ if exist "%TPX%%%i.tex" del "%TPX%%%i.tex"
    gswin32c -dBATCH -dNOPAUSE -q -sDEVICE=bbox -dFirstPage=%%i -dLastPage=%%i "%FROM%.pdf" 2>%TPX%%%i.tex
    echo {\catcode37=13 \catcode13=12 \def^^^^25^^^^25#1: #2^^^^M{\gdef\do{\proc[#2]}}\input _tcpc%%i.tex\relax}{}^
    \def\proc[#1 #2 #3 #4]{\pdfhorigin-#1bp \pdfvorigin#2bp \pdfpagewidth=\dimexpr#3bp-#1bp\relax\pdfpageheight\dimexpr#4bp-#2bp\relax}\do^
    \advance\pdfhorigin by %4bp\relax \advance\pdfpagewidth by %4bp\relax \advance\pdfpagewidth by %6bp\relax^
    \advance\pdfvorigin by -%7bp\relax \advance\pdfpageheight by %7bp\relax \advance\pdfpageheight by %5bp\relax^
    \setbox0=\hbox{\pdfximage page %%i mediabox{%FROM%.pdf}\pdfrefximage\pdflastximage}^
    \ht0=\pdfpageheight \shipout\box0\relax >>%TPX%n.tex
    )
  15. aminophen revised this gist Mar 15, 2015. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions tcpdfcrop.bat
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,9 @@ if "%TO%"=="" set TO=%FROM%-crop
    if exist "%TO%.pdf" del "%TO%.pdf"
    if exist "%TO%.pdf" exit /B
    if "%NUM%"=="" set NUM=1
    if exist "%TPX%n.tex" del "%TPX%n.tex"
    for /L %%i in (1,1,%NUM%) do (
    if exist "%TPX%%%i.tex" del "%TPX%%%i.tex"
    gswin32c -dBATCH -dNOPAUSE -q -sDEVICE=bbox -dFirstPage=%%i -dLastPage=%%i "%FROM%.pdf" 2>%TPX%%%i.tex
    echo {\catcode37=13 \catcode13=12 \def^^^^25^^^^25#1: #2^^^^M{\gdef\do{\proc[#2]}}\input _tcpc%%i.tex\relax}{}^
    \def\proc[#1 #2 #3 #4]{\pdfhorigin-#1bp \pdfvorigin#2bp \pdfpagewidth=\dimexpr#3bp-#1bp\relax\pdfpageheight\dimexpr#4bp-#2bp\relax}\do^
    @@ -20,7 +22,7 @@ echo {\catcode37=13 \catcode13=12 \def^^^^25^^^^25#1: #2^^^^M{\gdef\do{\proc[#2]
    )
    echo \end >>%TPX%n.tex
    pdftex -no-shell-escape -interaction=batchmode %TPX%n.tex
    if not exist %TPX%n.pdf exit /B
    ren %TPX%n.pdf "%TO%.pdf"
    for /L %%i in (1,1,%NUM%) do del %TPX%%%i.tex
    del %TPX%n.tex %TPX%n.log
    if not exist %TPX%n.pdf exit /B
    ren %TPX%n.pdf "%TO%.pdf"
  16. aminophen revised this gist Mar 15, 2015. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions tcpdfcrop.bat
    Original file line number Diff line number Diff line change
    @@ -3,13 +3,15 @@ echo tcpdfcrop v0.5 (2015-03-15)
    setlocal
    set FROM=%~n1
    set TO=%~n2
    set NUM=%3
    set TPX=_tcpc
    if "%FROM%"=="" echo Usage: tcpdfcrop in.pdf [out.pdf]
    if not exist "%FROM%.pdf" exit /B
    if "%TO%"=="" set TO=%FROM%-crop
    if exist "%TO%.pdf" del "%TO%.pdf"
    if exist "%TO%.pdf" exit /B
    for /L %%i in (1,1,%3) do (
    if "%NUM%"=="" set NUM=1
    for /L %%i in (1,1,%NUM%) do (
    gswin32c -dBATCH -dNOPAUSE -q -sDEVICE=bbox -dFirstPage=%%i -dLastPage=%%i "%FROM%.pdf" 2>%TPX%%%i.tex
    echo {\catcode37=13 \catcode13=12 \def^^^^25^^^^25#1: #2^^^^M{\gdef\do{\proc[#2]}}\input _tcpc%%i.tex\relax}{}^
    \def\proc[#1 #2 #3 #4]{\pdfhorigin-#1bp \pdfvorigin#2bp \pdfpagewidth=\dimexpr#3bp-#1bp\relax\pdfpageheight\dimexpr#4bp-#2bp\relax}\do^
    @@ -20,5 +22,5 @@ echo \end >>%TPX%n.tex
    pdftex -no-shell-escape -interaction=batchmode %TPX%n.tex
    if not exist %TPX%n.pdf exit /B
    ren %TPX%n.pdf "%TO%.pdf"
    for /L %%i in (1,1,%3) do del %TPX%%%i.tex
    for /L %%i in (1,1,%NUM%) do del %TPX%%%i.tex
    del %TPX%n.tex %TPX%n.log
  17. aminophen revised this gist Mar 15, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tcpdfcrop.bat
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    @echo off
    echo tcpdfcrop v0.4 (2015-02-08)
    echo tcpdfcrop v0.5 (2015-03-15)
    setlocal
    set FROM=%~n1
    set TO=%~n2
  18. aminophen revised this gist Mar 15, 2015. 1 changed file with 14 additions and 8 deletions.
    22 changes: 14 additions & 8 deletions tcpdfcrop.bat
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,24 @@
    @echo off
    echo tcpdfcrop v0.4 (2015-02-08)
    setlocal
    set FROM=%~n1
    set TO=%~n2
    set TPX=_tcpc
    if "%FROM%"=="" echo Usage: tcpdfcrop in.pdf [out.pdf]
    if not exist "%FROM%.pdf" exit /B
    if "%TO%"=="" set TO=%FROM%-crop
    if exist "%TO%.pdf" del "%TO%.pdf"
    if exist "%TO%.pdf" 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}{}^
    for /L %%i in (1,1,%3) do (
    gswin32c -dBATCH -dNOPAUSE -q -sDEVICE=bbox -dFirstPage=%%i -dLastPage=%%i "%FROM%.pdf" 2>%TPX%%%i.tex
    echo {\catcode37=13 \catcode13=12 \def^^^^25^^^^25#1: #2^^^^M{\gdef\do{\proc[#2]}}\input _tcpc%%i.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 -interaction=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
    \setbox0=\hbox{\pdfximage page %%i mediabox{%FROM%.pdf}\pdfrefximage\pdflastximage}^
    \ht0=\pdfpageheight \shipout\box0\relax >>%TPX%n.tex
    )
    echo \end >>%TPX%n.tex
    pdftex -no-shell-escape -interaction=batchmode %TPX%n.tex
    if not exist %TPX%n.pdf exit /B
    ren %TPX%n.pdf "%TO%.pdf"
    for /L %%i in (1,1,%3) do del %TPX%%%i.tex
    del %TPX%n.tex %TPX%n.log
  19. aminophen revised this gist Feb 7, 2015. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions tcpdfcrop.bat
    Original file line number Diff line number Diff line change
    @@ -3,16 +3,16 @@ setlocal
    set FROM=%~n1
    set TO=%~n2
    set TPX=_tcpc
    if not exist %FROM%.pdf exit /B
    if not exist "%FROM%.pdf" exit /B
    if "%TO%"=="" set TO=%FROM%-crop
    if exist %TO%.pdf del %TO%.pdf
    if exist %TO%.pdf exit /B
    gswin32c -dBATCH -dNOPAUSE -q -sDEVICE=bbox %FROM%.pdf 2>%TPX%1.tex
    if exist "%TO%.pdf" del "%TO%.pdf"
    if exist "%TO%.pdf" 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 -interaction=batchmode %TPX%2.tex
    if not exist %TPX%2.pdf exit /B
    ren %TPX%2.pdf %TO%.pdf
    ren %TPX%2.pdf "%TO%.pdf"
    del %TPX%1.tex %TPX%2.tex %TPX%2.log
  20. aminophen revised this gist Feb 7, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions tcpdfcrop.bat
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ set TPX=_tcpc
    if not exist %FROM%.pdf exit /B
    if "%TO%"=="" set TO=%FROM%-crop
    if exist %TO%.pdf del %TO%.pdf
    if exist %TO%.pdf del exit /B
    if exist %TO%.pdf 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^
    @@ -15,4 +15,4 @@ echo {\catcode37=13 \catcode13=12 \def^^^^25^^^^25#1: #2^^^^M{\gdef\do{\proc[#2]
    pdftex -no-shell-escape -interaction=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
    del %TPX%1.tex %TPX%2.tex %TPX%2.log
  21. aminophen revised this gist Feb 7, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions tcpdfcrop.bat
    Original file line number Diff line number Diff line change
    @@ -4,15 +4,15 @@ set FROM=%~n1
    set TO=%~n2
    set TPX=_tcpc
    if not exist %FROM%.pdf exit /B
    if "%TO%"=="" exit /B
    if "%TO%"=="" set TO=%FROM%-crop
    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
    pdftex -no-shell-escape -interaction=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
    del %TPX%1.tex %TPX%2.tex %TPX%2.log
  22. @zr-tex8r zr-tex8r created this gist Oct 16, 2014.
    18 changes: 18 additions & 0 deletions tcpdfcrop.bat
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    @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