[Tex/LaTex] Position includepdf to top of page (when input is of varied size)

pdfpagespositioning

I'm trying to include a pdf document into my main LaTeX document (all my publications into my manuscript), but I want to keep the same page numbering throughout. I'm using the pdfpages package as follows,

\RequirePackage{pdfpages}

\includepdf[pages={-}, % all pages
pagecommand={\thispagestyle{fancy}} % continue page numbering
]{file.pdf}

For most files this works great, but for one particular file this happens:

Input doesn't fit, trails off the page

Definitely not what I wanted, so I removed all excess margins by applying

 pdfcrop file.pdf file-pdfcrop.pdf

And update the options as follows,

\includepdf[pages={-}, % all pages
width=\textwidth, % full text-width
frame=true, % for debugging
pagecommand={\thispagestyle{fancy}} % continue page numbering
]{file-pdfcrop.pdf}

This works fine but not exactly aesthetically pleasing for some pages. As the pages in file.pdf have been cropped to various sizes.
Input fits, but centered

Is there any way to force \includepdf to be positioned to the top of the page instead of the default centering?

PS This is my first post on tex.stackexchange, so be gentle 😉

Best Answer

I figured I might as well just use pdfcrop to same sized margins and using a bash script to apply it to all of my pdfs

for file in $DIRECTORY/*.pdf; do
  # Process $file
  echo $file
  # Find bounding boxes
  pdfcrop --verbose $file tmp.pdf | grep "%%HiResBoundingBox:" > bbox; 
  # First page has the largest bounding box
  largest=`echo $(head -n 1 bbox)| cut -d':' -f 2` 
  # Crop $file
  pdfcrop $file tmp.pdf --bbox "$largest"
  mv tmp.pdf $file
done
rm bbox

Finally, success! Final result

Related Question