22

Background

Wrote a technical manual in LyX. The technical manual currently has two parts:

  • Cover image (PDF)
  • Manual text (PDF)

Problem

When merging the two PDF files (with GhostScript or other software tools), there are a number of issues:

  • Bookmarks (lost in merging)
  • Colours (obvious changes)
  • PDF tags (lost in merging)

I would rather include the cover page image as a full page (no margins) at the start of the manual and have LyX (LaTeX) generate the front page when it creates the PDF. In this fashion, the cover page and the manual text need not be merged as a separate step.

Question

How do you instruct LaTeX to generate a full page image as the first page in a PDF using KOMA-Script?

Update

Using the pdfpages package produces the following result:

Image

Note the white space above and below the image. The white space is removed using the following:

\includepdf[fitpaper]{cover}

Update

Part of the preamble contains:

% Resize figures that are too wide for the page.
\let\oldincludegraphics\includegraphics
\renewcommand\includegraphics[2][]{%
  \graphicsformat{%
    \oldincludegraphics[width=\ScaleIfNeeded,#1]{#2}%
  }%
}

The full preamble is at: http://pastebin.com/qHKEDPeU

The error message is:

!pdfTeX error: pdflatex (file cover.pdf): cannot find image file

The file ch_02.lyx and test.latex are in the same directory. The file test.latex is the document in Martin's post. The file test.latex can find the file cover.pdf, yet the file ch_02.lyx cannot find the file. Both use the following code:

\includepdf[fitpaper]{cover.pdf}

Update

The most minimal LyX example that produces the problem:

#LyX 1.6.7 created this file. For more info see http://www.lyx.org/
\lyxformat 345
\begin_document
\begin_header
\textclass scrbook
\begin_preamble
\usepackage{pdfpages}
\end_preamble
\use_default_options false
\language english
\inputencoding utf8
\font_roman lmodern
\font_sans helvet
\font_typewriter courier
\font_default_family default
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100

\graphics default
\float_placement H
\paperfontsize default
\spacing single
\use_hyperref true
\pdf_bookmarks true
\pdf_bookmarksnumbered false
\pdf_bookmarksopen false
\pdf_bookmarksopenlevel 1
\pdf_breaklinks false
\pdf_pdfborder false
\pdf_colorlinks false
\pdf_backref false
\pdf_pdfusetitle true
\papersize letterpaper
\use_geometry false
\use_amsmath 2
\use_esint 1
\cite_engine basic
\use_bibtopic false
\paperorientation portrait
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\defskip medskip
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\bullet 0 5 11 -1
\bullet 1 5 24 -1
\bullet 2 0 0 -1
\tracking_changes false
\output_changes false
\author "" 
\author "" 
\end_header

\begin_body

\begin_layout Standard
\begin_inset ERT
status collapsed

\begin_layout Plain Layout


\backslash
includepdf[fitpaper]{cover.pdf}
\end_layout

\end_inset


\end_layout

\begin_layout Standard
Test
\end_layout

\end_body
\end_document

Thank you!

Martin Scharrer
  • 262,582
Dave Jarvis
  • 11,809
  • 1
    Your code should still use the optional argument. At the moment it is discarded: \renewcommand\includegraphics[2][]{% \graphicsformat{% \oldincludegraphics[width=\ScaleIfNeeded,#1]{#2}% }% } – Martin Scharrer Apr 01 '11 at 09:47

3 Answers3

16

You can use the pdfpages packages (not to be confused with pgfpages) to include a PDF image/page as single page(s) to your document. This is useful for appendices or cover pages. Depending on your needs you should make sure that the page numbers are not counted for the cover page and the white filler page after it.

\documentclass{scrbook}

\usepackage{pdfpages}

\begin{document}
\includepdf{cover}
\cleardoublepage
\frontmatter
\tableofcontents
\mainmatter
\chapter{A}
...
\chapter{B}
...
\end{document}

Update:

As Bruno already commented, the fitpaper option of the pdfpages package will fit the page size of the first page to the size of the cover, removing excess white space. The option can be used as part of the \includepdf[<options>]{<file>} command.

This is fine for screen view, but for print-outs you should ensure that the cover and the normal pages have the same size from the beginning, either by recreating the cover with a larger height or by reducing the document size.

Andrew Stacey
  • 153,724
  • 43
  • 389
  • 751
Martin Scharrer
  • 262,582
  • 1
    Just a little addendum: I've also used pdfpages and found the fitpaper option quite useful. – Bruno Apr 01 '11 at 08:31
  • Perhaps you didn't start pdflatex in this directory. Or the name isn't actually cover.pdf but contains e.g. a space. – Ulrike Fischer Apr 01 '11 at 08:52
  • @Dave: It should work. Try running kpsewhich cover.pdf in the document folder and see if it finds the file. Try it with a different file name. – Martin Scharrer Apr 01 '11 at 08:54
  • @Dave: Try it with a minimal test file and see if it works. Maybe some other package causes this. – Martin Scharrer Apr 01 '11 at 09:13
  • @Dave: Your redefinition is most likely causing it. Include the cover as follows: {\let\includegraphics\oldincludegraphics\includepdf[fitpaper]{cover}}. – Martin Scharrer Apr 01 '11 at 09:44
  • @Dave: pdfpages uses includegraphics internally and sets some of the options. So I suspect that your overwriting is causing problems. I would recommend that you not reuse \includegraphics but define \myincludegraphics as a wrapper around \includegraphics and see if that helps. – Andrew Stacey Apr 01 '11 at 09:45
  • Or do what Martin says! – Andrew Stacey Apr 01 '11 at 09:45
  • @Dave: As this is the inclusion of the front cover, you could try shifting your redefinition of \includegraphics to after it. – Andrew Stacey Apr 01 '11 at 09:59
  • @Dave: In that case, it's back to basics I'm afraid! First: is it Lyx? If you compile Martin's test document in LyX, does it work? – Andrew Stacey Apr 01 '11 at 10:12
  • @Dave: May I suggest we move this to chat? Martin's currently getting notified of every update to this discussion! – Andrew Stacey Apr 01 '11 at 10:19
  • @Dave: Make a copy of your LyX document and start to minimize it. Delete everything after the cover page for starters and then remove parts of the preamble and see if the error disappears. Normally a binary search is the best one: remove one half of the preamble and recompile, mind other created because of this. If the cover is found the error is caused by the just removed part, otherwise go on and remove half of the remaining preamble until the error is gone. This way you can track down the cause. – Martin Scharrer Apr 01 '11 at 10:23
  • @Andrew, Dave: moving to the chat is a good idea! – Martin Scharrer Apr 01 '11 at 10:24
  • @Dave: When pdfLaTeX says that is can't find cover.pdf I would at first believe that it really can't find it. And this means - if the name is correct - that LaTeX/Lyx is not looking in the folder where the pdf resides. Make a small testfile.tex with two or three words, save it in this folder and then try if Lyx/pdflatex can find it if you use \input{testfile}. – Ulrike Fischer Apr 01 '11 at 10:49
8

Solution

The following code inserts the cover as expected, within LyX:

\thispagestyle{empty}
\begin{tikzpicture}[remember picture, overlay]
 \node[inner sep=0pt] at (current page.center) {%
  \includegraphics[width=\paperwidth,height=\paperheight]{cover}%
};
\end{tikzpicture}
\cleardoublepage{}

Problems

Martin's solution works in a simple case, for a simple LaTeX document. Due to what appears to be a bug in LyX, the LyX software is unable to directly export a simple document to a TeX document, and then into a PDF document. Trying to work around the bug by exporting to TeX and then running pdflatex manually results in a cover page that consists of an extremely small rectangle.

The given solution uses tikz to centre the image on the page.

Related

See also:

Dave Jarvis
  • 11,809
1

Using pdfpages in LyX

Use the menu Insert->File->External Material, then choose "pdfpages". This will include and PDF with the package pdfpages.

See also: http://wiki.lyx.org/FAQ/PDF

lumbric
  • 4,269