Skip to content

Instantly share code, notes, and snippets.

@przemoc
Last active February 6, 2018 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save przemoc/1039310 to your computer and use it in GitHub Desktop.
Save przemoc/1039310 to your computer and use it in GitHub Desktop.
Converting EPS w/ crop marks to PDF w/ TrimBox+CropBox and final JPEG
#!/bin/sh
# SPDX-License-Identifier: MIT
## Copyright (C) 2011 Przemyslaw Pawelczyk <przemoc@gmail.com>
##
## This script is licensed under the terms of the MIT license.
## https://opensource.org/licenses/MIT
#
# Converting EPS w/ crop marks to PDF w/ TrimBox+CropBox and final JPEG
# Simple script with brief explanation
# 2+3D 40th anniversary issue (10 years) cover contest
# http://2plus3d.pl/artykuly/konkurs-na-okladke-40-numeru-2plus3d
# EPS in: http://dl.dropbox.com/u/1691461/2plus3d/szablon.zip
# EPS file name w/o extension
EPS=szablon
# Sanitize EPS
eps2eps $EPS.eps $EPS-eps2eps.eps
# Convert it to PDF
epstopdf --hires $EPS-eps2eps.eps
# Prepare LaTeX file using previously obtained PDF, and define there some PDF
# boxes as in the comments from original EPS
## (BTW you can create your cover now in LaTeX, have fun!)
cat >$EPS-withcrop.tex <<_EOF
\documentclass{article}
\usepackage[paperwidth=665.1495bp,paperheight=865.7012bp]{geometry}
\usepackage{pdfpages}
\begin{document}
\pagestyle{empty}
\pdfpageattr{%
% Below MediaBox is commented, because pdflatex outputs its own according to
% page size, which has a bit lesser but still acceptable accuracy.
%% 234.65mm x 305.40mm
%/MediaBox[0 0 665.1495 865.7012]
%% 209.25mm x 280.00mm
/TrimBox[36.0000 36.0000 629.1495 829.7012]
/CropBox[36.0000 36.0000 629.1495 829.7012]
}
\includepdf[noautoscale=true]{$EPS-eps2eps}
\end{document}
_EOF
# Generate final PDF
pdflatex $EPS-withcrop.tex
# Convert it to high-quality trimmed JPEG
convert -verbose -density 437x435.4 -define pdf:use-trimbox=true $EPS-withcrop.pdf \
-resize 33.333% -quality 100 $EPS-trimmed.jpg
@przemoc
Copy link
Author

przemoc commented Feb 6, 2018

commit 74489e18be19ecb24f74a5ad68838d6905fa816c
Author:     Przemyslaw Pawelczyk <przemoc@gmail.com>
AuthorDate: 2018-02-06 13:53:53 +0100

    2+3d-szablon-eps-to-pdf+jpg.sh: Relicense to MIT.

commit cdb1724e53d526c10f972c6ef96963143520ea09
Author:     Przemyslaw Pawelczyk <przemoc@gmail.com>
AuthorDate: 2018-02-06 13:55:26 +0100

    Add SPDX License Identifier.

    The Software Package Data Exchange (SPDX) is a good initiative, it has
    matured over time and deserves accelerated adoption in open-source.

    https://spdx.org/learn
    https://spdx.org/using-spdx
    https://spdx.org/license-list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment