DeveloperBreeze

How to Convert PDF to Image on Ubuntu

Converting a PDF to an image can be useful for sharing content on platforms that don't support PDF, or for extracting images from a PDF file. This tutorial will guide you through converting PDF files to image formats like PNG or JPEG on Ubuntu.

Requirements

To convert PDFs to images on Ubuntu, we’ll use a tool called pdftoppm, which is part of the poppler-utils package, and ImageMagick to provide more options if needed.

Step 1: Install poppler-utils

The pdftoppm tool is available via poppler-utils. To install it, open a terminal and run the following command:

sudo apt update
sudo apt install poppler-utils

Step 2: Convert PDF to Image

Once pdftoppm is installed, you can use it to convert a PDF to an image format like PNG or JPEG.

Syntax

pdftoppm [options] input.pdf output

For example, to convert the first page of a PDF to a PNG image, use the following command:

pdftoppm -png input.pdf output

This will convert all pages of the PDF into PNG images, and the images will be saved with names like output-1.png, output-2.png, etc.

If you want to convert specific pages, you can specify the page range using the -f (from page) and -l (last page) options:

pdftoppm -png -f 1 -l 1 input.pdf output

This command converts only the first page of the PDF into a PNG image.

Step 3: Convert PDF to JPEG

To convert the PDF to JPEG format, simply change the -png flag to -jpeg:

pdftoppm -jpeg input.pdf output

Again, all pages will be converted, and each page will be saved as output-1.jpg, output-2.jpg, etc.

Step 4: Install ImageMagick (Optional)

For more advanced conversion options, you can use ImageMagick, which is a powerful image processing tool.

Install it by running:

sudo apt install imagemagick

Once installed, you can use the convert command to convert PDFs to images:

convert -density 150 input.pdf output.png

Here, -density 150 sets the resolution of the output image, which can improve image quality. You can replace output.png with output.jpg for JPEG conversion.

Step 5: Handling Multi-Page PDFs

If you want to convert only specific pages of a PDF with convert, you can specify the page number:

convert -density 150 input.pdf[0] output.png

This command converts only the first page (0-indexed) of the PDF to an image. You can adjust the page number as needed.

Step 6: Batch Conversion (Optional)

If you have multiple PDF files to convert, you can use a simple loop to convert all PDFs in a directory to images:

for pdf in *.pdf; do
    pdftoppm -png "$pdf" "${pdf%.pdf}"
done

This script converts all PDF files in the current directory to PNG images.

Conclusion

You now know how to convert PDF files to image formats like PNG or JPEG using both pdftoppm and ImageMagick on Ubuntu. These tools provide flexibility, allowing you to convert single or multiple pages and adjust image quality as needed.

Summary of Key Commands:

  • Convert PDF to PNG:
  pdftoppm -png input.pdf output
  • Convert PDF to JPEG:
  pdftoppm -jpeg input.pdf output
  • Using ImageMagick:
  convert -density 150 input.pdf output.png

Related Posts

More content you might like

Tutorial

How to Stop SSH From Timing Out

If your SSH session closes after a minute of inactivity, it’s usually caused by idle timeouts. You can fix this with keep-alive settings on both the server and client.

Edit the SSH daemon config:

Aug 21, 2025
Read More
Tutorial

How to Translate URLs in React (2025 Guide)

  • How to structure language-specific routes
  • How to integrate URL translation with react-router-dom
  • How to switch routes with language changes
  • Bonus: how to integrate with react-i18next

Start with a React project (you can use CRA or Vite):

May 04, 2025
Read More
Tutorial

Globalization in React (2025 Trends & Best Practices)

const formatCurrency = (value, lng) => {
  const currency = lng === 'ar' ? 'EGP' : 'USD';
  return new Intl.NumberFormat(lng, {
    style: 'currency',
    currency
  }).format(value);
};

Languages like Arabic and Hebrew need RTL layouts. Use CSS:

May 04, 2025
Read More
Tutorial

Implementing Internationalization (i18n) in a Large React Application (2025 Guide)

import React from 'react';
import { useTranslation } from 'react-i18next';

const Home = () => {
  const { t, i18n } = useTranslation();

  const changeLanguage = (lng) => {
    i18n.changeLanguage(lng);
  };

  const today = new Date();
  const price = 199.99;

  return (
    <div className="p-4">
      <h1>{t('welcome')}</h1>

      <div className="mt-4">
        <strong>{t('language')}:</strong>
        <button onClick={() => changeLanguage('en')} className="ml-2">EN</button>
        <button onClick={() => changeLanguage('fr')} className="ml-2">FR</button>
      </div>

      <p>{t('date_example', { date: today })}</p>
      <p>{t('price_example', { price })}</p>
    </div>
  );
};

export default Home;

Install i18next-format plugin (optional):

May 04, 2025
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Be the first to share your thoughts!