I have about 190 image files (png and jpg) in a directory. For more information, each image has 2500 x 3072 pixels, and about 500KB.

I use the command convert from ImageMagik to convert and combine them into a pdf file:

convert * my.pdf

It takes about 10GB (at peak) and 4 hours to create a 80MB pdf file. I firstly failed to run it, because I don't have enough free space in my /tmp (actually in my / partition). Then I had to find a external hdd with abundant free space, and set the environment variable TMPDIR to point to it, and then succeeded.

I wonder if there is some other software to convert and combine the images into a pdf file besides convert, so as to eliminate the need for an external hdd? Or is it typical that such conversion and combination requires similar amount of temporary space from the disk?

More information of the image files, for example,

$ 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
  • You could convert the image files to pdfs individually, and then combine the pdfs incrementally (eg adding one pdf at a time to the total), using pdtk,for example. I don't see any obvious reason why you have to do this all at once. Nov 15, 2014 at 21:30

2 Answers 2


Maybe is a long shot, but I use pdflatex. I create a file (with a script or whatever) of the style:




And then run it with pdflatex file. The composition is fast (and you can easily --- if you know LaTeX --- change shape and position of the images, adding captions, etc...)

The problem is that the file is normally way big; I tested with 200 jpg of 500K+ --- the run took around 7 seconds on my i5/16G ram and gave a 800Mbyte PDF. I am trying to reduce its size by using

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=lowres.pdf file.pdf 

...and it has been running 8 minutes, but it has not used a lot of RAM. I cannot comment on the compression because gs is smarter than me and discovered I was using the same image 200 times so compressed the thing to a 50k PDF... which is clearly not real.


Unfortunately convert changes the image before so to have minimal loss of quality of the original jpg you need to use img2pdf, I use this commands:

A shorter one liner solution also using only img2pdf features

  1. Make PDF

    img2pdf *.jp* --output combined.pdf

  2. OCR the output PDF

    ocrmypdf combined.pdf combined_ocr.pdf

This was the original commands with more command and more tools needed:

1) This to make a pdf file out of every jpg image without loss of either resolution or quality:

ls -1 ./*jpg | xargs -L1 -I {} img2pdf {} -o {}.pdf

2) This to concatenate the pdfpages into one:

pdftk *.pdf cat output combined.pdf

3) And last I add an OCRed text layer that doesn't change the quality of the scan in the pdfs so they can be searchable:

pypdfocr combined.pdf  

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .