修改单页大小并插入图片

修改单页大小并插入图片

我正在尝试生成一个 PDF,其中每一页都有一个背景图像和一些放置在特定位置的文本。

有些页面是普通的 A4 纵向页面,其他页面是横向页面。

我的问题是,当我将某个页面尺寸从纵向更改为横向或从横向更改为纵向后,放置图像的坐标就乱了。

似乎\put坐标在我更改页面大小后,轴偏离了 +/- 253.5 毫米。

\documentclass[10pt,a4paper]{article}
\pdfpagewidth 210mm
\pdfpageheight 297mm
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[a4paper,portrait,margin=0.0mm]{geometry}
\usepackage{eso-pic}
\usepackage[absolute,showboxes]{textpos}
\usepackage[pdftex]{graphicx}

\begin{document}
\fontfamily{phv} \selectfont
\thispagestyle{empty}

\begin{textblock*}{98.00mm}(24.00mm,38.00mm)
\raggedright
\normalsize
Some text\end{textblock*}

\AddToShipoutPicture*{
\put(0,0){%
\includegraphics[page=1,width=210mm,height=297mm]{backgroundimage.pdf}}}

\null\newpage

%change page to landscape
\eject \pdfpagewidth=297mm \pdfpageheight=210mm

\begin{textblock*}{98.00mm}(24.00mm,38.00mm)
\raggedright
\normalsize
Some text\end{textblock*}

% This image isn't placed correctly at 0,0 ...need to use \put(0,253.5)
\AddToShipoutPicture*{
\put(0,0){% 
\includegraphics[page=1,width=297mm,height=210mm]{landscape.pdf}}}
\null\newpage 

\end{document}

答案1

该包eso-pic使用长度\paperwidth\paperheight设置左下角锚点。在您的 MWE 中,您只需更改\pdfpagewidth\pdfpageheight中间文档。如果您还更改\paperwidth\paperheight,它会起作用:

\documentclass[10pt,a4paper]{article}
\pdfpagewidth 210mm
\pdfpageheight 297mm
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[a4paper,portrait,margin=0.0mm]{geometry}
\usepackage{eso-pic}
\usepackage[absolute,showboxes]{textpos}
\usepackage[pdftex]{graphicx}

\begin{document}
\fontfamily{phv} \selectfont
\thispagestyle{empty}

\begin{textblock*}{98.00mm}(24.00mm,38.00mm)
\raggedright
\normalsize
\the\paperwidth hallo \the\paperheight\end{textblock*}

\AddToShipoutPicture*{
\put(0,0){%
\includegraphics[page=1,width=210mm,height=297mm]{backgroundimage.pdf}}}

\null\newpage

%change page to landscape
\eject \pdfpagewidth=297mm \pdfpageheight=210mm
\setlength{\paperheight}{210mm}
\setlength{\paperwidth}{297mm}

\begin{textblock*}{98.00mm}(24.00mm,38.00mm)
\raggedright
\normalsize
\the\paperwidth hallo \the\paperheight\end{textblock*}

% This image isn't placed correctly at 0,0 ...need to use \put(0,253.5)
\AddToShipoutPicture*{
\put(0,0){% 
\includegraphics[page=1,width=297mm,height=210mm]{landscape.pdf}
}}
\null\newpage 

\end{document}

相关内容