Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

Are you a Java Developer working with PDF files?

Find out why you should be using JPedal

How to Rasterize PDF files

1 min read

Convert PDF to Image

What is rasterizing a PDF file?

When you rasterize a PDF file, you convert the pages of the document into image files. The advantage of rasterizing the file is that the pages cannot be edited and a PDF viewer is no longer needed to display the pages. The disadvantage is that you lose all the features of the PDF file and Viewer and have all the limitations of a bitmap display.

To rasterize a PDF file, some additional software is needed. We will show you the process using the JPedal Java PDF library and Java.

How do I convert a PDF to a raster image ?

You will need a PDF library to convert a PDF file to raster images. In our example we show you how to use the JPedal  Java PDF library.

How to Rasterize a PDF file from Command Line

  1. Download a trial copy of JPedal.
  2. Make sure your Computer has Java installed.
  3. Open up a Command line or console window
  4. Type in this command (adding in your own values).
    java -jar jpedal.jar --convert "inputFileOrDir" "outputDir" png

If you are a Java Developer, you can also add this functionality into your own code.

How to Rasterize a PDF file in Java

  1. Download a trial copy of JPedal and add it to your IDE.
  2. Create a File handle, InputStream or URL pointing to the PDF file
  3. Create a File handle, InputStream or URL pointing to the PDF file
ConvertPagesToImages extract=new ConvertPagesToImages(path);
  1. Include a password if file password protected
    extract.setPassword("password");
  2. Open the PDF file
    if (extract.openPDFFile()) {
  3. Iterate over the pages
    int pageCount = extract.getPageCount();
      for (int page = 1; page <= pageCount; page++) {
          BufferedImage img = extract.getPageAsImage(page, hasAlpha);
      }
    }
  4. Close the PDF file
     extract.closePDFfile();
    
    
    


The JPedal PDF library allows you to

Display PDF files in Java Apps
View PDF files in Java
Convert PDF Files to image
Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.