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...
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:43pdf: ~ put ~ @pages ~instead ofpdf: ~ put ~ @thispage ~in my definitions, thenTrimBoxnot showing in all pages, please advise... – MadyYuvi Sep 16 '21 at 07:04LaTeX2e <2021-06-01> patch level 1. – Ulrike Fischer Sep 16 '21 at 07:21