164

I have a bunch of text files, images and pdf files which I want to convert into a single pdf file. How do I do it?

7
  • Take a look at this answer: askubuntu.com/a/302927/147044 Jun 4, 2013 at 8:30
  • 22
    Well, you can do convert image1.jpg image2.png text.txt PDFfile.pdf outputFileName.pdf. It worked for me, but the problem is it converts the text.txt file into an image, so you can't highlight the text in the resulting pdf.
    – Alaa Ali
    Jun 4, 2013 at 8:46
  • 5
    @Alaa you should post this as an answer rather than a comment. Simple, concise and on the money. Dec 14, 2013 at 2:10
  • 1
    gscan2pdf Is a GUI version also in case the command 'convert' fails and worked for me. (from ifoss.com): Once gscan2pdf is opened, you can select all the required files in it by clicking on the Open Files. By default it is arranged in alphabetical order but you can drag and drop to reorder the images as per your choice. then click on the Save icon to save the files to PDF. if you just want a PDF file, hit the save . Since by default the output file is PDF, you don’t need to bother a lot here. Just choose where to save the converted file. Save the converted images to pdf, That’s it.
    – Bran
    Sep 8, 2014 at 0:05
  • See also How to generate a PDF from a series of images? on superuser.
    – zrajm
    Jan 20, 2015 at 12:47

15 Answers 15

213

If you're willing to use a terminal, you can use ImageMagick. Install it with

sudo apt install imagemagick

then you can do:

convert image1.jpg image2.png text.txt PDFfile.pdf outputFileName.pdf

or as another example:

convert *.jpg outputJpgFiles.pdf

It worked for me, but the problem is it converts the text.txt file into an image, so you can't highlight the text in the resulting pdf.

13
  • 5
    ImageMagic convert reduces quality and increases size in my experience. Try pdftk. But not sure how you add images there. Sep 22, 2014 at 12:22
  • 6
    You can tweak with -quality flag to increase or decrease the resulting PDF file size. Example: convert -quality 50 image1.jpeg image2.jpeg image3.jpeg outputFileName.pdf Feb 4, 2015 at 18:36
  • 6
    Be aware that convert uses ghostscript under the hood and gs will decode and reencode JPEGs which result in a loss of quality, even if speciiy a high quality.
    – tobltobs
    May 4, 2015 at 9:28
  • 6
    I had to create more than 6000 pdfs starting from 30000 tiffs. convert estimate time ~6-7 hours. I used tiffcp and tiff2pdf, they took few seconds.
    – j.c
    May 4, 2017 at 10:15
  • 10
    uh... wth?! When I run convert with two png files as input and "Test.pdf" as the output, I get this error: convert-im6.q16: not authorized `Test.pdf' @ error/constitute.c/WriteImage/1037.
    – Michael
    Dec 23, 2018 at 22:24
41

Install pdftk

sudo apt-get install pdftk

Pdftk

If PDF is electronic paper, then pdftk is an electronic staple-remover, hole-punch, binder, secret-decoder-ring, and X-Ray-glasses. Pdftk is a simple tool for doing everyday things with PDF documents.

You can create pdf files from text or images with Libre Office then to stitch these togeter with other pdf files

pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf

It can also

  • Split PDF Pages into a New Document

  • Rotate PDF Pages or Documents

and a lot more besides

More details here: Ubuntu Geek: List of PDF Editing tools

6
  • 1
    There is a GUI for pdftk. See my answer.
    – landroni
    Mar 26, 2014 at 9:23
  • 11
    This doesn't work for concatenating images with PDFs though, right?
    – Garrett
    May 28, 2014 at 21:52
  • 3
    @Garret. No but there are several ways of converting an image to pdf, using covert for example or just print to pdf from many programs. Once the image is a pdf then you can use pdftk to join them together. May 29, 2014 at 7:22
  • 1
    Works like a charm and keeps the vectorial text in pdf.
    – conualfy
    Jan 10, 2016 at 22:32
  • 3
    Doesn't appear to be available in the default repos any more?
    – Boxbot
    May 22, 2019 at 21:53
21

Try PDF Chain:

PDF Chain is a graphical user interface for the PDF Toolkit (PDFtk). The GUI supports all common features of the command line tool in a comfortable way.

enter image description here

You can install it either from the default repos, or get the latest and greatest from PDF Chain PPA.

sudo apt-get install pdfchain

Or PDF Mod:

PDF Mod is a simple application for modifying PDF documents.

You can reorder, rotate, and remove pages, export images from a document, edit the title, subject, author, and keywords, and combine documents via drag and drop.

sudo apt-get install pdfmod

enter image description here


See also:

3
  • 7
    But can this concatenate text files, images and PDF files, as in the question?
    – Garrett
    May 28, 2014 at 21:35
  • 1
    You can convert the text files (say, Print to PDF) or the images (via convert) to PDF, and then use that.
    – landroni
    May 29, 2014 at 4:53
  • @Garrett - just tried PDF Chain and it works to concatenate pdf files.
    – conualfy
    Jan 10, 2016 at 22:37
15

For multiple files inside a directory and its subdirectories with different extensions I couldn't find a neat answer, so here it is

convert -quality 85 `find -type f -name '*.png' -or -name '*.jpg' | sort -V` output.pdf

I used command substitution to pass the selected items returned by find command as an argument to convert command. Unfortunately sort -n didn't sort my files correctly so I tried -V option and it did the trick. Also make sure the name of your files and directories are in natural sort order in advance. For example dir1, dir2, dir3 not dir1, dir_2, dir3.

6
  • 2
    Exactly what I needed! Tried multiple tools all had some issue in sorting for example. Perfect!
    – Max
    Mar 28, 2018 at 17:12
  • 1
    You can install it via sudo apt install imagemagick. Otherwise you don't have the convert command. Aug 13, 2018 at 18:50
  • 1
    Im getting error convert-im6.q16: not authorized `./output.pdf' @ error/constitute.c/WriteImage/1037. Jan 31, 2022 at 16:46
  • @user1325696 i got also your error.
    – SL5net
    Oct 4, 2022 at 11:12
  • 1
    @SL5net See this: askubuntu.com/q/1081895/255257
    – Dante
    Oct 4, 2022 at 11:21
5

This is the solution i used to convert multiple TIFFs to PDFs.

I had to create more than 6.000 PDFs starting from 30.000 tiffs. convert estimate time: 6 to 7 hours.
I used tiffcp and tiff2pdf, they took few seconds.

$ tiffcp 1.tiff 2.tiff ... multi.tiff
$ tiff2pdf multi.tiff > final.pdf

This way is really fast because images are not converted, just packed.

Maybe there are some tiff formats that doesn't work so easily, for me it worked perfectly.

Hope it helps.

3
  • 1
    Hrm, my input tif files are 160M, but the pdf generated by tiff2pdf is about 820M. Not sure if this is really "just packing" things. Sep 8, 2018 at 1:09
  • @markasoftware - Reduce the size of a PDF file consisting of scanned images. A service menu for Dolphin file manager here.
    – cipricus
    Jan 17, 2022 at 13:36
  • @markasoftware - In my case 90 MB multi.tiff was converted to a 365 MB pdf. Looking into it with pdfimages -list, under image type is listed image, which may mean uncompressed, with width/height 4600 /6408. - Shrinking it to 300 dpi gave a 30 MB pdf with no sensible decrease of quality.
    – cipricus
    Jan 17, 2022 at 14:17
4

Install Master PDF editor. The tool offers creating, merging and extracting PDF files. Check here for details about master PDF editor and installing it on Ubuntu

6
  • 8
    Master PDF Editor is not free.
    – Force
    Nov 18, 2013 at 9:20
  • 2
    @Force From their site: The Linux-based version is free for non-commercial use.
    – janot
    Mar 19, 2015 at 13:59
  • 2
    @janot Yes, but I don't think it's free.
    – Sparhawk
    Mar 23, 2017 at 1:03
  • 1
    It is free for non-commercial purposes, works great. This is a modern, up-to-date tool, unlike others mentioned here, which are very high voted but are old and rudimentary.
    – user47206
    Jan 24, 2018 at 19:59
  • 1
    code-industry.net/free-pdf-editor/#get
    – user47206
    Jan 24, 2018 at 20:00
2

I use PDF-Shuffler for this kind of use, it works great.

sudo apt-get install pdfshuffler

It is a graphical tool. You simply load all the pdf files you want to fuse. You can change the page order as you wish.

5
  • Can you include instructions on how to do what the OP wants?
    – Seth
    Jan 6, 2014 at 4:12
  • It is done. :-)
    – cochisebt
    Jan 6, 2014 at 4:24
  • 3
    I would downvote, but have not enough rep. PDF-Shuffler accepts only PDF files. Question also included image files and text files. Jan 31, 2014 at 12:17
  • With Libreoffice you can convert text files to pdf. As it is also possible to insert image files in Libreoffice, then convert in pdf. Once everything is in pdf, Pdf-Shuffler can do the job. But I don't think one software can do all the job at once.
    – cochisebt
    Jan 31, 2014 at 15:24
  • As of 22.04, pdfshuffler (which has been renamed as "PDF Arranger") can do what the OP asked. I needed a multi-page PDF, consisting of two jpg images: just dragged them into a new blank canvas in PDF Arranger, saved as new PDF and voilà...
    – sxc731
    Sep 11, 2022 at 11:22
2

I can't believe nobody has mentioned latex (tex) yet. It is specifically designed for producing documents, and can combine text, images, and PDFs into a 'master' document (without any degradation of quality). It is a full suite of libraries and an extensible markup language, basically - it's been around since forever and highly used in the scientific community, still.

Technically, it's a typesetting language.

3
  • 1
    This seems more a comment then an answer... please review askubuntu.com/help/how-to-answer May 14, 2016 at 20:05
  • 3
    Probably because nobody expected the OP's question to be about creating a day job-level work flow. Talk about using a nuke to start a camp fire! (I am a TeX fan, BTW, but I would never use it for this purpose.)
    – Lexible
    Apr 25, 2019 at 17:09
  • This is interesting. OP, could you please demonstrate it with some sample code?
    – Nav
    Feb 6, 2021 at 4:15
2

Try LaTeX with pdflatex.

I had never used it before but it took me about 10 minutes to start making .PDFs with it and about 40 minutes to get them customized exactly as I wanted. I included the best formatting guides I found, at the end.

sudo apt-get install pdflatex && sudo apt-get install texlive

Basically you create one .tex file - for example hello.tex - with the LaTeX language, then run pdflatex hello.tex on that file and it will generate the PDF. The basics of the language can be found here: http://www.maths.tcd.ie/~dwilkins/LaTeXPrimer/


Here is a barebones example .tex file:

 \documentclass[a4paper,10pt]{article}

 \begin{document}

 {\footnotesize
 YOUR TEXT HERE

 YOUR TEXT HERE
 }

 \end{document}

Optional extra formatting:

To add images: https://www.sharelatex.com/learn/Inserting_Images

For different font sizes: https://www.sharelatex.com/learn/Font_sizes,_families,_and_styles

For different fonts: https://www.sharelatex.com/learn/Font_typefaces

To change page size and margins when using pdflatex: \usepackage[pass,paperwidth=148mm,paperheight=210mm,margin=5mm]{geometry}

2

Adding on the community answer above, you can do convert 'ls *.jpg -tr'. To force the PDF file to have the images in chronological order.

2

There is series of utilities in package texlive-extra-utils wrapped on pdfjam. To join pdfs use

pdfjoin -o out.pdf 1.pdf 2.pdf 3.pdf

Unlike convert it directly manipulates on pdf without converting them to images.

Also on 18.04LTS (Bionic Beaver) at this moment package pdftk is not supported. I would recommend pdfjam if someone prefers to use command line.

4
  • The OP is asking how to convert image1.tif image 2.tif image 3.jpg to images.pdf
    – Lexible
    Apr 25, 2019 at 17:12
  • Not exactly. OP also wants merge pdf files with images. It is better to create pdf files from images using img2pdf command, since it creates pdf containing original image, and then use pdfjoin.
    – kubus
    Apr 27, 2019 at 11:28
  • pdftk in 18.04: askubuntu.com/a/1165823/925128 (CLI only, as pdfchain is not available in 18.04 afaik)
    – cipricus
    Dec 4, 2019 at 12:34
  • pdfjoin will also create pdfs from images, e.g. pdfjoin -o images.pdf *.png Sep 9, 2021 at 18:10
1

Using Gimp, import as layers, export as pdf:)

Gimp version: 2.10.8

3
  • This is the best answer in my case because one of the images was itself a PDF that required additional processing and convert was unable to properly, uh, convert it. I didn't expect GIMP to handle PDFs so well. Thank you! May 24, 2021 at 19:49
  • How is that done exactly? There is no gui option to export as pdf but the extension can be modified manually. At 260 pages as tif files it crashed though.
    – cipricus
    Jan 17, 2022 at 13:20
  • In the menu, under <File> there exists an option <Open as Layers> as well as one <Export as>. Version: 2.10.30
    – Spyros
    Jan 17, 2022 at 19:01
1

1. Images to PDF

A tool I wrote called pdf2searchablepdf can combine many images into a single PDF. It is particularly good if you want the final PDF to have searchable text in it, as my tool performs OCR (Optical Character Recognition) on the images using a program called tesseract in order to bundle them into a single PDF.

Installation instructions are here: https://github.com/ElectricRCAircraftGuy/PDF2SearchablePDF#install

Since pdf2searchablepdf is a wrapper around tesseract, it accepts any image format supported by tesseract, which includes bmp, pnm, png, jfif, jpeg/jpg, and tiff. Gif is not supported. See https://coptr.digipres.org/index.php/Tesseract-ocr:

Any image readable by Leptonica is supported in Tesseract including BMP, PNM, PNG, JFIF, JPEG, and TIFF. GIF is not supported http://www.leptonica.com/library-overview.html.

To convert all images into a PDF, they need to be all in the same folder and with nothing else in that folder. So, assuming you have img1.jpg, img2.jpg, and image3.jpg, you could do this:

# Create an `images` dir and move all images into it
mkdir -p images
mv *.jpg images  # use `cp` instead of `mv` to copy instead of move the images

# Now combine all of these images into 1 pdf
pdf2searchablepdf images

That's it! You'll now have a searchable PDF file called images_searchable.pdf in the directory you were in when you ran the pdf2searchablepdf command.

Note: to go the opposite direction and convert a PDF file into a bunch of image files, I like to use pdftoppm as I explain here.

To convert a non-searchable pdf named input.pdf into a searchable pdf named input_searchable.pdf, do:

pdf2searchablepdf input.pdf

See pdf2searchablepdf -h for the full help menu, including options and other examples.

2. Text to PDF

See: https://stackoverflow.com/questions/20129029/a-light-solution-to-convert-text-to-pdf-in-linux/20129300#20129300

3. PDF to single PDF

See: https://stackoverflow.com/questions/2507766/merge-convert-multiple-pdf-files-into-one-pdf/11280219#11280219

2
0

For multi-page pdf:
Convert all files to pdf, then join using a pdf writer eg. pdftk, pdfill, Microsoft Print to PDF, CutePDF, etc

For single-page pdf:
Convert all files to images eg. PNG, named in sequence. Then join to one page with image converter eg. imgconv

imgconv.exe -append *.png out2.pdf (for vertical)
imgconv.exe +append *.png out2.pdf (for sideways)

if you're not on Win 10 WSL, load ImageMagick:

sudo apt-get install imagemagick

The converter, installed as part of imagemagick converts to one pdf:

convert "*.{png}" -quality 100 combined.pdf

If you already have single page pdfs, merge them with pdftk:

pdftk *.pdf cat output combined.pdf
2
  • you do know that this is askubuntu, and exes aren't useful on ubuntu? ;)
    – xeruf
    Apr 19, 2021 at 16:50
  • Hehe thanks for feedback. I've updated answer for base installs
    – Zimba
    May 3, 2021 at 4:31
0

To elaborate on @Veles' answer -

Using GIMP 2.10.30 -

  1. File -> Open as Layers...
  2. Select all images and click Open
  3. File -> Export As...
  4. Edit name with extension as .pdf
  5. Select 'Layers as pages (top layers first)'
  6. Select 'Reverse the pages order'
  7. Export

You must log in to answer this question.

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