
我的目錄中有大約 190 個圖片檔案(png 和 jpg)。有關詳細信息,每個圖像都有 2500 x 3072 像素,大約 500KB。
我使用 ImageMagik 中的命令convert
將它們轉換並組合成 pdf 檔案:
convert * my.pdf
建立 80MB 的 pdf 檔案大約需要 10GB(高峰時)和 4 小時。
/tmp
我首先無法運行它,因為我的(實際上是我的/
分區中)沒有足夠的可用空間。然後我必須找到一個具有充足可用空間的外部硬碟,並將環境變數設定TMPDIR
為指向它,然後就成功了。
我想知道除了 pdf 之外,是否還有其他軟體可以將圖像轉換並合併為 pdf 文件convert
,從而無需外接硬碟?或者這種轉換和組合通常需要磁碟上類似數量的臨時空間?
圖像文件的更多信息,例如,
$ exiftool 1.jpg
ExifTool Version Number : 8.60
File Name : 1.jpg
Directory : .
File Size : 453 kB
File Modification Date/Time : 2014:11:15 13:41:55-05:00
File Permissions : rwxrwx---
File Type : JPEG
MIME Type : image/jpeg
JFIF Version : 1.01
Resolution Unit : None
X Resolution : 1
Y Resolution : 1
Image Width : 2500
Image Height : 3072
Encoding Process : Baseline DCT, Huffman coding
Bits Per Sample : 8
Color Components : 3
Y Cb Cr Sub Sampling : YCbCr4:2:0 (2 2)
Image Size : 2500x3072
$ exiftool 2.png
ExifTool Version Number : 8.60
File Name : 2.png
Directory : .
File Size : 310 kB
File Modification Date/Time : 2014:11:15 13:50:58-05:00
File Permissions : rwxrwx---
File Type : PNG
MIME Type : image/png
Image Width : 2500
Image Height : 3072
Bit Depth : 8
Color Type : Grayscale
Compression : Deflate/Inflate
Filter : Adaptive
Interlace : Noninterlaced
Pixels Per Unit X : 11929
Pixels Per Unit Y : 11929
Pixel Units : Meters
Image Size : 2500x3072
答案1
也許是一個遠景,但我使用pdflatex
.我會建立一個以下樣式的文件(帶有腳本或其他內容):
\documentclass{report}
\usepackage{graphicx}
\begin{document}
\includegraphics[width=0.95\textwidth]{img000}\par
\includegraphics[width=0.95\textwidth]{img001}\par
[...]
\includegraphics[width=0.95\textwidth]{img200}\par
\end{document}
然後用 運行它pdflatex file
。構圖速度很快(而且你可以輕鬆地——如果你了解 LaTeX——改變圖像的形狀和位置,添加標題等...)
問題是該文件通常很大;我用 500K+ 的 200 張 jpg 進行了測試——在我的 i5/16G 內存上運行大約需要 7 秒,並給出了 800Mbyte 的 PDF。我試圖透過使用來減小它的大小
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=lowres.pdf file.pdf
……它已經運行了 8 分鐘,但沒有使用大量 RAM。我無法評論壓縮,因為gs
它比我聰明,發現我使用同一張圖像 200 次,所以將其壓縮為 50k PDF……這顯然不是真實的。
答案2
很遺憾convert
更改之前的圖像,以便將jpg
您需要使用的原始圖像的質量損失降到最低img2pdf
,我使用以下命令:
較短的單襯管解決方案,也僅使用img2pdf
特徵
製作PDF
img2pdf *.jp* --output combined.pdf
OCR 輸出 PDF
ocrmypdf combined.pdf combined_ocr.pdf
這是原始命令,需要更多命令和更多工具:
1) 這是為了將pdf
每個jpg
影像建立一個文件,而不會損失解析度或品質:
ls -1 ./*jpg | xargs -L1 -I {} img2pdf {} -o {}.pdf
2)這將pdf
頁面連接成一個:
pdftk *.pdf cat output combined.pdf
3)最後我添加了一個OCRed文字層,它不會改變pdf中的掃描質量,因此它們可以被搜尋:
pypdfocr combined.pdf