0

For the book to be published, I need to provide a different /BleedBox for odd and even pages. I tried to achieve this through \pdfpageattr which works well if only used once in my document, for even/odd page separation, I tried:

\documentclass[numbers=noenddot,10pt,paper=155mm:230mm]{scrbook}
\usepackage[frame,width=169.8truemm,height=247.4truemm,cam,pdftex,cross]{crop}
\setlength{\voffset}{7.4mm}
\setlength{\hoffset}{7.4mm}

\usepackage{ifthen,everypage}

\newcommand{\checkthatpage}[2]{%
    \ifthenelse{\isodd{\value{page}}}%
    {#1}%
    {#2}%
}%

\AddEverypageHook{\checkthatpage{An even page with no bleed left\noexpand\pdfpageattr{
            /TrimBox [20.976 28.346 460.346 680.315]
            /BleedBox [29.480 19.843 460.346 688.819]
    }}{An odd page with no bleed right\noexpand\pdfpageattr{
    /TrimBox [20.976 28.346 460.346 680.315]
    /BleedBox [20.976 19.843 468.850 688.819]
}}}

\begin{document}
This page is:
\newpage
This page is:
\newpage
This page is:
\newpage
This page is:
\newpage
\end{document}

However with this appraoch I am not getting any boxes into the output at all, I checked the PDF in an editor. What am I doing wrong? Is it due to expansion, or because of the macro position? There is no /BleedBox in the output at all.

Bonus question: Can I automate the calculation by just setting an odd/even relative bleed margin and get the /BleedBox from the settings for the crop package?

Answer to bonus question: With the help of @Ulrike Fischer in her answer and some additions from other questions and answers, I was able to figure this out by myself, see my own answer.

TobiBS
  • 5,240

3 Answers3

1

You can use atbegshi. If needed switch the odd/even values, I copied the values into the pages. Be aware that you are overwriting the \pdfpageattr register. If other parts of your code write to it too, the content will be lost.

% uncompress the pdf: 
\pdfcompresslevel0
\pdfobjcompresslevel0

\documentclass[numbers=noenddot,10pt,paper=155mm:230mm]{scrbook}
\usepackage[frame,width=169.8truemm,height=247.4truemm,cam,pdftex,cross]{crop}
\setlength{\voffset}{7.4mm}
\setlength{\hoffset}{7.4mm}

\usepackage{atbegshi}

\AtBeginShipout
{\ifodd\value{page}
   \pdfpageattr{
            /TrimBox [20.976 28.346 460.346 680.315]
            /BleedBox [29.480 19.843 460.346 688.819]
     }
 \else 
    \pdfpageattr{
      /TrimBox [20.976 28.346 460.346 680.315]
      /BleedBox [20.976 19.843 468.850 688.819]
      }
 \fi     
}

\begin{document}
This page is: /TrimBox [20.976 28.346 460.346 680.315] /BleedBox [29.480 19.843 460.346 688.819] 
\newpage
This page is: /TrimBox [20.976 28.346 460.346 680.315] /BleedBox [20.976 19.843 468.850 688.819] 
\newpage
This page is: /TrimBox [20.976 28.346 460.346 680.315] /BleedBox [29.480 19.843 460.346 688.819] 
\newpage
This page is: /TrimBox [20.976 28.346 460.346 680.315] /BleedBox [20.976 19.843 468.850 688.819] 
\newpage
\end{document}
Ulrike Fischer
  • 327,261
0

Try this version of your MWE.

% bleedboxprob.tex SE 546714

\documentclass[numbers=noenddot,10pt,paper=155mm:230mm]{scrbook}
\usepackage[frame,width=169.8truemm,height=247.4truemm,cam,pdftex,cross]{crop}
\setlength{\voffset}{7.4mm}
\setlength{\hoffset}{7.4mm}

\usepackage{ifthen,everypage}

\newcommand{\checkthatpage}[2]{%
    \ifthenelse{\isodd{\value{page}}}%
    {#1}%
    {#2}%
}%

\AddEverypageHook{\checkthatpage{An even page with no bleed left\noexpand\pdfpageattr{
            /TrimBox [20.976 28.346 460.346 680.315]
            /BleedBox [29.480 19.843 460.346 688.819]
    }}{An odd page with no bleed right\noexpand\pdfpageattr{
    /TrimBox [20.976 28.346 460.346 680.315]
    /BleedBox [20.976 19.843 468.850 688.819]
}}}

\begin{document}
This page is: \checkthatpage{odd}{even}
\newpage
This page is: \checkthatpage{odd}{even}
\newpage
This page is: \checkthatpage{odd}{even}
\newpage
This page is: \checkthatpage{odd}{even}
\newpage
\end{document}

There seems to be a contradiction in the output. Perhaps you would want to check your code.

Peter Wilson
  • 28,066
  • Hi @Peter Wilson: If I need to call \checkthatpage on every page, then there is no purpose in setting the \AddEverypageHook. I need this for a 190 page document and I cannot manually set the PDF output there. – TobiBS May 28 '20 at 17:25
  • @TobiBS If you ran my MWE you would have seen that my checkthatpage{odd}{even} gave different results to your \AddEveryPageHook I was not suggesting that you put \checkthatpage on every page but take a look at what your \AddEverypageHook does. – Peter Wilson May 28 '20 at 18:55
  • Hi @Peter Wilson, thanks for pointing that out, but this was not my main issue. The main issue was, that while the visible text was sent to the PDF, the \pdfpageattr was not sent to the PDF for whatever reason. However @Ulrike Fischer provided a working solution for me. – TobiBS May 28 '20 at 19:08
0

With the answer of @Ulrike Fischer, which I accepted and the solutions given in How can I set the PDF TrimBox dynamically (with a macro) and compiler independent? and Set BleedBox using PDFLaTeX I also came up with an answer for my bonus question, which allows automatic computation of the boxes based on existing and given values. \hoffset, \voffset, \stockwidth and \stockheight are values from crop. Additionally you can define \outsidebleed which is the additional margin on the outside edges of a mounted page.

Maybe it is of help to someone looking here in the future.

\documentclass[numbers=noenddot,10pt,paper=155mm:230mm]{scrbook}
\usepackage[frame,width=169.8truemm,height=247.4truemm,cam,pdftex,cross]{crop}
\setlength{\voffset}{7.4mm}
\setlength{\hoffset}{7.4mm}

\usepackage{xparse}
\ExplSyntaxOn

%% define bleed for the three outside edges
\dim_new:N \outsidebleed 
\dim_set:Nn \outsidebleed { 3mm }

%% values for the Trim box on all pages
\tl_new:N \trim_box
\tl_set:Nx \trim_box {
    \dim_to_decimal_in_bp:n { \hoffset} \space 
    \dim_to_decimal_in_bp:n { \stockheight - \paperheight - \voffset} \space
    \dim_to_decimal_in_bp:n { \paperwidth + \hoffset } \space
    \dim_to_decimal_in_bp:n { \stockheight - \voffset }
}

%% values for the Bleed box on odd pages
\tl_new:N \bleed_box_odd
\tl_set:Nx \bleed_box_odd {
    \dim_to_decimal_in_bp:n { \hoffset } \space 
    \dim_to_decimal_in_bp:n { \stockheight - \paperheight - \voffset } \space
    \dim_to_decimal_in_bp:n { \paperwidth + \hoffset + \outsidebleed } \space
    \dim_to_decimal_in_bp:n { \stockheight - \voffset + \outsidebleed }
}

%% values for the Bleed box on even pages
\tl_new:N \bleed_box_even
\tl_set:Nx \bleed_box_even {
    \dim_to_decimal_in_bp:n { \hoffset - \outsidebleed } \space 
    \dim_to_decimal_in_bp:n {  \stockheight - \paperheight - \voffset - \outsidebleed } \space
    \dim_to_decimal_in_bp:n { \paperwidth + \hoffset } \space
    \dim_to_decimal_in_bp:n { \stockheight - \voffset + \outsidebleed }
}

%% page attribute for odd pages
\tl_new:N \pageattr_odd
\tl_set:Nx \pageattr_odd {
    /TrimBox \space [ \trim_box ]
    \space
    /BleedBox \space [ \bleed_box_odd ]
}

%% page attribute for even pages
\tl_new:N \pageattr_even
\tl_set:Nx \pageattr_even {
    /TrimBox \space [ \trim_box ]
    /BleedBox \space [ \bleed_box_even ]
}

%% command to set the page attribute
\NewDocumentCommand{\setpdfpageattreven}{}{\exp_args:Ne \pdfpageattr { \pageattr_even } }
\NewDocumentCommand{\setpdfpageattrodd}{}{\exp_args:Ne \pdfpageattr { \pageattr_odd } }

%% just a macro to show some debug info
\NewDocumentCommand { \debuginfo } { } {
    \par\medskip\noindent
    pageattribute \space even: \\
    \mbox { \texttt { \pageattr_even } }
    \par\medskip\noindent
    pageattribute \space odd: \\
    \mbox { \texttt { \pageattr_odd } }
}

\ExplSyntaxOff

\usepackage{atbegshi}

\AtBeginShipout
{\ifodd\value{page}
    \setpdfpageattrodd
    \else 
    \setpdfpageattreven
    \fi     
}

\begin{document}
\debuginfo
Test
\newpage
Test
\newpage
Test
\newpage
Test
\newpage
Test
\newpage
Test
\newpage
Test
\end{document}
TobiBS
  • 5,240