Меню Рубрики

Convert jpg to pdf linux

Конвертирование jpg в pdf в Linux

Формат jpg несомненно является самым популярным графическим форматом в интернете, однако в некоторых случаях удобнее использовать pdf, так как он может включать как растровую, так и векторную графику. Поэтому качество печати изображений jpg зависит только от их разрешения и степени сжатия, в то время как векторные pdf-файлы можно печатать любого размера. Кроме того, pdf-файлы с текстовым слоем поддерживают поиск по содержимому и могут содержать больше метаданных, чем jpg.
В Linux для конвертирования jpg в pdf вы можете использовать ImageMagic или GhostScript.

Конвертирование jpg в pdf с помощью ImageMagick

Для начала установите ImageMagick.

В пакет ImageMagick входит утилита convert, которая позволяет конвертировать jpg в pdf. Эта команда масштабирует изображение таким образом, чтобы оно соответствовало размеру страницы. Конвертирование осуществляется с помощью команды:

Если вы хотите конвертировать несколько изображений jpg в один pdf-файл (с несколькими страницами), это делается с помощью команды:

Утилита convert также поддерживает различные операции редактирования изображения перед его конвертированием в формат pdf.

С помощью опции “-page” команды convert можно задать размер страницы. Если размер больше, чем размер исходного изображения, оно будет размещено в левом нижнем углу страницы.

Можно также задать размер изображения:

Изменить размер изображения:

Конвертирование jpg в pdf с помощью Ghostscript

Сначала установите ghostscript.

Для конвертирования используется команда gs вида:

Конвертирование нескольких изображений jpg в один файл pdf осуществляется с помощью команды:


JPG (documents) to PDF (linux console) [closed]

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 6 years ago .

I have some high quality JPG. They are documents, I mean, no photos, no pictures, mainly text.

Is there any way to convert them into a PDF considering they are documents and they have to be slightly transformed, rotated, aligned, cropped, maybe solarized and joined ?

When you scan a document it’s not perfectly straight and maybe it’s in some perspective. I’ve seen some software doing this (the app CamScanner per example).

Any way to do it in linux console ?

7 Answers 7

There is a lot of command line tools to modify pictures, I guess that is not really the problem. But converting it to PDF is?

Without researching the parameters, here comes the commands to transform a JPEG to PDF:

jpegtopnm | pnmtotiff | tiff2pdf

Have a look at the ScanTailor project. This is a very good tool to prepare all kinds of scanned or photographed documents that mainly consist of text (as you have) as a preparation for any OCR software (in open source you would choose tesseract-ocr, optionally in combination with gImageReader). However there is only support for batch processing which is also very powerful. If you still need a cli interface then you need to change the source code which you can find in github by yourself.

Why no imagemagick? It is more or less the standard on scripted image processing. I don’t think that you will find an alternative.

Is there any way to convert them into a PDF considering they are documents and they have to be slightly transformed, rotated, aligned, cropped, maybe solarized and joined ?

With convert command various options are available which can be seen on the man page HERE, you can use to transform, rotate, align, crop the image file from command line easily.

install package imagemagick ( in ubuntu sudo apt-get install imagemagick)

When you scan a document it’s not perfectly straight and maybe it’s in some perspective. I’ve seen some software doing this (the app CamScanner per example).

But also CS needs the support of a human. Without human interaction it’s very hard to get perspective and so on right.

If you want to do such things, you’ll maybe need to implement it yourself. You could start looking at OpenCV examples. Here’s a nice one: Automatic perspective correction for quadrilateral objects.

OpenCV does not support PDF creation. So once you have prepared the image and obtained the necessary parameters (clippping, perspective, scaling) you can use other tools/libraries like ImageMagick to create a PDF out of your image data.


Convert a directory of JPEG files to a single PDF document

I have many JPEG files in a directory, and I want to convert them to PDF and concatenate them together to make a single document.

How can this be done?

I would prefer using the command line, as this process will be faster.

8 Answers 8

From the imagemagick package, use the convert command:

You will get a single pdf containing all jpg in the current folder.

Edit: Note that images will be out of specific order if they are not numbered. if you have 10 or more you need to name them ending filename01.jpg. filename99.jpg etc. The leading zeros are required for proper ordering. If you have 100 or more 001. 999.

Unfortunately, convert changes the image quality before “packing it” into the PDF. So, to have minimal loss of quality, is better to put the original jpg into the PDF, you need to use img2pdf .

I use these commands:

A shorter one liner solution also using img2pdf sugested in the comments

img2pdf *.jp* –output combined.pdf

OCR the output PDF

ocrmypdf combined.pdf combined_ocr.pdf

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

This command is 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

This command will concatenate the pdf pages into one document:

pdftk *.pdf cat output combined.pdf

And finally, I add an OCRed text layer that doesn’t change the quality of the scan in the pdfs so that they can be searchable:

An alternative to using pypdfocr :

ocrmypdf combined.pdf combined_ocr.pdf

  • This ls will list one file a time in a “natural order” (1,2,3. ) and proceed with conversion.

Worked for me (BUT warning! turns off compression and resulting PDF will be big!):

From ubuntuforums.org, the +compress helps it to not hang. NOTE: the +compress turns off compression. The machine I was working on at the time seemed to hang ?forever?(I did not wait forever though to find out.) without the +compress option. Your Mileage May Vary quite a bit! RTFM on imagemagick.org option -compress, maybe experiment with -compress if you have slow compression/hanging problems to find out what will work for you.

Open jpg or png file with LibreOffice Writer and export as PDF.

I hope, this is simple way to export pdf.

The following solution also relies on ImageMagick’s convert but is a bit more sophisticated because:

  • It allows all images to have different dimensions, while keeping the output PDF page size the same (A4 in the example below).
  • It centers the images on the PDF page.
  • It allows you to guarantee a minimum space between image borders and PDF page borders, to allow printing the PDF without problems.
  • It does not change the image data. (So image quality is unaffected, the PDF file has about the same file size as the image, and you can re-extract the original images later with pdfimages -j file.pdf img .) At the moment, this only works with PNG – see the comment by @dma_k below.

    Use my script from this answer to convert each image into its own one-page PDF file with A4 page size and 5% border all around.

Concatenate all your one-page PDF files with PDFtk as follows:


Конвертирование pdf в формат jpg в Linux

Хотя PDF является широко используемым форматом документов и поддерживается множеством приложений, в некоторых случаях может потребоваться конвертировать его в другие форматы, например в jpg, чтобы вставить в презентацию. Приведенное ниже руководство поможет вам преобразовать файл формата PDF в jpg/jpeg в операционной системе Linux.

Самый простой способ конвертирования – воспользоваться ImageMagick.

Обратите внимание, что если input.pdf – это многостраничный pdf-файл, то вышеприведенная команда создаст ровно столько изображений, сколько страниц имеется в pdf-файле (т.е. output-0.jpg, output-1.jpg, output-2.jpg и т.д).

Для конвертирования в jpg с заданным уровнем компрессии, используется команда вида:

Опция “-quality” задает уровень компрессии изображения. Для формата JPG диапазон уровней компрессии ранжируется от 1 (лучшая компрессия и худшее качество) до 100 (лучшее качество и худшая компрессия).

Конвертирование pdf в jpg шириной 500px:

Конвертирование первой страницы pdf-файла в jpg:

Конвертирование нескольких pdf-файлов в формат jpg в пакетном режиме:

Если вы думаете, что конвертирование займет слишком много оперативной памяти и приведет к замедлению работы системы, вы можете проверить количество доступных ресурсов и ограничить их использование:

В приведенной выше команде ImageMagic/convert опирается на Ghostscript для интерпретации файлов PDF. Вы можете использовать Ghostscript напрямую для конвертации pdf в jpg следующим образом:

Приведенная выше команда генерирует серию файлов (image1.jpg, image2.jpg. image5.jpg) для первых пяти страниц входящего файла pdf. Уровень компрессии JPG составляет 100, разрешение (ширина) изображения 500px.


How To Convert Multiple Images To PDF In Ubuntu Linux

Last updated October 28, 2019 By Abhishek Prakash 47 Comments

You have several documents or images scanned individually and you need to save multiple images to one PDF file. If you Google, you will find many online websites for this purpose. But they are either not free or they will put their watermark on the final PDF file. You don’t want it, do you?

I had this need when I had to apply for a job and they required me to upload a single PDF file consisting of several documents. My problem was that I had documents scanned individually but not in one file. It’s just one of the example where you may need to convert multiple image files in one PDF file.

If you are using Ubuntu then many people would suggest to use the command line tool Image Magic. But if you prefer a GUI tool over command line, gscan2pdf that is the perfect tool for merging multiple images into one PDF file. We shall see both methods in this tutorial.

1. The GUI way to convert multiple images to PDF in Ubuntu Linux

In this tutorial we’ll see how to convert multiple images to PDF with gscan2pdf. Though the tutorial is performed in Ubuntu 14.04, it should be valid for earlier or newer Ubuntu versions as well as other Linux distributions based on Ubuntu such as Linux Mint and elementary OS.

Install gscan2pdf in Ubuntu:

Open terminal (Ctrl+Alt+T) and use the following command to install gscan2pdf:

How to convert multiple images to PDF with gscan2pdf:

Once installed, open gscan2pdf by searching for it in Unity Dash:

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. Once done, you can click on the Save icon to save the files to PDF.

When you hit the save button, the next screen might look confusing. Actually it provides you option of putting metadata in the document such as author, date etc similar to a word document. If you just want a PDF file, hit the save button. 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.

2. The command line way to convert multiple images to PDF in Ubuntu Linux

If you want to go the command line way, you can use ImageMagick. It’s very easy to convert several images into one PDF file this way as well.

Open a terminal and install ImageMagic using the command below:

Once you have it installed, use the ‘convert’ command line tool of ImageMagic. Just provide the paths to individual images and at the end of the command, name the output file. For example, something like this:

That’s it. Nothing more to be done. Cool isn’t it? 🙂

Did it work for you?

I hope this article helped you to merge multiple images into one PDF in Ubuntu Linux. If you are further interested, check this article to know how to edit PDF files in Ubuntu Linux.

Questions, suggestions, a word of thanks is always encouraged.

Like what you read? Please share it with others.