I know barely enough to survive in this digital world.
I have many one-page postscript files (graphics / images) that I want to convert to pdf and automatically crop to a narrow border. I'm on windows right now (I'm using linux too, so feel free to post code for Linux)
In the past, I was successful by combining Ghostscript gswin32c.exe and Caliber pdfmanipulate.exe. This is probably a familiar approach to many here.
But this approach is fraught with problems for several reasons.
One problem arose after I “upgraded” to the 64-bit gswin64c.exe. The 32-bit version of gswin32c.exe still works on my system, so I can't complain too much.
Another issue occurred while working with postscript files that may have been incorrectly encoded. There seem to be at least two problems, but I'm not sure who, if any, is responsible, or if both of them. One of the problems is that the bounding box line, for example, %% BoundingBox: 135 179 484 587 is not always placed on the second line from the top. I understand that this can be a problem. Another problem is that the bounding box above corresponds to the Portrait orientation in Ghostscript, but cropping follows the Landscape orientation. Another problem that I have not identified is that for some files, trimming seems pretty random.
So here is my 32-bit approach (which works for high-quality files), followed by a 64-bit adaptation that doesn't work (perhaps because it calls some kind of pypdf script on my machine, and not a fixed script, caliber provided, if I understand https://bugs.launchpad.net/ubuntu/+source/calibre/+bug/800551 and http://www.mobileread.com/forums/archive/index.php/t-103097. html , but I just guess and don't know the workaround):
@echo off echo batch processing with Latex ps2pdf followed by Ghostscript gswin64c.exe and Calibre2 pdfmanipulate.exe for %%I in (*.ps,*.eps) do ( "C:\Program Files\MiKTeX 2.9\miktex\bin\x64\ps2pdf" %%I ) for %%I in (*.pdf) do ( "C:\Program Files (x86)\Ghostscript\gs9.00\bin\gswin32c.exe" -dSAFER -dNOPAUSE -dBATCH
-sDEVICE#bbox "%%I" 2> bounding "C:\Program Files (x86)\Calibre2\pdfmanipulate.exe" crop -o "%%~nICropped32.pdf" -b bounding "%%I" pause "C:\Program Files\Ghostscript\gs9.04\bin\gswin64c.exe" -dSAFER -dNOPAUSE -dBATCH
-sDEVICE#bbox "%%I" 2> bounding "C:\Program Files (x86)\Calibre2\pdfmanipulate.exe" crop -o "%%~nICropped64.pdf" -b bounding "%%I" pause )
The above 32-bit approach works with high quality files, for example. Postscript 3 level created by PSTricks or the standard Maple 2D graphics adapter, but not for older files, for example. A Level 2 postscript (if any) created by the Maple classic graphics driver.
. epstopdf LaTeX (MiKTeX). Maple. , postscript, PSTricks , Matlab.
, . , , . BoundingBox Portrait/Landscape, .
. linux . , "".
, , , , () pdf.
EDIT: . gswin32c/pdfmanipulate postscript 3, "bounding" , :
%% BoundingBox: 34 128 567 667
%% HiResBoundingBox: 34.364390 128.875004 566.054069 666.071980
. %% BoundingBox %% HiResBoundingBox
postscript 2 (, , ), "" :
%% BoundingBox: 189 137 574 467
%% HiResBoundingBox: 189.485994 137.843996 573.299983 466.668478
%% BoundingBox: 135 179 484 587
(135 179 484 587) , postscript ( ), , Ghostview/Ghostscript, .
Ghostscript...
, 189 137 574 467 - ...
2. :
, , ,
, --- , , - :
, 2 , , Ghostscript.
Ghostscript, . Ghostscript/Calibrate http://www.mobileread.com/forums/archive/index.php/t-72885.html , , .
, Ghostscript, , .
" , " " 64- gswin64c.exe" , , ? , ......
, , : https://bugs.launchpad.net/ubuntu/+source/calibre/+bug/800551,
http://www.mobileread.com/forums/archive/index.php/t-103097.html,
- .
, , PostScript . PostScript, "%", . BoundingBox .
, . , %%, Ghostview. Ghostview , . , . , - , , Ghostview. %% Bounding Box, Caliber/pdfmipulate pdf , , %%. , "" .
, .....
Adobe. adobe,
" DSC
EPS , ,
EPS. . "
http://partners.adobe.com/public/developer/en/ps/5002.EPSF_Spec.pdf
Adobe "". , , PDF eps, .
Ghostscript DSC, , ProcessDSC true, ( BoundingBox ).
pdfmanipulate pdf .
. , LaTeX ps2pdf, PostScript, Ghostscript PDF. , Ghostscript , ?
.
, " ", , - , .....
, , "" ( , ) . , , , . , , , . .
, , ,
http://www.charlietanksley.net/philtex/reading-pdfs-on-portables/
, , ,
. , , , , , , Ghostscript epstopdf , , , , ...
, 2 , Ghostscript, BoundingBox, . 4 , ( ). "translate" PostScript (, 0,0, ). , , width = right-left height = top-bottom. PostScript Ghostscript pdfwrite, PDF.
, . , pdfwrite, , , . .
, , , , . - . , , . , , .
, Matlab, Maple, PSTricks, (, , ), , %%.
%% Bounding Box , , Ghostscript Caliber pdfwrite - .
, , , .
, postscript ? 420 .
, , .
EDIT 3. .
postscript , :
%% BoundingBox: 135 179 484 587
Ghostscript gswin64c/gswin32c , viz
for %%I in (*.ps,*.eps) do ("C:\Program Files\Ghostscript\gs9.04\bin\gswin64c.exe" -dSAFER -dNOPAUSE -dBATCH -dAutoRotatePages=/None -sDEVICE#bbox "%%I" 2> bounding)
:
%% BoundingBox: 145 189 475 574 %% HiResBoundingBox: 145.331574 189.485994 474.155986 573.299983
ps2pdf, Ghostscript gswin64c, ..
for %%I in (*.ps,*.eps) do ("C:\Program Files\MiKTeX 2.9\miktex\bin\x64\ps2pdf" %%I)
for %%I in (*.pdf) do ("C:\Program Files\Ghostscript\gs9.04\bin\gswin64c.exe" -dSAFER -dNOPAUSE -dBATCH -dAutoRotatePages=/None -sDEVICE#bbox "%%I" 2> bounding)
:
%% BoundingBox: 189 137 574 467 %% HiResBoundingBox: 189.395994 137.843996 573.299983 466.668478
, , ps pdf ps2pdf , . , ps2pdf - , , eps2pdf . , . , Ghostcript, . ( ) . - :
for %%I in (*.eps,*.ps) do ("C:\Program Files\MiKTeX 2.9\miktex\bin\x64\epstopdf" %%I)
for %%I in (*.pdf) do (
"C:\Program Files\Ghostscript\gs9.04\bin\gswin64c.exe" -dSAFER -dNOPAUSE -dBATCH -dAutoRotatePages=/None -sDEVICE#bbox "%%I" 2> bounding
"C:\Program Files (x86)\Calibre2\pdfmanipulate.exe" crop -o "%%~nICropped.pdf" -b bounding "%%I"
)