Convert PDF to Image Formats in Java

Aspose.PDF for Java can render PDF pages to raster and vector image formats with format-specific device options.

Convert PDF to BMP

Use this example when PDF pages should be rendered as BMP images.

  1. Open the source PDF in a Document instance.
  2. Create a BmpDevice with a Resolution of 300 DPI.
  3. Iterate through document.getPages() and call device.process(...) for each page.
  4. Save the generated BMP images to numbered output paths.
public static void convertPdfToBmp(Path inputFile, Path outputPrefix) {
       try (Document document = new Document(inputFile.toString())) {
           BmpDevice device = new BmpDevice(new Resolution(300));
           for (int page = 1; page <= document.getPages().size(); page++) {
               device.process(document.getPages().get_Item(page), numberedOutput(outputPrefix, page, "bmp"));
           }
       }
       System.out.println(inputFile + " converted into " + outputPrefix);
   }

Convert PDF to EMF

Use this example when PDF pages should be exported as EMF vector images.

  1. Open the source PDF in a Document instance.
  2. Create an EmfDevice with a Resolution of 300 DPI.
  3. Iterate through the pages and call device.process(...) for each page.
  4. Save the EMF outputs to numbered file paths.
public static void convertPdfToEmf(Path inputFile, Path outputPrefix) {
    try (Document document = new Document(inputFile.toString())) {
        EmfDevice device = new EmfDevice(new Resolution(300));
        for (int page = 1; page <= document.getPages().size(); page++) {
            device.process(document.getPages().get_Item(page), numberedOutput(outputPrefix, page, "emf"));
        }
    }
    System.out.println(inputFile + " converted into " + outputPrefix);
}

Convert PDF to GIF

Use this example when PDF pages should be converted into GIF images.

  1. Open the source PDF in a Document instance.
  2. Create a GifDevice with a Resolution of 300 DPI.
  3. Iterate through the pages and call device.process(...) to render each page.
  4. Save the GIF files to numbered output paths.
public static void convertPdfToGif(Path inputFile, Path outputPrefix) {
    try (Document document = new Document(inputFile.toString())) {
        GifDevice device = new GifDevice(new Resolution(300));
        for (int page = 1; page <= document.getPages().size(); page++) {
            device.process(document.getPages().get_Item(page), numberedOutput(outputPrefix, page, "gif"));
        }
    }
    System.out.println(inputFile + " converted into " + outputPrefix);
}

Convert PDF to JPEG

Use this example when PDF pages should be exported as JPEG images.

  1. Open the source PDF in a Document instance.
  2. Create a JpegDevice with a Resolution of 300 DPI.
  3. Iterate through the pages and call device.process(...) to rasterize each page to JPEG.
  4. Save the JPEG output files to numbered paths.
public static void convertPdfToJpeg(Path inputFile, Path outputPrefix) {
    try (Document document = new Document(inputFile.toString())) {
        JpegDevice device = new JpegDevice(new Resolution(300));
        for (int page = 1; page <= document.getPages().size(); page++) {
            device.process(document.getPages().get_Item(page), numberedOutput(outputPrefix, page, "jpeg"));
        }
    }
    System.out.println(inputFile + " converted into " + outputPrefix);
}

Convert PDF to PNG

Use this example when PDF pages should be converted into PNG images.

  1. Open the source PDF in a Document instance.
  2. Create a PngDevice with a Resolution of 300 DPI.
  3. Iterate through the pages and call device.process(...) for each PDF page.
  4. Save the PNG outputs to numbered file paths.
public static void convertPdfToPng(Path inputFile, Path outputPrefix) {
    try (Document document = new Document(inputFile.toString())) {
        PngDevice device = new PngDevice(new Resolution(300));
        for (int page = 1; page <= document.getPages().size(); page++) {
            device.process(document.getPages().get_Item(page), numberedOutput(outputPrefix, page, "png"));
        }
    }
    System.out.println(inputFile + " converted into " + outputPrefix);
}

Convert PDF to PNG with a default font fallback

Use this example when rendering should use a fallback font for missing glyphs.

  1. Open the source PDF in a Document instance.
  2. Create a PngDevice with a Resolution of 300 DPI.
  3. Enable document.setAbsentFontTryToSubstitute(true) so missing glyphs can fall back to substitute fonts during rendering.
  4. Render the pages and save the PNG files.
public static void convertPdfToPngWithDefaultFont(Path inputFile, Path outputPrefix) {
    try (Document document = new Document(inputFile.toString())) {
        PngDevice device = new PngDevice(new Resolution(300));
        document.setAbsentFontTryToSubstitute(true);
        for (int page = 1; page <= document.getPages().size(); page++) {
            device.process(document.getPages().get_Item(page), numberedOutput(outputPrefix, page, "png"));
        }
    }
    System.out.println(inputFile + " converted into " + outputPrefix);
}

Convert PDF to SVG

Use this example when PDF pages should be exported as SVG graphics.

  1. Open the source PDF in a Document instance.
  2. Create SvgSaveOptions and disable ZIP compression when raw .svg output is required.
  3. Enable setTreatTargetFileNameAsDirectory(true) so per-page SVG output can be organized under the target path.
  4. Save the SVG output.
public static void convertPdfToSvg(Path inputFile, Path outputPrefix) {
    try (Document document = new Document(inputFile.toString())) {
        SvgSaveOptions saveOptions = new SvgSaveOptions();
        saveOptions.setCompressOutputToZipArchive(false);
        saveOptions.setTreatTargetFileNameAsDirectory(true);
        document.save(outputPrefix + ".svg", saveOptions);
    }
    System.out.println(inputFile + " converted into " + outputPrefix);
}

Convert PDF to TIFF

Use this example when one or more PDF pages should be exported to TIFF.

  1. Open the source PDF in a Document instance.
  2. Create TiffSettings and configure compression, color depth, and blank-page behavior.
  3. Create a TiffDevice with a Resolution of 300 DPI and the prepared TIFF settings.
  4. Render the pages and save the TIFF output.
public static void convertPdfToTiff(Path inputFile, Path outputPrefix) {
    try (Document document = new Document(inputFile.toString())) {
        TiffSettings tiffSettings = new TiffSettings();
        tiffSettings.setCompression(CompressionType.LZW);
        tiffSettings.setDepth(ColorDepth.Default);
        tiffSettings.setSkipBlankPages(false);

        TiffDevice tiffDevice = new TiffDevice(new Resolution(300), tiffSettings);
        tiffDevice.process(document, outputPrefix + ".tiff");
    }
    System.out.println(inputFile + " converted into " + outputPrefix);
}