【问题标题】:Unix: Combine PDF -files and images into PDF -file?Unix:将 PDF 文件和图像组合成 PDF 文件?
【发布时间】:2012-09-17 11:08:29
【问题描述】:

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

  • $ pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf [仅pdf]
  • $ convert 1.png 2.png myfile.pdf [仅图像]

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

【问题讨论】:

标签: image macos unix pdf


【解决方案1】:

【讨论】:

    【解决方案2】:

    您可以运行一个循环,识别 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[@]}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-11
      • 1970-01-01
      • 2013-08-13
      • 2017-02-07
      相关资源
      最近更新 更多