How can I append two PDFs that have links

5,091

Solution 1

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!

Solution 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.

Solution 3

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/

Share:
5,091

Related videos on Youtube

Martin Thoma
Author by

Martin Thoma

I also have a blog about Code, the Web and Cyberculture and a career profile on Stackoverflow. My interests are mainly machine-learning, neural-networks, data-analysis.

Updated on September 18, 2022

Comments

  • Martin Thoma
    Martin Thoma over 1 year

    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.

    • kylex
      kylex almost 11 years
      Did you ever figure out a good solution for this?
    • Martin Thoma
      Martin Thoma almost 11 years
      @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
    Martin Thoma over 11 years
    No, it doesn't work.
  • Simon
    Simon over 11 years
    @Moose: Thx for letting me know. If I find out further info I'll post it for you.
  • Martin Thoma
    Martin Thoma over 11 years
    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.
  • Werner
    Werner over 11 years
    @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.
  • Martin Thoma
    Martin Thoma over 11 years
    Yes, I read the documentation. I tried this command \includepdf[pages=-,fitpaper=true,noautoscale]{../GUI/render‌​ed/Entwurf.pdf}, but it did resize Entwurf.pdf (my GUI) to A4. I also tried it with fitpaper=true which also didn't work.
  • Werner
    Werner over 11 years
    @moose: It seems like your options fitpaper and noautoscale are contradictory. What about only noautoscale or with fitpaper=false?
  • Martin Thoma
    Martin Thoma over 11 years
    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.
  • Werner
    Werner over 11 years
    @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.
  • Martin Thoma
    Martin Thoma over 11 years
    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.
  • Mathias Bynens
    Mathias Bynens over 4 years
    I can confirm this preserves links.