3

My codes are follows:

\documentclass{book}

\usepackage{xparse}%%

\setlength{\paperheight}{9truein}%
\setlength{\paperwidth}{7truein}%

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

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

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

%% set crop size
\usepackage [a4, center,cam,info] { 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 { N }

% values for the Trim box
\tl_new:N \g_@@_trim_box_quadruple_tl
\tl_set:Nx \g_@@_trim_box_quadruple_tl {
   \dim_to_decimal_in_bp:N \g_@@_bleed_dim \space 
   \dim_to_decimal_in_bp:N \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 }
}

% values for the Bleed box
\tl_new:N \g_@@_bleed_box_quadruple_tl
\tl_set:Nx \g_@@_bleed_box_quadruple_tl {
   \dim_to_decimal_in_bp:N \g_@@_bleed_dim \space 
   \dim_to_decimal_in_bp:N \g_@@_bleed_dim \space
   \dim_to_decimal_in_bp:n { \paperwidth + 9pt + \g_@@_bleed_dim } \space
   \dim_to_decimal_in_bp:n { \paperheight + 9pt + \g_@@_bleed_dim }
}

%% special for use with XeTeX -- Not yet tested
\tl_new:N \g_@@_trim_special_tl
\tl_set:Nx \g_@@_trim_special_tl {
   pdf: ~ put ~ @thispage ~
   << ~ /TrimBox \space [ \g_@@_trim_box_quadruple_tl ] ~ >>
   << ~ /BleedBox \space [ \g_@@_bleed_box_quadruple_tl ] ~ >>
}

%% page attribute for use with LuaTeX and PDFTeX -- have to check with LuaLaTeX later
\tl_new:N \g_@@_trim_pageattr_tl
\tl_set:Nx \g_@@_trim_pageattr_tl {
   /TrimBox \space [ \g_@@_trim_box_quadruple_tl ]
   /BleedBox \space [ \g_@@_bleed_box_quadruple_tl ]
}


%% command to set the specials for xetex -- Not yet tested
\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

\setlength\oddsidemargin{6pc}
\addtolength\oddsidemargin{-1in}    % subtract out the 1 inch driver margin
\setlength\@tempdima{\paperwidth}
\addtolength\@tempdima{-\textwidth}
\addtolength\@tempdima{-6pc}
\setlength\evensidemargin{\@tempdima}
\addtolength\evensidemargin{-1in}


\makeatother %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\begin{document}

Test

\end{document}

Trim Box (Green color box) successfully fixed (Credit goes to David Carlisle refer the question How can I set the PDF TrimBox dynamically (with a macro) and compiler independent?)

Now I am trying to fix the Bleed box (Blue color box) too, but it went wrong bottom and left side, I am not sure what I did wrong in this. Can anyone suggest?

enter image description here

1

It's not exactly clear to me what \g_@@_bleed_dim is meant to refer to. But you're using it as the trim offset from the bottom left corner of the page.

But then you also set the bottom left corner of the bleed box to \g_@@bleed_dim, which is why your two boxes start at the same place.

Also, (on my system at least) generating and N variant is said to be deprecated. The error says to use a V variant instead.

So the macros to set the trim and bleed boxes should become:

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

% values for the Trim 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 }
}

% values for the Bleed box
\tl_new:N \g_@@_bleed_box_quadruple_tl
\tl_set:Nx \g_@@_bleed_box_quadruple_tl {
   \dim_to_decimal_in_bp:n { \g_@@_bleed_dim - 4.5pt } \space 
   \dim_to_decimal_in_bp:n { \g_@@_bleed_dim - 4.5pt } \space
   \dim_to_decimal_in_bp:n { \paperwidth + 4.5pt + \g_@@_bleed_dim } \space
   \dim_to_decimal_in_bp:n { \paperheight + 4.5pt + \g_@@_bleed_dim }
}

This will then line up with your trim marks.

Currently the code only works with pdflatex. lualatex should be easy to fix. xelatex might take a bit longer.

  • 2
    It works like a champ....thanks for your attention on my request.... – MadyYuvi Aug 21 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.