105

I would like to (re)submit a paper with a short cover letter, explaining the changes I have made. However, the journal only allows me to upload one file. As the main article will use the journal style class, and so forth, it's not really practical to use the 1st page for the letter (or is it? Could I reset the page number etc. etc.??)

Instead, could I create, say, two PDF files (one the letter, the other the article) and then somehow merge them together?

egreg
  • 1,121,712
Matthew Daws
  • 1,367

3 Answers3

131

Create the separate documents separately and merge them with a PDF utility. Semantically speaking, I feel this is the way to go rather than futzing with the document settings. After all, what you are submitting is not one "document" but a set of them.

Edit: This is an important question that has been asked more than once. It's also not exactly TeX-related. So I'm community-wikifying my answer so it can be improved and made definitive.

LaTeX

use Herbert's answer: the pdfpages package

\documentclass{article}% or something else
\usepackage{pdfpages}
\begin{document}
\includepdf[pages=-]{paper1}
\includepdf[pages=-]{paper2}

\end{document}

You could also keep the document page sizes by adding a option:

\includepdf[pages=-,fitpaper]{paper1}
\includepdf[pages=-,fitpaper]{paper2}

And not to repeat yourself use this:

\includepdfset{pages=-,fitpaper}
\includepdf{paper1}
\includepdf{paper2}
\includepdf{paper3}
\includepdf[fitpaper=false]{paper4} // you can add document specific options
\includepdf{paper5}
\includepdf{paper6}
\includepdfset{} // to put default values back

Command Line

  • pdftk

     $ pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf
    
  • GhostScript

     $ gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=merged.pdf source1.pdf source2.pdf source3.pdf etc.pdf
    

    (via Macworld)

  • PDFJAM is a suite of scripts that uses LaTeX and pdfpages on the backend.

     $ pdfjoin foo1.pdf foo2.pdf --outfile bar.pdf
    

    (via Uwe Hermann)

  • stapler is a pure Python alternative to pdftk.

      $ stapler cat in1.pdf in2.pdf out.pdf
    
  • PyMuPDF is a Python binding for MuPDF – “a lightweight PDF and XPS viewer”.

       $ python -m fitz join -o output.pdf file1.pdf file2.pdf
    
  • qpdf is a command-line tool and C++ library that performs content-preserving transformations on PDF files.

        $ qpdf --empty --pages file1.pdf file2.pdf -- output.pdf
    

GUI

This question is very similar although the questioner didn't realize it.

frabjous
  • 41,473
Matthew Leingang
  • 44,937
  • 14
  • 131
  • 195
  • 8
    Beat me to it on pdftk; a very useful little program for mucking about with PDFs. – Andrew Stacey Jan 10 '11 at 21:45
  • 1
    I'll accept this; actually, I guess I should have search harder, as that other question was almost identical to mine! Many thanks to all. – Matthew Daws Jan 10 '11 at 22:16
  • Am I the only one who has trouble with the output of pdftk working well with ghostcript? Ghostscript complains that pdftk output violates the PDF spec. I prefer the pdfjam scripts, which provide similar commandline functionality, but uses pdflatex/pdfpages for its backend. (For that matter, gs can itself combine PDFs from the commandline.) – frabjous Jan 10 '11 at 22:25
  • @frabjous: I haven't had any problems with pdftk (which I've just been playing with); but also using gs directly works! – Matthew Daws Jan 11 '11 at 09:06
  • 13
    Note that pdfpages removes all hyperlinks and other PDF annotations from the included PDFs. – Martin Scharrer Jul 06 '11 at 19:37
  • I added PDFCreator as another GUI option. With the answer being CW, I hope that's ok. – doncherry Jul 06 '11 at 21:38
  • PDF Mod is a very nice application, but it seems to have problems opening LaTeX documents. – gilbertohasnofb Aug 04 '16 at 10:04
  • The ghostscript option worked well for me on MacOS, preserving the url hyperlinks (did not have any internal document links to check) in the final output. – dayne Apr 26 '19 at 14:29
  • I was using pdftk but some times i ggt increase heapsize error. HOw to solve this – Santhosh Aug 22 '20 at 12:13
  • One problem with pdfpages is the pages size are all changed to article. If my pdf has inbetween different page sizes it does not consider that – Santhosh Aug 22 '20 at 12:20
  • 1
    Even if we use fitpaper option for includepdf (pdfpages) it will consider the first page as the page size for all the paages. – – Santhosh Aug 22 '20 at 12:21
  • @SanthoshYedidi: That's another good reason to use a native PDF utility instead. – Matthew Leingang Aug 24 '20 at 23:17
  • I generally use either pdftk ( Java and C++) or stapler (python pypdf based). – Santhosh Aug 25 '20 at 08:46
  • @SanthoshYedidi: Stapler is a new one for me. Can you add it to the post? (It's CW) – Matthew Leingang Aug 25 '20 at 17:25
  • Can we add qpdf, which I think is a really nice tool and doesn't mangle forms and bookmarks: qpdf --empty --pages file1.pdf file2.pdf -- output.pdf – frabjous Mar 22 '22 at 20:27
  • @frabjous: Go right ahead. Please add it in and include a line of usage for easy copying/pasting. – Matthew Leingang Mar 28 '22 at 16:49
28

Package pdfpagesmay help

\documentclass{article}% or something else
\usepackage{pdfpages}
\begin{document}
\includepdf[pages=...]{paper1}
\includepdf[pages=...]{paper2}

\end{document}
  • This works fine as well (once I noticed the typo: "includepdf" not "inlcudepdf"!) Actually, maybe this is the "nicest" way to do a cover letter, as then I can just include the PDF file of paper at the end. – Matthew Daws Jan 11 '11 at 15:47
  • @Matthew: I had a knot in my fingers ... :-) –  Jan 11 '11 at 15:49
  • I have clickable links in the PDF that I want to include. They are gone in the merged PDF. How can I maintain these links? ... Ah ok, seems like it's not possible. – stefanbschneider Mar 10 '21 at 15:35
  • @CGFoX: pdftk seems to keep internal links. – Eric Duminil Jun 23 '21 at 12:41
8

If you have Ghostscript installed, you might also join the two separate PDF files in one by issuing a command such as this:

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=merged.pdf input1.pdf input2.pdf
F. Tusell
  • 753