Philip Taylor wrote:
[...] Once we realise this, we are in a position to write the code :

    % !TeX Program=XeTeX

    \pdfpageheight = 210 mm
    \pdfpagewidth = 297 mm

    \hsize = \pdfpagewidth
    \vsize = \pdfpageheight

    \parindent = 1 cm

    \output = {\advance \hoffset by -1 in \advance \voffset by -1 in
    \shipout \box 255 }

    \newcount \xmin
    \newcount \ymin
    \newcount \xmax
    \newcount \ymax
    \newcount \height
    \newcount \width

    \xmin = 1900
    \ymin = 300

    \width = 700
    \height = 70

    \xmax = \numexpr \xmin + \width \relax
    \ymax = \numexpr \ymin + \height \relax

    \setbox 0 = \vbox {\XeTeXpdffile Example-image-3.pdf }
    \setbox 0 = \hbox to \width bp {\kern - \xmin bp \box 0 \hss}
    \setbox 0 = \vbox to \height bp {\kern \dimexpr \ymax bp - (\ht 0
    + \dp 0) \box 0 \vss}

    \setbox 0 = \hbox
        \bgroup
            \special {x:gsave}
            \special {pdf:literal 0 0 \number \width \space \number
    \height \space re W n }
            \box 0
            \special {x:grestore}
        \egroup

    \topglue 1 cm
    \leavevmode \box 0

    \end

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.
And for those who /like/ syntactic sugar, and who want to be able to handle included graphics with non-zero depth, herewith today’s version :

        % !TeX Program=XeTeX

        \pdfpageheight = 210 mm
        \pdfpagewidth = 297 mm

        \hsize = \pdfpagewidth
        \vsize = \pdfpageheight

        \parindent = 1 cm

        \output = {\advance \hoffset by -1 in \advance \voffset by -1
   in \shipout \box 255 }

        \newcount \xmin
        \newcount \ymin
        \newcount \xmax
        \newcount \ymax
        \newcount \height
        \newcount \width

        \def \then #1 {#1}

        \def \cm #1{\numexpr \dimexpr #1 cm / 65536 * 7200 / 7227
   \relax \relax}
        \def \depth {\ifnum \dp 0 = 0 \then 0 \else -\the \numexpr \dp
   0 / 65536 \relax \fi}

        \xmin = \cm {67} % 1900
        \ymin = \cm {10.5} % 300

        \width = \cm {25} % 700
        \height = \cm {2.5} % 70

        \xmax = \numexpr \xmin + \width \relax
        \ymax = \numexpr \ymin + \height \relax

        \setbox 0 = \vbox {\XeTeXpdffile Example-image-3.pdf }
        \setbox 0 = \hbox to \width bp {\kern - \xmin bp \box 0 \hss}
        \setbox 0 = \vbox to \height bp {\kern \dimexpr \ymax bp - (\ht
   0 + \dp 0) \box 0 \vss}

        \setbox 0 = \hbox
            \bgroup
            \special {x:gsave}
            \special {pdf:literal 0 \depth \space \number \width \space
   \number \height \space re W n }
            \box 0
            \special {x:grestore}
            \egroup

        \topglue 1 cm
        \leavevmode \box 0

        \end


Attachment: Example-image-3.pdf
Description: Adobe PDF document

Reply via email to