To convert multiple images to pdf this script will do that for all images inside a folder:

for f in *.png; do
  convert ./"$f" ./"${f%.png}.pdf"

But each image is converted into a separate file.

Can all images be converted into one single pdf?


You can use the -adjoin option of convert:

convert -adjoin *.png out.pdf

This command will result in one pdf file with all the png images.

  • can -adjoin be added as such to the the script in the question? – user32012 Feb 16 '16 at 16:09
  • 1
    @cipricus What's the problem with Marius's command? If the problem is that you're collecting the input file names one at a time, why not store them into an array and process the whole array when you've finished collecting them? – Gilles 'SO- stop being evil' Feb 16 '16 at 22:41
  • @Gilles - It works if run in terminal inside the folder containing the image files. I was just trying to use his command in a context menu files manager action like I was doing with the script mentioned in the question. - On the other hand I have found a very comprehensive solution that I have presented in a separate answer. – user32012 Feb 16 '16 at 22:59

Source here, to Generate PDF file from any set of documents, not only images.

From the above source:

Main principle

When you want to generate a multi-pages PDF file from multiple documents, you need to follow few steps :

Sort of all input documents in alphabetical order
Convert them to some temporary PDF files
Assemble all temporary PDF documents to a final multi-pages PDF document.

Conversion of input documents to temporary PDF format should be done according to their mimetype :

Image files (jpg, png, tiff, …)
Plain text files (txt)
Libre Office & Open Office documents (odt, ods, …)
Microsoft Office files (doc, docx, xls, xlsx, ppt, pptx, …)

Depending on input document types, conversion to PDF should be done using specific tools :

convert (from ImageMagick) for image files
unoconv for Libre Office, Microsoft Office and plain text files

Once all input documents are converted to some temporary PDF files, final document assembly is done using GhostScript. This powerful tool allows to :

merge multiple PDF documents
optimize final file size

For Nautilus and Gnome see more details at the above link, which includes more scripts to automate the processes needed. I have used a more limited approach, as the solution is streamlined for Gnome ad Nautilus and I use mainly KDE and Dolphin.

This solution gives the results requested in the question but is intended to also be applied to text documents and pdfs (beside images) and to merge them all into the final pdf.

The files are integrated into the output pdf in alphabetical order.

The final context-menu command can be also applied to the folder containing all the files to be merged.

The solution also includes some GUI features.


sudo apt-get install imagemagick unoconv ghostscript zenity libfile-mimeinfo-perl

Using gedit or other text editor:

gedit ~/.config/pdf-generate.conf

And paste this:


So if you want to modify any default parameter, just edit this file before running the tool.

Main script in charge of the PDF generation k=job should be placed under /usr/local/bin/pdf-generate. See source link for the content of the main script. (Also here.)

You can install main script and its configuration file from command line :

# mkdir --parents $HOME/.config
# wget --header='Accept-Encoding:none' -O $HOME/.config/pdf-generate.conf https://raw.githubusercontent.com/NicolasBernaerts/ubuntu-scripts/master/pdf/pdf-generate.conf
# sudo wget --header='Accept-Encoding:none' -O /usr/local/bin/pdf-generate https://raw.githubusercontent.com/NicolasBernaerts/ubuntu-scripts/master/pdf/pdf-generate
# sudo chmod +x /usr/local/bin/pdf-generate

To fully integrate this PDF generation tool in your desktop environment:

gedit /usr/share/applications/pdf-generate.desktop.

See link for Gnome/Nautilus integration and automated download and installation. A slightly simplified and adjusted version for my KDE needs:

    [Desktop Entry]
Name[en_US]=Generate PDF document
Name[en]=Generate PDF document
Name[C]=Generate PDF document
Name[fr_FR]=Génération d'un PDF
Comment=Tool to merge a set of documents to a PDF file.
Comment[en_US]=Tool to merge a set of documents to a PDF file.
Comment[fr_FR]=Outil de concaténation de documents en un fichier PDF.

To get a full desktop integration, this PDF generation tool should be available from a custom action in the file manager context menu.

For Nautilus you need to declare the new custom action in a .desktop file placed under ~/.local/share/file-manager/actions (see link for content). For Dolphin/KDE it is in ~/.kde/share/kde4/services/ServiceMenus/. Therefore, I did:

gedit ~/.kde/share/kde4/services/ServiceMenus/pdf-generate.desktop

with the content:

[Desktop Entry]

[Desktop Action pdf-generate]
Exec=pdf-generate %F
Name=Create pdf file

After re-login, a context menu option appears when selecting files, as indicated in the source link. For my KDE/Dolphin configuration, this works for selected files if they have the same extension. Otherwise, the best way it just to put all needed files in one folder and then execute the command from the right-click context menu of that folder.

enter image description here

Testing on a folder containing a png, a jpeg, a pdf and an odt file:

enter image description here

enter image description here

The output file is in the source folder, with the name first_in_alphabetical_order-merged.pdf.

enter image description here


An easy way of creating pdf files is the option "print to file" available in the list of printers.

Why not use that with images accessed from an image browser/viewer (like gThumb, Pix, Shotwell, Gwenview etc)?

After installing the image viewer (gThumb, for example):

  • select the images, right click them and open them all in gThumb (they will be displayed as in a file browser, not in the image viewer);

enter image description here

One can even re-arange the images before creating the pdf!

Just drag & drop:

enter image description here

  • in order to print them, select them again, right-click them, select "Print";

enter image description here

  • select location where to save the file and in the list of printers select "Print to file".

enter image description here

(By the way, I am the OP and author of another answer too (now signed user32012): I have deleted my account at some point and now I'm back.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy