Search code examples
svgbackgroundlatex

How to insert a background image in only one page using latex?


I am writing a document and I need to insert a background on only the third page (which is sort of a second cover of the document), but I have troubles in doing it, since all I tried resulted in the image not appearing or a background with the word "Draft".

\documentclass[epsfig,a4paper,11pt,titlepage,twoside,openany]{book}
\usepackage{epsfig}
\usepackage{plain}
\usepackage{setspace}
\usepackage[paperheight=29.7cm,paperwidth=21cm,outer=1.5cm,inner=2.5cm,top=2cm,bottom=2cm]{geometry} % layout setting
\usepackage{titlesec} % custom setup title of chanpter
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage[inkscapeformat=pdf]{svg}
\usepackage[pages=some]{background}
\usepackage{eso-pic}  

\newcommand\BackgroundPic{%
\put(0,0){%
\parbox[b][\paperheight]{\paperwidth}{%
\vfill
\centering
\includesvg[width=\paperwidth]{logo.svg}
\vfill
}}}
\pagenumbering{gobble}
\input{front}
\cleardoublepage
\BgThispage
\lipsum[1-3]
\cleardoublepage

With this code the result is the "Draft" word appearing as the background image. I also tried to use a png image, thinking that the svg conversion could be the problem, but apparently it's not since using a png image results in the same "Draft" word appearing in the background.

EDIT: As a minimal reproducible example:

\documentclass[epsfig,a4paper,11pt,titlepage,twoside,openany]{book}
\usepackage{epsfig}
\usepackage{plain}
\usepackage{setspace}
\usepackage[paperheight=29.7cm,paperwidth=21cm,outer=1.5cm,inner=2.5cm,top=2cm,bottom=2cm]{geometry} % layout setting
\usepackage{titlesec} % custom setup title of chanpter
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage[inkscapeformat=pdf]{svg}
\usepackage[pages=some]{background}

\usepackage{eso-pic}

\newcommand\BackgroundPic{%
\put(0,0){%
\parbox[b][\paperheight]{\paperwidth}{%
\vfill
\centering
\includesvg[width=\paperwidth]{logo.png}
\vfill
}}}

\usepackage[latin1]{inputenc} % Windows;
\singlespacing

\begin{document}

  \pagenumbering{gobble}
  \cleardoublepage
  \BgThispage
  \lipsum[1-3]
  \cleardoublepage
 
\end{document}

The image, saved as logo is found at the following Link


Solution

  • You no longer need all these eso-pic and background package. Latex now has a build in support for adding stuff to the background via its hook mechanism:

    \documentclass[a4paper,11pt,titlepage,twoside,openany]{book}
    \usepackage{epsfig}
    \usepackage{plain}
    \usepackage{setspace}
    \usepackage[paperheight=29.7cm,paperwidth=21cm,outer=1.5cm,inner=2.5cm,top=2cm,bottom=2cm]{geometry} % layout setting
    \usepackage{titlesec} % custom setup title of chanpter
    \usepackage{graphicx}
    \usepackage{lipsum}
    \usepackage[inkscapeformat=pdf]{svg}
    
    \usepackage[utf8]{inputenc} % Windows;
    \singlespacing
    
    \usepackage{tikz}
    
    \AddToHookNext{shipout/background}{
      \begin{tikzpicture}[remember picture,overlay]
      \node at (current page.center) {
        \includegraphics[width=16cm]{example-image-duck}
      };
      \end{tikzpicture}
    }
    
    \begin{document}
    
      \pagenumbering{gobble}
      \cleardoublepage
      \lipsum[1-3]
      \cleardoublepage
     
    \end{document}
    

    enter image description here