TransWikia.com

Merge two PDF files output by LaTeX?

TeX - LaTeX Asked on August 14, 2021

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?

3 Answers

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=-,fitpapaer]{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
    

GUI

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

Correct answer by Matthew Leingang on August 14, 2021

Package pdfpagesmay help

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

end{document}

Answered by user2478 on August 14, 2021

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

Answered by F. Tusell on August 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP