Context
For a personal project I would like to have a tikzpicture on every page that borders the text and all that is on there. I started with LuaLaTeX and wanted to add only a few Chinese characters, and tested \usepackage[UTF8]{ctex}. I noticed how it unwantedly changed the spacing in the rest of my document. Then I tested XeLatex as the compiler and the corresponding xeCJK package, which seemed to do what I wanted. However, I noticed that the relative positioning with respect to the page that I had created while using the background package and an additional tikzpicture on top of that were in the incorrect positions. I used the code from the following post Positioning relative to page in TikZ and answer by 'romain.bqt4', such that the top-left corner of the page has coordinates (0, 0) and the bottom-right has coordinates (1, 1). Then I Googled the problem and it seemed to be that XeLaTeX engine does not work well with the overlay option in \begin{tikzpicture}. Also I found out that nested tikzenvironments are not 'the way to go', so I am trying to implement this properly. I think I fixed most of the issues I had, but then came across 'Dimension too large.' at every \newpage command. A very inconsistent error, as while I tried to provide code for a MWE, recompiling the code does not give the errors all the time. It seems that using the \input command somehow causes this, as I am trying around now. See the code for a (hopefully) MWE.
Code
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{background}
\usepackage[T1]{fontenc}
\usepackage{xeCJK}
\setCJKmainfont{NotoSansSC-Bold.otf}
\usepackage{lipsum}
\usepackage[textwidth=24cm, centering, margin=2cm, showframe]{geometry}
\usetikzlibrary{shapes.misc, positioning, calc}
\SetBgAngle{0}
\SetBgScale{1}
\SetBgOpacity{1}
\SetBgContents{
\begin{tikzpicture}[remember picture,shift=(current page.north west)] % for XeLaTeX
\begin{scope}[x={(current page.north east)},y={(current page.south west)}]
\node (logo) at (0.5, 0.95) {\pic};
\draw[rounded corners=10pt, line width = 2pt] (logo) -| (0.05, 0.025) -- (0.95, 0.025) |- (logo);
\end{scope}
\end{tikzpicture}
}
\newcommand*{\pic}{\includegraphics[height = 2cm]{example-image.pdf}}
\pagestyle{empty}
\begin{document}
% The 'nested' tikzpicture
\input{mwe} % The following lines are in mwe.tex
% \begin{tikzpicture}[remember picture,overlay,shift=(current page.north west)]
% \begin{scope}[x={(current page.north east)},y={(current page.south west)}]
% \node at (1/2, 1/2) {你好};
% \node at (1/5, 1/5) {\pic};
% \node at (2/5, 1/5) {\pic};
% \node at (3/5, 1/5) {\pic};
% \node at (4/5, 1/5) {\pic};
% \node at (1/5, 2/5) {\pic};
% \node at (2/5, 2/5) {\pic};
% \node at (3/5, 2/5) {\pic};
% \node at (4/5, 2/5) {\pic};
% \node at (1/5, 3/5) {\pic};
% \node at (2/5, 3/5) {\pic};
% \node at (3/5, 3/5) {\pic};
% \node at (4/5, 3/5) {\pic};
% \draw[dashed, line width = 2pt] (0.05, 0.785) -- (0.95, 0.785);
% \node at ({1/3}, 0.855) {\pic};
% \node at ({2/3}, 0.855) {\pic};
% \end{scope}
% \end{tikzpicture}
\newpage
\lipsum[1]
\newpage
\lipsum[2]
\end{document}
Output
This is the output I would like to have and it seems to work.

Question
What causes these dimension errors and why did I not see them when using LuaLaTeX?
\picis a tikz command so you probably shouldn't use it as a custom command. – Andrew Stacey Apr 22 '22 at 11:50\AddToHook{shipout/background}{\put(0pt,-\paperheight) {...}}will put the contents at the lower left corner of the page. No package needed. – John Kormylo Apr 22 '22 at 15:08