You can use the pagecommand key:
\includepdf[scale=0.8,pages=1,pagecommand=\subsection{blub}]{testpdf}
You get the empty page when you use \includegraphics
because the graphics is too large for the textbody, so latex tries if it fits on the next page (and then complain). pdfpages
hides the size of the graphics so it is possible to insert complete pages which overwrites the margins. If you want to insert large graphics with \includegraphics
: use eso-pic
.
Let our first step is to prepare such a book (book.tex
).
%! *latex book.tex
\documentclass[a4paper]{article}
\pagestyle{empty}
\usepackage{pdflscape}
\begin{document}
\font\malfont=cmbx10 at 500pt \malfont
\def\insertpage{\mbox{}\vfil\hfil\thepage}
\insertpage
\begin{landscape}\insertpage\end{landscape}
\insertpage
\begin{landscape}\insertpage\end{landscape}
\end{document}
The fastest way is probably to use the pdfpages
package, http://www.ctan.org/pkg/pdfpages, with an option rotateoversize
switched to true. This is an example and its result.
%! *latex book-transform1.tex
\documentclass[a4paper]{article}
\usepackage{pdfpages}
\begin{document}
\includepdf[pages={-},fitpaper,rotateoversize]{book.pdf}
\end{document}
The only problem would be if we want to rotate (or ornament, typeset in, sign, watermark them etc.) landscape pages the other way around. This is an improved version. We are testing every single page if it was typeset in a portrait/landscape mode. We will discover that by measuring its page width and page height in a virtual box before typesetting.
The terminal is informing us about the findings.
Page 1, portrait, 597.50682pt, height 845.04504pt, depth 0.0pt.
Page 2, landscape, 845.04504pt, height 597.50682pt, depth 0.0pt.
Page 3, portrait, 597.50682pt, height 845.04504pt, depth 0.0pt.
Page 4, landscape, 845.04504pt, height 597.50682pt, depth 0.0pt.
I enclose an example and a preview of our efforts.
%! *latex book-transform2.tex
\batchmode
\documentclass[a4paper]{article}
\usepackage{pdfpages}
\def\malfile{book.pdf}
\pdfximage{\malfile}
\begin{document}
\newcount\malcount \malcount=0 % This is a page counter...
\newbox\malbox % This is a virtual box...
\loop % Let's test all the pages one by one...
\advance\malcount by 1%
% Measure a single page virtually...
\setbox\malbox=\hbox{\includegraphics[page={\the\malcount}]{\malfile}}%
% Send the information to the terminal...
\scrollmode
\message{Page \the\malcount, \ifnum\wd\malbox<\ht\malbox portrait\else landscape\fi, \the\wd\malbox, height \the\ht\malbox, depth \the\dp\malbox.}%
\batchmode
% Testing and inserting that particular single page into a document...
\ifnum\wd\malbox<\ht\malbox %Portrait; no changes please...
\includepdf[pages={\the\malcount}, fitpaper]{\malfile}
\else % Landscape mode; rotate it, decorate it, draw something on it... :-)
\includepdf[pages={\the\malcount}, fitpaper, angle=270]{\malfile}% 90 degrees is the default value in pdfpages, 270 degrees is an experiment, if somebody is in need of it...
\fi
% Test all the pages from the input PDF file...
\ifnum\malcount<\pdflastximagepages\repeat
\end{document}
Best Answer
It seems pdfTeX has trouble with the font encodings in
analysiscompsSprJan2011.pdf
that was generated bydvipdfm 0.13.2d
.Workarounds:
The example works with LuaTeX.
It seems to work, if the PDF file is preprocessed by
pdfcrop
. Usually pdfTeX tries to detect the fonts in embedded PDF files and if the fonts are known, then pdfTeX uses the fonts directly ignoring the embedded fonts. Because of merging effects the file size can decrease. But the risk is that the embedded fonts and the fonts found by pdfTeX on its system might differ.pdfcrop
disables all fonts, thus pdfTeX just copies the fonts from the included PDF file.generates
analysiscompsSprJan2011-crop.pdf
with removed white margins. The margins can also be kept. Then the/MediaBox
inside the PDF file tells the dimension of the page:that can be used as new bounding box for
pdfcrop
:Finally
analysiscompsSprJan2011-crop.pdf
is used for embedding the file:BTW, package
pdfpages
can also handle.jpg
or.png
files. Then the extension needs to be specified:However JPEG/PNG are bitmaps and JPEG is not a lossless compression, it is better to avoid them, if the original file is vector based like in this case.