Create a single pdf from multiple text, images or pdf files

220,265

Solution 1

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

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.

Solution 2

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

Solution 3

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:

Solution 4

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.

Solution 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.

Share:
220,265
AJha
Author by

AJha

Updated on September 18, 2022

Comments

  • AJha
    AJha over 1 year

    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?

    • Radu Rădeanu
      Radu Rădeanu almost 11 years
      Take a look at this answer: askubuntu.com/a/302927/147044
    • Alaa Ali
      Alaa Ali almost 11 years
      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.
    • LAFK says Reinstate Monica
      LAFK says Reinstate Monica over 10 years
      @Alaa you should post this as an answer rather than a comment. Simple, concise and on the money.
    • Bran
      Bran over 9 years
      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.
    • zrajm
      zrajm over 9 years
    • Gabriel Staples
      Gabriel Staples over 2 years
      @AlaaAli, you can take your resulting PDF and make it searchable again using my pdf2searchablepdf tool I wrote, which I describe here. It's a wrapper around the tesseract OCR engine.
    • Gabriel Staples
      Gabriel Staples over 2 years
  • Force
    Force over 10 years
    Master PDF Editor is not free.
  • web.learner
    web.learner over 10 years
    Can you include instructions on how to do what the OP wants?
  • cochisebt
    cochisebt over 10 years
    It is done. :-)
  • borisdiakur
    borisdiakur over 10 years
    I would downvote, but have not enough rep. PDF-Shuffler accepts only PDF files. Question also included image files and text files.
  • cochisebt
    cochisebt over 10 years
    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.
  • landroni
    landroni about 10 years
    There is a GUI for pdftk. See my answer.
  • Garrett
    Garrett about 10 years
    But can this concatenate text files, images and PDF files, as in the question?
  • Garrett
    Garrett about 10 years
    This doesn't work for concatenating images with PDFs though, right?
  • landroni
    landroni about 10 years
    You can convert the text files (say, Print to PDF) or the images (via convert) to PDF, and then use that.
  • Warren Hill
    Warren Hill about 10 years
    @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.
  • VishApp
    VishApp over 9 years
    ImageMagic convert reduces quality and increases size in my experience. Try pdftk. But not sure how you add images there.
  • RajaRaviVarma
    RajaRaviVarma over 9 years
    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
  • janot
    janot about 9 years
    @Force From their site: The Linux-based version is free for non-commercial use.
  • tobltobs
    tobltobs about 9 years
    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.
  • conualfy
    conualfy over 8 years
    Works like a charm and keeps the vectorial text in pdf.
  • conualfy
    conualfy over 8 years
    @Garrett - just tried PDF Chain and it works to concatenate pdf files.
  • Marcellinov
    Marcellinov about 8 years
    This seems more a comment then an answer... please review askubuntu.com/help/how-to-answer
  • Sparhawk
    Sparhawk about 7 years
    @janot Yes, but I don't think it's free.
  • j.c
    j.c about 7 years
    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.
  • Admin
    Admin over 6 years
    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.
  • Admin
    Admin over 6 years
  • Max
    Max about 6 years
    Exactly what I needed! Tried multiple tools all had some issue in sorting for example. Perfect!
  • Chris1804505
    Chris1804505 almost 6 years
    You can install it via sudo apt install imagemagick. Otherwise you don't have the convert command.
  • Chris1804505
    Chris1804505 almost 6 years
    You can install it via sudo apt install imagemagick. Otherwise you don't have the convert command.
  • markasoftware
    markasoftware over 5 years
    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.
  • Michael
    Michael over 5 years
    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.
  • adq
    adq over 5 years
  • Lexible
    Lexible about 5 years
    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
    Lexible about 5 years
    The OP is asking how to convert image1.tif image 2.tif image 3.jpg to images.pdf
  • kubus
    kubus about 5 years
    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.
  • Boxbot
    Boxbot about 5 years
    Doesn't appear to be available in the default repos any more?
  • cipricus
    cipricus over 4 years
    a lot of functions are not allowed in the free version
  • cipricus
    cipricus over 4 years
    pdftk in 18.04: askubuntu.com/a/1165823/925128 (CLI only, as pdfchain is not available in 18.04 afaik)
  • kap
    kap over 3 years
    For newer ubuntu versions (since 18.04 I believe) use snap install pdftk.
  • Nav
    Nav over 3 years
    This is interesting. OP, could you please demonstrate it with some sample code?
  • xeruf
    xeruf about 3 years
    you do know that this is askubuntu, and exes aren't useful on ubuntu? ;)
  • Zimba
    Zimba about 3 years
    Hehe thanks for feedback. I've updated answer for base installs
  • Andy Mikhaylenko
    Andy Mikhaylenko about 3 years
    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!
  • David C. Rankin
    David C. Rankin over 2 years
    pdfjoin will also create pdfs from images, e.g. pdfjoin -o images.pdf *.png
  • Gabriel Staples
    Gabriel Staples over 2 years
    @AlaaAli, you can take your resulting PDF and make it searchable again using my pdf2searchablepdf tool I wrote, which I describe here. It's a wrapper around the tesseract OCR engine.
  • Gabriel Staples
    Gabriel Staples over 2 years
    convert doesn't work for me. :( Example run: convert *.jpg my.pdf or convert pg-1.jpg pg-2.jpg out.pdf. They both produce the following error: convert-im6.q16: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408.
  • Gabriel Staples
    Gabriel Staples over 2 years
    I found a solution for the convert-im6.q16: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408. error!: see stackoverflow.com/a/53180170/4561887
  • Gabriel Staples
    Gabriel Staples over 2 years
    This doesn't work on text files at all. I get error: convert-im6.q16: improper image header `text.txt' @ error/txt.c/ReadTXTImage/450.
  • cipricus
    cipricus over 2 years
    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
    cipricus over 2 years
    @markasoftware - Reduce the size of a PDF file consisting of scanned images. A service menu for Dolphin file manager here.
  • cipricus
    cipricus over 2 years
    @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.
  • Veles
    Veles over 2 years
    In the menu, under <File> there exists an option <Open as Layers> as well as one <Export as>. Version: 2.10.30
  • user1325696
    user1325696 over 2 years
    Im getting error convert-im6.q16: not authorized `./output.pdf' @ error/constitute.c/WriteImage/1037.