4

My problem

I have two PDFs which I would like to merge to one PDF. The first one was generated with LaTeX and has links to the chapters, the second one is a GUI-draft with links created with Balsamiq.

How can I append the GUI draft to the LaTeX document with working links?

What I've tried

pdftk LatexDocument.pdf GUI.pdf cat output merged.pdf

worked, but links don't link to the correct pages any longer.

Martin Thoma
  • 3,384
  • 9
  • 31
  • 65
  • Did you ever figure out a good solution for this? – kylex May 18 '13 at 01:20
  • @kylex: No. It seems to be impossible to merge two PDFs while keeping the link structure of both PDFs. I "solved" this problem by referencing to the other PDF as text ("See file 'GUI.pdf'") :-/ – Martin Thoma May 18 '13 at 07:12
  • See also: [Adobe Acrobat: How to batch to combine multiple pdf files? - Super User](https://superuser.com/questions/389760/adobe-acrobat-how-to-batch-to-combine-multiple-pdf-files) – user202729 Mar 26 '23 at 11:44

3 Answers3

6

I found the answer to this question over at the TeX stackexchange: https://tex.stackexchange.com/a/8665

i.e. use ghostscript!

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

I found that unlike other utilities I tried, and the \includedpdf{} command mentioned here, the above gs command preserved my links when merging 4 pdfs, at least for my LuaLaTeX generated file.

Only one of my files contained links, but merging it in multiple times seem to preserve the right order.

Hope that helps!

phillmv
  • 61
  • 1
  • 1
  • 1
    I can confirm this preserves links. – Mathias Bynens Aug 21 '19 at 06:50
  • This worked! I merged the cover page PDF with the contents PDF and it preserved links properly. FYI, I've tried using pdftk and it didn't preserve links or just about any other solution. Thanks for sharing this! – bezbos. May 20 '23 at 21:31
2

From within LaTeX you can include the other PDF, GUI.pdf, using pdfpages. Try something like this:

\documentclass{report}
\usepackage{pdfpages}% http://ctan.org/pkg/pdfpages
% Other preamble content
\begin{document}
% LaTeXDocument content
\includepdf{GUI.pdf}
\end{document}

If the two documents have different page/stock sizes, pdfpages will rescale the included document to the source page sizes. To avoid this, use

\includepdf[noautoscale]{GUI.pdf}

and any additional options you may require. Read the pdfpages documentation for more information on the operations that can be performed on the input pages.

Werner
  • 364
  • 2
  • 12
  • Well, the problem with that solution is that both PDF-files have different page sizes. I didn't figure out how to include a PDf with `pdfpages` without resizing. – Martin Thoma Dec 11 '12 at 18:38
  • @moose: Did you read the documentation I linked to? Use the option `noautoscale` (page 4), since page sizes are automatically rescaled by default. I'll update my answer. – Werner Dec 11 '12 at 18:44
  • Yes, I read the documentation. I tried this command `\includepdf[pages=-,fitpaper=true,noautoscale]{../GUI/rendered/Entwurf.pdf}`, but it did resize `Entwurf.pdf` (my GUI) to A4. I also tried it with `fitpaper=true` which also didn't work. – Martin Thoma Dec 11 '12 at 18:51
  • @moose: It seems like your options `fitpaper` and `noautoscale` are contradictory. What about *only* `noautoscale` or with `fitpaper=false`? – Werner Dec 11 '12 at 18:53
  • Only `noautoscale` didn't work. The image one the page didn't get scaled, but the page size of the document the GUI gets attaced to is wrong (A4). With only `fitpaper=true` the page size changed from A4 to the exotic one, but the image is ... well, not completely on the page. It's a bit to far at the top left. So I can't see the top/left part, but at the bottom/right is free space. And - by the way - the links get completely filtered. So even if it got correctly attached, I would need the links. – Martin Thoma Dec 11 '12 at 19:02
  • @moose: So *both* files have links in them? You didn't mention that in your original post, and I don't know what "Balsamiq" is/does. `\includepdf` will remove those links as you mentioned, making this answer somewhat useless for your case, I guess. – Werner Dec 11 '12 at 19:05
  • I did mention that in my original post: "The first one [...] has links to the chapters, the second one is a GUI-draft with links [...]". Balsamiq is a GUI sketching software, that allows you to export the GUI as a PDF with links. – Martin Thoma Dec 11 '12 at 19:17
0

You might like to try the recently launched Advanced PDF Manipulation tool : Sejda

It has different merging options available (it might work for you)

http://sejda.com/

Simon
  • 4,437
  • 8
  • 39
  • 51