1

In the mid document i want to insert a pdf page into a custom page size. The pdf page size is 432pt x 177pt and want to fit it in the center of a page 300pt x 300pt

\documentclass{article}
\usepackage{pdfpages}
\usepackage{geometry}

\begin{document}
...
\eject
\pdfpagewidth=300pt \pdfpageheight=300pt
\newgeometry{layoutwidth = 300pt,layoutheight = 300pt,left=0mm,right=0mm,top=0mm, bottom=0mm}
\includepdfmerge[]{/home/simha/latex/test.pdf, 494}
...
\end{document}

The output of this (the page size is 300pt x 300pt as i wanted but the pdf is gone sideways. I want it to be fit in the center

enter image description here

If i try to use fitpaper option in pdfpages

\documentclass{article}
\usepackage{pdfpages}
\usepackage{geometry}
\begin{document}
\eject
\pdfpagewidth=300pt \pdfpageheight=300pt
\newgeometry{layoutwidth = 300pt,layoutheight = 300pt,left=0mm,right=0mm,top=0mm, bottom=0mm}
\includepdfmerge[fitpaper]{/home/simha/latex/test.pdf, 494}
\end{document}

the output i get is (the page size is not 300pt x 300pt but the size of the pdf page size is "432pt x 177pt" which is not i want

enter image description here

I am stuck up here. I want to inser a pdf page into a size i want in the mid of the document.

0
0

If you intend to fit the PDF image to the page, you can use the following.

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{graphicx}
\usepackage{lipsum}% MWE only
\begin{document}
\lipsum[1-6]
\eject
\pdfpagewidth=300pt \pdfpageheight=300pt
\newgeometry{margin=0mm}
\noindent\includegraphics[width=300pt,height=300pt,page=1]{example-image}
\eject
\pdfpagewidth=\paperwidth
\pdfpageheight=\paperheight
\restoregeometry
\lipsum[1-6]
\end{document}

If you intent to crop and center, you can use this version. Note, trying to scale and crop in one step is not a good idea. If the image is already 432pt by 177pt, you can skip the scaling step.

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{adjustbox}
\usepackage{lipsum}% MWE only
\begin{document}
\lipsum[1-6]
\eject
\pdfpagewidth=300pt \pdfpageheight=300pt
\newgeometry{margin=0mm}
\noindent\begin{minipage}[c][300pt][c]{300pt}% vertically center
  \adjustbox{clip,trim=66 0 66 0}{\includegraphics[width=432pt,height=177pt,page=1]{example-image}}
\end{minipage}
\eject
\pdfpagewidth=\paperwidth
\pdfpageheight=\paperheight
\restoregeometry
\lipsum[1-6]
\end{document}

This version doesn't need a minipage.

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{graphicx}
\usepackage{lipsum}% MWE only
\begin{document}
\lipsum[1-6]
\eject
\pdfpagewidth=300pt \pdfpageheight=300pt
\newgeometry{top=0pt,left=0pt,textwidth=300pt,textheight=300pt,noheadfoot}
\null\vfill% or \vspace*{\fill}
\noindent
  \makebox[\textwidth]{\includegraphics[width=432pt,height=177pt,page=1]{example-image}}
\vfill\null
\eject
\pdfpagewidth=\paperwidth
\pdfpageheight=\paperheight
\restoregeometry
\lipsum[1-6]
\end{document}
4
  • \begin{minipage}[c][300pt][c]{300pt} How this will center vertically. ALso if i want to center both horizontal and vertical how to do it
    – Santhosh
    Aug 4 '20 at 7:21
  • The first optional argument controls the baseline, which isn't relevant here. The second optional argument is the height. The third optional optional argument controls the placement within the vertical space (t,c,b,and s). Since the width of the image is greater than the width of the page, centering consists of trimming off equal amounts on both sides. If the image were smaller than the width \centering will do. \makebox[300pt]{...} is an alternative. Aug 4 '20 at 13:55
  • i tried \centering but it centers as per article rather than by \pdfpagewidth=300pt \pdfpageheight=300pt
    – Santhosh
    Aug 5 '20 at 2:07
  • \centering won't do anything when the image is wider than page. Also, \newgeometry may not set \textwidth or \textheight correctly. Aug 5 '20 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.