<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Philip Taylor wrote:<br>
</div>
<blockquote type="cite"
cite="mid:3a3e005f-c46e-7252-da3a-f9d548f16e61@Hellenic-Institute.Uk">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
[...] Once we realise this, we are in a position to write the code
:<br>
<blockquote><tt>% !TeX Program=XeTeX</tt><tt><br>
</tt><tt><br>
</tt><tt>\pdfpageheight = 210 mm</tt><tt><br>
</tt><tt>\pdfpagewidth = 297 mm</tt><tt><br>
</tt><tt><br>
</tt><tt>\hsize = \pdfpagewidth</tt><tt><br>
</tt><tt>\vsize = \pdfpageheight</tt><tt><br>
</tt><tt><br>
</tt><tt>\parindent = 1 cm</tt><tt><br>
</tt><tt><br>
</tt><tt>\output = {\advance \hoffset by -1 in \advance \voffset
by -1 in \shipout \box 255 }</tt><tt><br>
</tt><tt><br>
</tt><tt>\newcount \xmin</tt><tt><br>
</tt><tt>\newcount \ymin</tt><tt><br>
</tt><tt>\newcount \xmax</tt><tt><br>
</tt><tt>\newcount \ymax</tt><tt><br>
</tt><tt>\newcount \height</tt><tt><br>
</tt><tt>\newcount \width</tt><tt><br>
</tt><tt><br>
</tt><tt>\xmin = 1900</tt><tt><br>
</tt><tt>\ymin = 300</tt><tt><br>
</tt><tt><br>
</tt><tt>\width = 700</tt><tt><br>
</tt><tt>\height = 70</tt><tt><br>
</tt><tt><br>
</tt><tt>\xmax = \numexpr \xmin + \width \relax</tt><tt><br>
</tt><tt>\ymax = \numexpr \ymin + \height \relax</tt><tt><br>
</tt><tt><br>
</tt><tt>\setbox 0 = \vbox {\XeTeXpdffile Example-image-3.pdf }</tt><tt><br>
</tt><tt>\setbox 0 = \hbox to \width bp {\kern - \xmin bp \box 0
\hss}</tt><tt><br>
</tt><tt>\setbox 0 = \vbox to \height bp {\kern \dimexpr \ymax
bp - (\ht 0 + \dp 0) \box 0 \vss}</tt><tt><br>
</tt><tt><br>
</tt><tt>\setbox 0 = \hbox</tt><tt><br>
</tt><tt> \bgroup</tt><tt><br>
</tt><tt> \special {x:gsave}</tt><tt><br>
</tt><tt> \special {pdf:literal 0 0 \number \width \space
\number \height \space re W n }</tt><tt><br>
</tt><tt> \box 0</tt><tt><br>
</tt><tt> \special {x:grestore}</tt><tt><br>
</tt><tt> \egroup</tt><tt><br>
</tt><tt><br>
</tt><tt>\topglue 1 cm</tt><tt><br>
</tt><tt>\leavevmode \box 0</tt><tt><br>
</tt><tt><br>
</tt><tt>\end</tt><tt><br>
</tt></blockquote>
The file that I was seeking to clip, renamed as
Example-image-3.pdf, is attached. It is 100 cm wide by 20 cm tall
(plus bleed and trim marks), or about 2800 x 600 bp, so I would
normally want to express \xmin, \ymin, ..., \width in cm rather
than in bp, as is implied in the code above, but that would just
be syntactic sugar so I leave the code as I initially wrote it.
Note that my code does not correctly handle non-zero box depths as
it stands.<br>
</blockquote>
And for those who <i>like</i> syntactic sugar, and who want to be
able to handle included graphics with non-zero depth, herewith
today’s version :<br>
<blockquote><tt> % !TeX Program=XeTeX<br>
<br>
\pdfpageheight = 210 mm<br>
\pdfpagewidth = 297 mm<br>
<br>
\hsize = \pdfpagewidth<br>
\vsize = \pdfpageheight<br>
<br>
\parindent = 1 cm<br>
<br>
\output = {\advance \hoffset by -1 in \advance \voffset by
-1 in \shipout \box 255 }<br>
<br>
\newcount \xmin<br>
\newcount \ymin<br>
\newcount \xmax<br>
\newcount \ymax<br>
\newcount \height<br>
\newcount \width<br>
<br>
\def \then #1 {#1}<br>
<br>
\def \cm #1{\numexpr \dimexpr #1 cm / 65536 * 7200 / 7227
\relax \relax}<br>
\def \depth {\ifnum \dp 0 = 0 \then 0 \else -\the \numexpr
\dp 0 / 65536 \relax \fi}<br>
<br>
\xmin = \cm {67} % 1900<br>
\ymin = \cm {10.5} % 300<br>
<br>
\width = \cm {25} % 700<br>
\height = \cm {2.5} % 70<br>
<br>
\xmax = \numexpr \xmin + \width \relax<br>
\ymax = \numexpr \ymin + \height \relax<br>
<br>
\setbox 0 = \vbox {\XeTeXpdffile Example-image-3.pdf }<br>
\setbox 0 = \hbox to \width bp {\kern - \xmin bp \box 0
\hss}<br>
\setbox 0 = \vbox to \height bp {\kern \dimexpr \ymax bp -
(\ht 0 + \dp 0) \box 0 \vss}<br>
<br>
\setbox 0 = \hbox<br>
\bgroup<br>
\special {x:gsave}<br>
\special {pdf:literal 0 \depth \space \number \width
\space \number \height \space re W n }<br>
\box 0<br>
\special {x:grestore}<br>
\egroup<br>
<br>
\topglue 1 cm<br>
\leavevmode \box 0<br>
<br>
\end</tt><br>
</blockquote>
<br>
</body>
</html>