如何将图像添加到 pdf 文档中?

如何将图像添加到 pdf 文档中?

我想将 pdf 作为特定页面的背景并在左下角添加图片。

\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{pdfpages}


\begin{document}
    \begin{figure} \centering
        \begin{tikzpicture}[      
            every node/.style={anchor=south west,inner sep=0pt},
            x=1mm, y=1mm,
            ]   
            \node (fig1) at (0,0)
            {\includepdf{pdfile}};
            \node (fig2) at (3,3)
            {\includegraphics[scale=0.21]{example-image-b}};  
        \end{tikzpicture}
    \end{figure}
\end{document}

答案1

可以使用新的 shipout 钩子机制(需要 LaTeX 格式2020/10/01):

\documentclass[12pt]{article}
\usepackage{graphicx}

\begin{document}
    \AddToHookNext{shipout/background}{\put(0,0){\raisebox{-\paperheight}{\includegraphics[width=\paperwidth]{example-image-b}}}}%
    Dummy Text.
\end{document}

坐标(0,0)为页面左上角。因此\raisebox{-\paperheight}{...}

答案2

我会使用fancyhdr包并将图像放在左下角的 fancyfoot 中。看看我的代码 - 您的代码有一些细微的更改,我希望这仍然没问题。我插入了很多注释以使其更易于理解。如果您不想再使用 fancy pagestyle,您可以将其更改为 plain(可选)。

\documentclass[12pt]{article}
\usepackage{pdfpages}
\usepackage{fancyhdr}
\usepackage{tikz}
\usepackage{graphicx}

\renewcommand{\headrulewidth}{0pt} % remove the line in the header that comes with fancyhdr
\fancyhf{} % remove page numbers on the bottom center
\fancyfoot[L]{ %fancyfoot with the argument "L" means anything you want will be put at the bottom left. Change the "L" to "R" if you want it to be on the bottom right
    \begin{tikzpicture}[      
        every node/.style={anchor=south west,inner sep=0pt},
        x=1mm, y=1mm,
        ]   
        \node (fig2) at (3,3)
        {\includegraphics[scale=0.21]{example-image-b}};  
    \end{tikzpicture}
    }

\fancypagestyle{plain}{ % optional: define a plain fancyheader / fancyfoot if you don't want to use the fancy pagestyle for certain pdf files
    \fancyhf{}
    }

\begin{document}
    \includepdfset{pages=-, pagecommand=\thispagestyle{fancy}} % fancy page style with image on the bottom left
    
    \includepdf{\detokenize{document.pdf}}
    
    \includepdfset{pages=-, pagecommand=\thispagestyle{plain}} % plain page style without image on the bottom left
    
    \includepdf{\detokenize{document.pdf}}
    
\end{document}

相关内容