Page Capture Example

Table of Contents

About the Page Capture Example

The Page Capture example demonstrates how to use the ICEpdf Document class to capture PDF page renders as image files. Once a file has been opened, the document pages can be iterated over, to generate an image capture of each page.

The source-code for this example is located at:

A primer on using Maven or Gradle build commands can be found here (Maven) and here (Gradle)

// save page caputres to file.
float scale = 1.0f;
float rotation = 0f;

// Paint each pages content to an image and write the image to file
for (int i = 0; i < document.getNumberOfPages(); i++) {
    BufferedImage image = (BufferedImage)
            document.getPageImage(i,
                                  GraphicsRenderingHints.SCREEN,
                                  Page.BOUNDARY_CROPBOX, rotation, scale);
    RenderedImage rendImage = image;
    // capture the page image to file
    try {
        System.out.println("\t capturing page " + i);
        File file = new File("imageCapture1_" + i + ".png");
        ImageIO.write(rendImage, "png", file);

    } catch (IOException e) {
        e.printStackTrace();
    }
    image.flush();
}
Tooltip
Make sure to always call document.dispose() when you are done processing a PDF document. Dispose cleans resources used by the document object.



Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

© Copyright 2017 ICEsoft Technologies Canada Corp.