2

My friend is asking this question, he is using Mac and cannot get PdfLatex working (having no dev CD, related here). Anyway my first idea:

  • $ pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf [only pdfs]
  • $ convert 1.png 2.png myfile.pdf [only images]

Now I don't know without LaTex or iPad's Notes Plus how to combine images and PDF -files. So how can I combine pdf -files and images in Unix?

Community
  • 1
  • 1
hhh
  • 44,388
  • 56
  • 154
  • 251

2 Answers2

1

I am gathering here some info.

Unix Commandline

  1. More about Pdftk here.

  2. Merging png images into one pdf file

  3. Combine all files in a folder as pdf

Mac

Because the moderator in Apple SE removed the useful thread "Merge PDF files and images to single PDF file in Mac?" here -- I collect the tips here for Mac -- sorry but the moderator is very intolerant about collecting Newbie -things.

  1. https://apple.stackexchange.com/questions/16226/what-software-is-available-preferably-free-to-create-and-edit-pdf-files-on-mac

  2. https://apple.stackexchange.com/questions/812/how-can-i-combine-two-pdfs-in-preview

  3. https://apple.stackexchange.com/questions/11163/how-do-i-combine-two-or-more-images-to-get-a-single-pdf-file

  4. https://apple.stackexchange.com/questions/69659/ipad-pdf-software-to-edit-merge-annotate-etc-well-pdf-documents-like-in-deskto

Community
  • 1
  • 1
hhh
  • 44,388
  • 56
  • 154
  • 251
1

You could run a loop, identifying PDF and images, and converting images to PDF with ImageMagick. When you're done, you assemble it all with pdftk.

This is a Bash-only script.

#!/bin/bash

# Convert arguments into list
N=0
for file in $*; do
        files[$N]=$file
        N=$[ $N + 1 ]
done
# Last element of list is our destination filename
N=$[ $N - 1 ]
LAST=$files[$N]
unset files[$N]
N=$[ $N - 1 ]
# Check all files in the input array, converting image types
T=0
for i in $( seq 0 $N ); do
        file=${files[$i]}
        case ${file##*.} in
                jpg|png|gif|tif)
                        temp="tmpfile.$T.pdf"
                        convert $file $temp
                        tmp[$T]=$temp
                        uses[$i]=$temp
                        T=$[ $T + 1 ]
                        # Or also: tmp=("${tmp[@]}" "$temp")
                ;;
                pdf)
                        uses[$i]=$file
                ;;
        esac
done
# Now assemble PDF files
pdftk ${uses[@]} cat output $LAST
# Destroy all temporary file names. Disabled because you never know :-)
echo "I would remove ${tmp[@]}"
# rm ${tmp[@]}
LSerni
  • 49,775
  • 9
  • 56
  • 97