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
- Download a trial copy of JPedal.
- Make sure your Computer has Java installed.
- Open up a Command line or console window
- 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
- Download a trial copy of JPedal and add it to your IDE.
- Create a File handle, InputStream or URL pointing to the PDF file
- Create a File handle, InputStream or URL pointing to the PDF file
ConvertPagesToImages extract=new ConvertPagesToImages(path);
- Include a password if file password protected
extract.setPassword("password");
- Open the PDF file
if (extract.openPDFFile()) {
- Iterate over the pages
int pageCount = extract.getPageCount(); for (int page = 1; page <= pageCount; page++) { BufferedImage img = extract.getPageAsImage(page, hasAlpha); } }
- 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 |