1

My tags are follows (Thanks to David Carlisle: How can I set the PDF TrimBox dynamically (with a macro) and compiler independent? and David Purton Set BleedBox using PDFLaTeX)

%\pdfcompresslevel0
\documentclass{article}
\usepackage{graphicx}
\usepackage{xparse}

\ExplSyntaxOn\makeatletter %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% bleed value (keyval class option in real document) \dim_new:N \g_@@bleed_dim \dim_set:Nn \g@@_bleed_dim { 3mm }

%% set page size (and other stuff in the real document) \usepackage { geometry } \geometry { papersize = { 185mm , 245mm } }

%% set crop size \usepackage [ center ] { crop } \CROP@size { \dim_eval:n { \paperwidth + 2 \g_@@bleed_dim } } { \dim_eval:n { \paperheight + 2 \g@@_bleed_dim } }

%% new variant \cs_generate_variant:Nn \dim_to_decimal_in_bp:n { V }

% values for the rim box \tl_new:N \g_@@trim_box_quadruple_tl \tl_set:Nx \g@@trim_box_quadruple_tl { \dim_to_decimal_in_bp:V \g@@bleed_dim \space \dim_to_decimal_in_bp:V \g@@bleed_dim \space \dim_to_decimal_in_bp:n { \paperwidth + \g@@bleed_dim } \space \dim_to_decimal_in_bp:n { \paperheight + \g@@_bleed_dim } }

%% special for use with XeTeX \tl_new:N \g_@@trim_special_tl \tl_set:Nx \g@@trim_special_tl { pdf: ~ put ~ @thispage ~ << ~ /TrimBox \space [ \g@@_trim_box_quadruple_tl ] ~ >> }

%% page attribute for use with LuaTeX and PDFTeX \tl_new:N \g_@@trim_pageattr_tl \tl_set:Nx \g@@trim_pageattr_tl { /TrimBox \space [ \g@@_trim_box_quadruple_tl ] }

%% command to set the specials for xetex \cs_new:Npn @@_special:n #1 { \AtBeginShipout { \immediate \special { #1 } } \immediate \special { #1 } }

%% command to set the page attributes for pdftex/luatex \cs_new:Npn @@_pdfpageattr:n #1 { \pdfpageattr { #1 } }

%% make a variants to make sure we get the expaned content \cs_generate_variant:Nn @@_special:n { V } \cs_generate_variant:Nn @@_pdfpageattr:n { V }

%% [A] THIS DOES NOT WORK! %% set the trim box according to engine \bool_if:nTF { \sys_if_engine_luatex_p: || \sys_if_engine_pdftex_p: } { @@pdfpageattr:V \g@@trim_pageattr_tl } { \sys_if_engine_xetex:TF { \usepackage{atbegshi} @@_special:V \g@@_trim_special_tl } { ERROR: UNKOWN MACHINE! } }

%% just a macro to show some debug info \NewDocumentCommand { \debuginfo } { } { \par\noindent Machine: ~ \texttt{ \c_sys_engine_str }

\par\bigskip\noindent special: \ \mbox { \texttt { \g_@@_trim_special_tl } }

\par\medskip\noindent pageattribute: \ \mbox { \texttt { \g_@@_trim_pageattr_tl } } }

\ExplSyntaxOff\makeatother %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% [B] THIS WORKS! %% for pdftex and luatex %\pdfpageattr { /TrimBox [8.50392 8.50392 532.91336 702.99211] } %% for xetex %\usepackage{atbegshi} %\AtBeginShipout { \special { pdf: put @thispage << /TrimBox [8.50392 8.50392 532.91336 702.99211] >> } } %\special { pdf: put @thispage << /TrimBox [8.50392 8.50392 532.91336 702.99211] >> }

\begin{document} \section*{Test Document} \debuginfo \clearpage Just another page \ldots

\newpage

\begin{figure}[p!] \includegraphics{example-image-a} \end{figure}

\end{document}

I'm using XeLaTeX above works fine and got TrimBox in all pages, but when a full page float comes then the TrimBox vanished, please suggest how to achieve that too... But the same works fine for all pages when using PDFLaTeX...

MadyYuvi
  • 13,693

2 Answers2

1

Sorry I don't know why it vanishes and I don't have the time to look. If you want the same trimbox on all pages you could use pdf: ~ put ~ @pages ~ instead. Or you try the new pdfmanagement:

\DocumentMetadata{}
\documentclass{article}

\usepackage{graphicx} \ExplSyntaxOn \pdfmanagement_add:nnn{Page}{Trimbox}{[8.50392~8.50392~532.91336~702.99211]} % or %\pdfmanagement_add:nnn{Pages}{Trimbox}{[8.50392~8.50392~532.91336~702.99211]} \ExplSyntaxOff \begin{document}

\section*{Test Document} \clearpage Just another page \ldots

\newpage

\begin{figure}[p!] \includegraphics{example-image-a} \end{figure}

\end{document}

This works with all engines.

Ulrike Fischer
  • 327,261
  • Thanks for the suggestion, I've tested it and couldn't find the Trim box in all pages, my version is This is XeTeX, Version 3.141592653-2.6-0.999993 (MiKTeX 21.3) (preloaded format=xelatex 2021.9.6) 16 SEP 2021 12:11 entering extended mode **./test.tex (test.tex LaTeX2e <2020-10-01> patch level 4 L3 programming layer <2021-02-18> – MadyYuvi Sep 16 '21 at 06:43
  • Also, if I use pdf: ~ put ~ @pages ~ instead of pdf: ~ put ~ @thispage ~ in my definitions, then TrimBox not showing in all pages, please advise... – MadyYuvi Sep 16 '21 at 07:04
  • I tested with a current miktex and it worked fine LaTeX2e <2021-06-01> patch level 1. – Ulrike Fischer Sep 16 '21 at 07:21
0

This is basically the same as Ulrike's answer, except I used your code as a base (and fixed the Trimbox→TrimBox typo in Ulrike's answer).

I suggest you do use the new pdfmanagement code, which currently works and will certainly be more reliable in the long term.

This works in all three engines with my tests:

\DocumentMetadata{uncompress}
\documentclass{article}
\usepackage{graphicx}

\ExplSyntaxOn\makeatletter %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% bleed value (keyval class option in real document) \dim_new:N \g_@@bleed_dim \dim_set:Nn \g@@_bleed_dim { 3mm }

%% set page size (and other stuff in the real document) \usepackage { geometry } \geometry { papersize = { 185mm , 245mm } }

%% set crop size \usepackage [ center ] { crop } \CROP@size { \dim_eval:n { \paperwidth + 2 \g_@@bleed_dim } } { \dim_eval:n { \paperheight + 2 \g@@_bleed_dim } }

%% new variant \cs_generate_variant:Nn \dim_to_decimal_in_bp:n { V }

% values for the TrimBox \tl_new:N \g_@@trim_box_quadruple_tl \tl_set:Nx \g@@trim_box_quadruple_tl { \dim_to_decimal_in_bp:V \g@@bleed_dim \space \dim_to_decimal_in_bp:V \g@@bleed_dim \space \dim_to_decimal_in_bp:n { \paperwidth + \g@@bleed_dim } \space \dim_to_decimal_in_bp:n { \paperheight + \g@@_bleed_dim } }

% set the TrimBox \pdfmanagement_add:nnx { Page } { TrimBox } { [ \g_@@_trim_box_quadruple_tl ] }

\ExplSyntaxOff\makeatother %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document} \section*{Test Document}

\clearpage

Just another page \ldots

\clearpage

\begin{figure}[p!] \includegraphics{example-image-a} \end{figure}

\end{document}

David Purton
  • 25,884
  • Much thanks for your reply, currently, I'm not in system, I'll confirm by tomorrow...Thanks – MadyYuvi Nov 22 '22 at 15:30
  • I received error as Undefined control sequence. l.1 \DocumentMetadata and I'm using XeTeX, Version 3.141592653-2.6-0.999993 (MiKTeX 21.3) Please advise – MadyYuvi Nov 23 '22 at 15:35
  • @MadyYuvi Your TeX distribution is too old. Upgrade MiKTeX in both admin and user mode – David Purton Nov 23 '22 at 20:48