0

For my purpose, I first wish to stay with background package if possible.

It works fine when I have texts only. Background is really background (in terms of the layers).

enter image description here

But when includepdf or \fitallincludepdf (a modified version) is used to include some pdf files, the background come foreward, which I don't like.

enter image description here

If you look closely, the test is ABOVE the pdf file like an overlay.

How can I make it underneath?

The following is used to make exam-pic.pdf.

\documentclass{article}
\usepackage{pdfpages}
\begin{document}
    \includepdf[fitpaper]{example-image-A}
    \includepdf[fitpaper]{example-image-10x16}
\end{document}

Now the MWE.

\documentclass[a4paper, 12pt, scheme=plain, twosides]{ctexart}
\usepackage{lipsum}

\usepackage{background}
\backgroundsetup{
    placement=center,
    scale=6,
    contents={test}
}%


\usepackage{pdfpages}
\makeatletter
\newcommand\fitallincludepdf[2][]{%
    \AM@findfile{#2}%
    \setkeys{pdfpages}{#1}%
    \expandafter\AM@readlist\expandafter{\AM@pagestemp}%
    \@for\xxx:=\AM@pagelist\do{%
    \edef\AM@tmp{[\unexpanded{#1},pages=\xxx]}%
    \expandafter\includepdf\AM@tmp{#2}%
}}%
\makeatother

\begin{document}


\lipsum[1-10]
\cleardoublepage
\includepdf[pages=-]{exam-pic}
\fitallincludepdf[fitpaper,pages=-]{exam-pic}

\end{document}
6
  • example-image has a gray background. If you put your background text in the background it will be behind the gray and so not visible. Would that be ok? May 7, 2020 at 16:44
  • btw: ctexart it not really the right class for a minimal example. May 7, 2020 at 16:58
  • @UlrikeFischer That would be GREAT. In fact, that's exactly what I hope to achieve. The real texts are of more importance and I hope these contents can be on the TOP layer and the background (texts and/or images) be just in the background.
    – CasperYC
    May 7, 2020 at 23:36
  • I thought that you want this, but it won't work. You can not split an included image like this. you need pdf's with a transparent background. May 7, 2020 at 23:41
  • @UlrikeFischer Sorry about the confusion. The image might be a bad example. All I need is that to put the image/pdf on top of the background text...
    – CasperYC
    May 8, 2020 at 7:12

1 Answer 1

1

The background packages uses everypage and this places its hook so that it will on top of \includepdf. An alternative is to use the eso-pic commands instead of background.

\documentclass[a4paper,12pt]{article}

\usepackage{pdfpages,tikzducks}

\AddToShipoutPictureBG{\AtPageCenter{\hspace{-5cm}\tikz[scale=8]\duck;}}

\begin{document}
\includepdf[pages=-]{example-image}
\end{document}

enter image description here

Another option is to move the \includepdf in the foreground, but this will also affect text inserted with page command which will now be behind the picture:

\documentclass[a4paper,12pt]{article}

\usepackage{pdfpages,lipsum}

\usepackage{background}
\backgroundsetup{
    placement=center,
    scale=25,
    contents={\bfseries Text}
}%

\begin{document}
\includepdf[pages=-,pagecommand={\lipsum[1-4]}]{example-image}


\makeatletter
\def\AM@AddToShipoutPicture{\AddToShipoutPictureFG*}
\makeatother

\includepdf[pages=-,pagecommand={\lipsum[1-4]}]{example-image}
\end{document}

enter image description here

1
  • Sorry about the late "acceptance" of your answer as I need VPN to access SE from China. Otherwise it's VERY slow and nearly impossbile to visit the site.
    – CasperYC
    May 17, 2020 at 12:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .