# How to fit pdf page in custom page size in the mid document

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

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

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

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{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
\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
\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}

• \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 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 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