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?
714 Answers
If you're willing to use a terminal, you can use ImageMagick. Install it with
sudo apt install imagemagickthen you can do:
convert image1.jpg image2.png text.txt PDFfile.pdf outputFileName.pdfIt 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.
Install pdftk
sudo apt-get install pdftkPdftk
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.pdfIt 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
6Try 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.
You can install it either from the default repos, or get the latest and greatest from PDF Chain PPA.
sudo apt-get install pdfchainOr 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 pdfmodSee also:
3For 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.pdfI 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.
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.pdfThis 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.
3Install 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
6I 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.
3Try 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:
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:
For different font sizes:
For different fonts:
To change page size and margins when using pdflatex: \usepackage[pass,paperwidth=148mm,paperheight=210mm,margin=5mm]{geometry}
Adding on the community answer above, you can doconvert 'ls *.jpg -tr'. To force the PDF file to have the images in chronological order.
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.pdfUnlike 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.
Using Gimp, import as layers, export as pdf:)
Gimp version: 2.10.8
31. 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:
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 :
Any image readable by Leptonica is supported in Tesseract including BMP, PNM, PNG, JFIF, JPEG, and TIFF. GIF is not supported .
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 imagesThat'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.pdfSee pdf2searchablepdf -h for the full help menu, including options and other examples.
2. Text to PDF
See:
3. PDF to single PDF
See:
I use PDF-Shuffler for this kind of use, it works great.
sudo apt-get install pdfshufflerIt is a graphical tool. You simply load all the pdf files you want to fuse. You can change the page order as you wish.
4For 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 imagemagickThe converter, installed as part of imagemagick converts to one pdf:
convert "*.{png}" -quality 100 combined.pdfIf you already have single page pdfs, merge them with pdftk:
pdftk *.pdf cat output combined.pdf 2