Unix:将PDF文件和图像合并为PDF文件?

时间:2012-09-25 21:27:08

标签: image macos unix pdf

我的朋友问这个问题,他正在使用Mac而无法使PdfLatex工作(没有开发CD,相关here)。无论如何我的第一个想法是:

  
      
  • $ pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf [only pdfs]
  •   
  • $ convert 1.png 2.png myfile.pdf [仅限图片]
  •   

现在我不知道没有LaTex或iPad的Notes Plus如何组合图像和PDF文件。那么如何在Unix中结合pdf文件和图像?

2 个答案:

答案 0 :(得分:1)

我在这里收集一些信息。

Unix命令行

  
      
  1. 有关Pdftk here的更多信息。

  2.   
  3. Merging png images into one pdf file

  4.   
  5. Combine all files in a folder as pdf

  6.   

<强>苹果

  

因为Apple SE中的主持人删除了有用的主题“将PDF文件和图像合并到Mac中的单个PDF文件?”   here    - 我在这里收集Mac的提示 - 对不起,主持人对收集Newbie -things非常不宽容。

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

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

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

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

  8.        

答案 1 :(得分:1)

您可以运行循环,识别PDF和图像,以及使用ImageMagick将图像转换为PDF。当你完成后,你用pdftk组装它。

这是一个仅限Bash的脚本。

#!/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[@]}