首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Unix:将PDF -files和图像合并成PDF -file?

Unix:将PDF -files和图像合并成PDF -file?
EN

Stack Overflow用户
提问于 2012-09-25 21:27:08
回答 2查看 2.3K关注 0票数 2

我的朋友正在问这个问题,他使用的是Mac,不能让PdfLatex工作(没有开发CD,相关的这里)。总之,我的第一个想法是:

  • $ pdftk 1.pdf 2.pdf 3.pdf猫输出123.pdf 仅为pdfs
  • $转换1.png 2.only myfile.pdf

现在,我不知道如果没有LaTex或iPad的Notes,如何将图像和PDF -files结合起来。那么,我如何将pdf -files和Unix中的图像结合起来呢?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-09-25 21:50:53

您可以运行一个循环,识别PDF和图像,并使用ImageMagick将图像转换为PDF。当你完成的时候,你用pdftk来组装它。

这是一个纯巴什的剧本。

代码语言:javascript
复制
#!/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[@]}
票数 1
EN

Stack Overflow用户

发布于 2012-09-25 21:50:10

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12591314

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档