Linux 将多个 PDF 文件合并/转换为一个 PDF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2507766/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Merge / convert multiple PDF files into one PDF
提问by alcohol
How could I merge / convert multiple PDF files into one large PDF file?
如何将多个 PDF 文件合并/转换为一个大的 PDF 文件?
I tried the following, but the content of the target file was not as expected:
我尝试了以下操作,但目标文件的内容不符合预期:
convert file1.pdf file2.pdf merged.pdf
I need a very simple/basic command line (CLI) solution. Best would be if I could pipe the output of the merge / convert straight into pdf2ps
( as originally attempted in my previously asked question here: Linux piping ( convert -> pdf2ps -> lp)).
我需要一个非常简单/基本的命令行 (CLI) 解决方案。最好是我可以将合并/转换的输出直接通过管道传输到pdf2ps
(正如我之前在此处提出的问题中最初尝试的那样:Linux 管道(转换 -> pdf2ps -> lp))。
采纳答案by alcohol
I'm sorry, I managed to find the answer myself using google and a bit of luck : )
对不起,我设法使用谷歌和一点运气自己找到了答案:)
For those interested;
对于那些有兴趣的人;
I installed the pdftk (pdf toolkit) on our debian server, and using the following command I achieved desired output:
我在我们的 debian 服务器上安装了 pdftk(pdf 工具包),并使用以下命令获得了所需的输出:
pdftk file1.pdf file2.pdf cat output output.pdf
OR
或者
gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf file1.pdf file2.pdf file3.pdf ...
This in turn can be piped directly into pdf2ps.
这又可以直接通过管道传输到 pdf2ps。
回答by Hubert Kario
Considering that pdfunite
is part of poppler it has a higher chance to be installed, usage is also simpler than pdftk
:
考虑到它pdfunite
是 poppler 的一部分,它有更高的安装机会,用法也比pdftk
:
pdfunite in-1.pdf in-2.pdf in-n.pdf out.pdf
回答by rodrigob
Also pdfjoin a.pdf b.pdf
will create a new b-joined.pdf
with the contents of a.pdf and b.pdf
也pdfjoin a.pdf b.pdf
将创建一个新b-joined.pdf
的 a.pdf 和 b.pdf 的内容
回答by Gery
Try the good ghostscript:
试试好的 ghostscript:
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=merged.pdf mine1.pdf mine2.pdf
or even this way for an improved version for low resolution PDFs (thanks to Adriano for pointing this out):
甚至对于低分辨率 PDF 的改进版本也是如此(感谢 Adriano 指出这一点):
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile=merged.pdf mine1.pdf mine2.pdf
In both cases the ouput resolution is much higher and better than this way using convert:
在这两种情况下,输出分辨率都比使用 convert 的这种方式更高更好:
convert -density 300x300 -quality 100 mine1.pdf mine2.pdf merged.pdf
In this way you wouldn't need to install anything else, just work with what you already have installed in your system (at least both come by default in my rhel).
通过这种方式,您不需要安装任何其他东西,只需使用您已经安装在系统中的东西(至少在我的 rhel 中两者都是默认的)。
Hope this helps,
希望这可以帮助,
UPDATE:first of all thanks for all your nice comments!! just a tip that may work for you guys, after googling, I found a superb trick to shrink the size of PDFs, I reduced with it one PDF of 300 MB to just 15 MB with an acceptable resolution! and all of this with the good ghostscript, here it is:
更新:首先感谢您的所有好评!!只是一个可能对你们有用的技巧,在谷歌搜索之后,我发现了一个缩小 PDF 大小的绝妙技巧,我用它把一个 300 MB 的 PDF 减少到只有 15 MB,并且分辨率可以接受!所有这一切都带有很好的ghostscript,这里是:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default -dNOPAUSE -dQUIET -dBATCH -dDetectDuplicateImages -dCompressFonts=true -r150 -sOutputFile=output.pdf input.pdf
cheers!!
干杯!!
回答by Trupti Kini
If you want to convert all the downloaded images into one pdf then execute
如果要将所有下载的图像转换为一个 pdf 则执行
convert img{0..19}.jpg slides.pdf
convert img{0..19}.jpg slides.pdf
回答by Noor
You can use the convert command directly,
可以直接使用convert命令,
e.g.
例如
convert sub1.pdf sub2.pdf sub3.pdf merged.pdf
回答by user3709983
I like the idea of Chasmo, but I preffer to use the advantages of things like
我喜欢 Chasmo 的想法,但我更喜欢利用诸如
convert $(ls *.pdf) ../merged.pdf
Giving multiple source files to convert
leads to merging them into a common pdf. This command merges all files with .pdf
extension in the actual directory into merged.pdf
in the parent dir.
提供多个源文件会convert
导致将它们合并为一个通用的 pdf。此命令将.pdf
实际目录中所有带有扩展名的文件合并到merged.pdf
父目录中。
回答by lumpchen
Apache PDFBox http://pdfbox.apache.org/
Apache PDFBox http://pdfbox.apache.org/
PDFMerger This application will take a list of pdf documents and merge them, saving the result in a new document.
PDFMerger 此应用程序将获取 pdf 文档列表并合并它们,将结果保存在新文档中。
usage: java -jar pdfbox-app-x.y.z.jar PDFMerger "Source PDF files (2 ..n)" "Target PDF file"
用法:java -jar pdfbox-app-xyzjar PDFMerger "源 PDF 文件 (2 ..n)" "目标 PDF 文件"
回答by billynoah
Here's a method I use which works and is easy to implement. This will require both the fpdfand fpdilibraries which can be downloaded here:
这是我使用的一种有效且易于实现的方法。这将需要两个FPDF和FPDI可以在这里下载库:
require('fpdf.php');
require('fpdi.php');
$files = ['doc1.pdf', 'doc2.pdf', 'doc3.pdf'];
$pdf = new FPDI();
foreach ($files as $file) {
$pdf->setSourceFile($file);
$tpl = $pdf->importPage(1, '/MediaBox');
$pdf->addPage();
$pdf->useTemplate($tpl);
}
$pdf->Output('F','merged.pdf');
回答by Andrea Vacondio
You can use sejda-console, free and open source.
Unzip it and run sejda-console merge -f file1.pdf file2.pdf -o merged.pdf
您可以使用sejda-console,免费且开源。解压并运行 sejda-console merge -f file1.pdf file2.pdf -o merged.pdf
It preserves bookmarks, link annotations, acroforms etc.. it actually has quite a lot of options you can play with, just run sejda-console merge -h
to see them all.
它保留书签、链接注释、acroforms 等。它实际上有很多你可以使用的选项,只需运行sejda-console merge -h
即可查看它们。