Programing

여러 PDF 파일을 하나의 PDF로 병합 / 변환

lottogame 2020. 9. 28. 07:54
반응형

여러 PDF 파일을 하나의 PDF로 병합 / 변환


여러 PDF 파일을 하나의 큰 PDF 파일로 병합 / 변환하려면 어떻게해야합니까?

다음을 시도했지만 대상 파일의 내용이 예상과 다릅니다.

convert file1.pdf file2.pdf merged.pdf

매우 간단하고 기본적인 명령 줄 (CLI) 솔루션이 필요합니다. 병합 / 변환의 출력을 직접 파이프 할 수 있다면 가장 좋습니다 (pdf2ps 원래 이전에 질문 한대로 Linux piping (convert-> pdf2ps-> lp) ).


pdfunite이것이 poppler의 일부 라는 점을 고려할 때 설치 가능성이 더 높으므로 사용법도 다음보다 간단합니다 pdftk.

pdfunite in-1.pdf in-2.pdf in-n.pdf out.pdf

좋은 대본을 사용해보십시오 :

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=merged.pdf mine1.pdf mine2.pdf

또는 저해상도 PDF를위한 개선 된 버전의 경우에도이 방법을 사용합니다 (이를 지적한 Adriano에게 감사드립니다).

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile=merged.pdf mine1.pdf mine2.pdf

두 경우 모두 출력 해상도는 convert를 사용하는 것보다 훨씬 높고 낫습니다.

convert -density 300x300 -quality 100 mine1.pdf mine2.pdf merged.pdf

이런 식으로 다른 것을 설치할 필요가 없으며 시스템에 이미 설치 한 것으로 작업하십시오 (적어도 둘 다 내 rhel에 기본적으로 제공됨).

도움이 되었기를 바랍니다,

업데이트 : 우선 모든 좋은 의견에 감사드립니다 !! 여러분에게 도움이 될 수있는 팁입니다. 인터넷 검색을 한 후 PDF 크기를 줄이는 훌륭한 트릭을 찾았습니다. 300MB의 PDF 하나를 허용 가능한 해상도로 15MB로 줄였습니다! 이 모든 것이 좋은 고스트 스크립트와 함께 있습니다.

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default -dNOPAUSE -dQUIET -dBATCH -dDetectDuplicateImages -dCompressFonts=true -r150 -sOutputFile=output.pdf input.pdf

건배!!


죄송합니다. Google과 약간의 행운을 사용하여 직접 답변을 찾았습니다. :)

관심있는 사람들을 위해;

데비안 서버에 pdftk (pdf 툴킷)를 설치하고 다음 명령을 사용하여 원하는 결과를 얻었습니다.

pdftk file1.pdf file2.pdf cat output output.pdf

또는

gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf file1.pdf file2.pdf file3.pdf ...

이것은 차례로 pdf2ps로 직접 파이프 될 수 있습니다.


또한 a.pdf 및 b.pdf의 내용으로 pdfjoin a.pdf b.pdf새 파일 b-joined.pdf만듭니다.


여러 파일이 있고 이름을 하나씩 입력하지 않으려는 경우 가장 쉬운 솔루션입니다.

qpdf --empty --pages *.pdf -- out.pdf


convert 명령을 직접 사용할 수 있습니다.

예 :

convert sub1.pdf sub2.pdf sub3.pdf merged.pdf

pdfunite전체 PDF를 병합하는 것이 좋습니다. 예를 들어 file1.pdf의 2-7 페이지와 file2.pdf의 1,3,4 페이지를 원하는 경우을 사용 pdfseparate하여 파일을 각 페이지에 대해 별도의 PDF로 분할해야합니다 pdfunite.

이 시점에서 더 많은 옵션이있는 프로그램을 원할 것입니다. qpdfPDF를 조작하는 데 내가 찾은 최고의 유틸리티입니다. pdftk더 크고 느리며 Red Hat / Fedora는 gcj에 대한 종속성으로 인해 패키지화하지 않습니다. 다른 PDF 유틸리티에는 Mono 또는 Python 종속성이 있습니다. 나는 발견 qpdf사용하는 것보다 훨씬 작은 출력 파일을 생성 pdfseparate하고 pdfunite30 페이지 출력 PDF, 970kB 대 1,6450 킬로바이트로 페이지를 조립. 더 많은 옵션을 제공하기 때문에 qpdf의 명령 줄은 그렇게 간단하지 않습니다. file1 및 file2 병합에 대한 원래 요청은 다음을 사용하여 수행 할 수 있습니다.

qpdf --empty --pages file1.pdf file2.pdf -- merged.pdf

Apache PDFBox http://pdfbox.apache.org/

PDFMerger이 응용 프로그램은 pdf 문서 목록을 가져 와서 병합하여 결과를 새 문서에 저장합니다.

사용법 : java -jar pdfbox-app-xyzjar PDFMerger "Source PDF files (2 ..n)" "Target PDF file"


Python https://pypi.python.org/pypi/pdftools/1.0.6의 PDF 도구 사용

tar.gz 파일을 다운로드하고 압축을 풀고 다음과 같은 명령을 실행하십시오.

python pdftools-1.1.0/pdfmerge.py -o output.pdf -d file1.pdf file2.pdf file3 

위의 명령을 실행하기 전에 pyhton3을 설치해야합니다.

이 도구는 다음을 지원합니다.

  • 더하다
  • 끼워 넣다
  • 풀다
  • 회전
  • 스플릿
  • 병합
  • 지퍼

아래 링크에서 자세한 내용을 찾을 수 있으며 오픈 소스입니다.

https://github.com/MrLeeh/pdftools


다운로드 한 모든 이미지를 하나의 pdf로 변환하려면 다음을 실행하십시오.

convert img{0..19}.jpg slides.pdf


sejda-console , 무료 및 오픈 소스를 사용할 수 있습니다 . 압축을 풀고 실행sejda-console merge -f file1.pdf file2.pdf -o merged.pdf

북마크, 링크 주석, 아크로 폼 등을 보존합니다. 실제로 사용할 수있는 많은 옵션이 있습니다 sejda-console merge -h. 실행 만하면 모두 볼 수 있습니다.


I second the pdfunite recommendation. I was however getting Argument list too long errors as I was attempting to merge > 2k PDF files.

I turned to Python for this and two external packages: PyPDF2 (to handle all things PDF related) and natsort (to do a "natural" sort of the directory's file names). In case this can help someone:

from PyPDF2 import PdfFileMerger
import natsort
import os

DIR = "dir-with-pdfs/"
OUTPUT = "output.pdf"

file_list = filter(lambda f: f.endswith('.pdf'), os.listdir(DIR))
file_list = natsort.natsorted(file_list)

# 'strict' used because of
# https://github.com/mstamy2/PyPDF2/issues/244#issuecomment-206952235
merger = PdfFileMerger(strict=False)

for f_name in file_list:
  f = open(os.path.join(DIR, f_name), "rb")
  merger.append(f)

output = open(OUTPUT, "wb")
merger.write(output)

Here's a method I use which works and is easy to implement. This will require both the fpdf and fpdi libraries which can be downloaded here:

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');

I am biased being one of the developers of PyMuPDF (a Python binding of MuPDF).

You can easily do what you want with it (and much more). Skeleton code works like this:

#-------------------------------------------------
import fitz         # the binding PyMuPDF
fout = fitz.open()  # new PDF for joined output
flist = ["1.pdf", "2.pdf", ...]  # list of filenames to be joined

for f in flist:
    fin = fitz.open(f)  # open an input file
    fout.insertPDF(fin) # append f
    fin.close()

fout.save("joined.pdf")
#-------------------------------------------------

That's about it. Several options are available for selecting only pages ranges, maintaining a joint table of contents, reversing page sequence or changing page rotation, etc., etc.

We are on PyPi.


I like the idea of Chasmo, but I preffer to use the advantages of things like

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 .pdfextension in the actual directory into merged.pdf in the parent dir.

참고URL : https://stackoverflow.com/questions/2507766/merge-convert-multiple-pdf-files-into-one-pdf

반응형