使用 PDFLaTeX 设置 BleedBox

使用 PDFLaTeX 设置 BleedBox

我的代码如下:

\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}

修剪框(绿色框)已成功修复(信用归于David Carlisle参考问题我如何才能动态地(使用宏)设置 PDF TrimBox 并使其独立于编译器?

现在我也在尝试修复出血框(蓝色框),但底部和左侧出了问题,我不确定我做错了什么。有人能给出建议吗?

在此处输入图片描述

答案1

我不太清楚它\g_@@_bleed_dim指的是什么。但您使用它作为页面左下角的修剪偏移量。

但是您还将出血框的左下角设置为\g_@@bleed_dim,这就是为什么两个框从同一位置开始的原因。

此外,(至少在我的系统上)N据说生成和变体已被弃用。错误提示应改用变V体。

因此,设置修剪和出血框的宏应该是:

%% 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 }
}

这将与您的修剪标记对齐。

目前代码仅适用于pdflatexlualatex应该很容易修复。xelatex可能需要更长的时间。

相关内容