Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 133737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:29:12+00:00 2026-05-11T06:29:12+00:00

I need to export the pages of an arbitrary PDF document into a series

  • 0

I need to export the pages of an arbitrary PDF document into a series of individual images in jpeg/png/etc format. I need to do this in in Java.

Although I do know about iText, PDFBox and various other java pdf libraries, I am hoping for a pointer to some working example, or some how-to.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:29:12+00:00Added an answer on May 11, 2026 at 6:29 am

    Here is one way to do it, combining some code fragments from around the web.

    How do I draw a PDF into an Image?

    https://pdf-renderer.dev.java.net/examples.html

    Creating a Buffered Image from an Image

    ORIGINAL: http://www.exampledepot.com/egs/java.awt.image/Image2Buf.html

    UPDATED: How to convert buffered image to image and vice-versa?

    Saving a Generated Graphic to a PNG or JPEG File

    ORIGINAL: http://www.exampledepot.com/egs/javax.imageio/Graphic2File.html

    UPDATED: http://docs.oracle.com/javase/tutorial/2d/images/saveimage.html

    Combined together into something that works like this to turn all the pages into images:

    import com.sun.pdfview.PDFFile; import com.sun.pdfview.PDFPage;  import java.awt.Graphics; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.HeadlessException; import java.awt.Image; import java.awt.Rectangle; import java.awt.Transparency; import java.io.*; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import javax.swing.*; import javax.imageio.*; import java.awt.image.*;  public class ImageMain {     public static void setup() throws IOException {         // load a pdf from a byte buffer         File file = new File('test.pdf');         RandomAccessFile raf = new RandomAccessFile(file, 'r');         FileChannel channel = raf.getChannel();         ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());         PDFFile pdffile = new PDFFile(buf);         int numPgs = pdffile.getNumPages();         for (int i = 0; i < numPgs; i++) {             // draw the first page to an image             PDFPage page = pdffile.getPage(i);             // get the width and height for the doc at the default zoom             Rectangle rect = new Rectangle(0, 0, (int) page.getBBox().getWidth(), (int) page.getBBox().getHeight());             // generate the image             Image img = page.getImage(rect.width, rect.height, // width & height                     rect, // clip rect                     null, // null for the ImageObserver                     true, // fill background with white                     true // block until drawing is done                     );             // save it as a file             BufferedImage bImg = toBufferedImage(img);             File yourImageFile = new File('page_' + i + '.png');             ImageIO.write(bImg, 'png', yourImageFile);         }     }      // This method returns a buffered image with the contents of an image     public static BufferedImage toBufferedImage(Image image) {         if (image instanceof BufferedImage) {             return (BufferedImage) image;         }         // This code ensures that all the pixels in the image are loaded         image = new ImageIcon(image).getImage();         // Determine if the image has transparent pixels; for this method's         // implementation, see e661 Determining If an Image Has Transparent         // Pixels         boolean hasAlpha = hasAlpha(image);         // Create a buffered image with a format that's compatible with the         // screen         BufferedImage bimage = null;         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();         try {             // Determine the type of transparency of the new buffered image             int transparency = Transparency.OPAQUE;             if (hasAlpha) {                 transparency = Transparency.BITMASK;             }             // Create the buffered image             GraphicsDevice gs = ge.getDefaultScreenDevice();             GraphicsConfiguration gc = gs.getDefaultConfiguration();             bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency);         } catch (HeadlessException e) {             // The system does not have a screen         }         if (bimage == null) {             // Create a buffered image using the default color model             int type = BufferedImage.TYPE_INT_RGB;             if (hasAlpha) {                 type = BufferedImage.TYPE_INT_ARGB;             }             bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);         }         // Copy image to buffered image         Graphics g = bimage.createGraphics();         // Paint the image onto the buffered image         g.drawImage(image, 0, 0, null);         g.dispose();         return bimage;     }      public static boolean hasAlpha(Image image) {         // If buffered image, the color model is readily available         if (image instanceof BufferedImage) {             BufferedImage bimage = (BufferedImage) image;             return bimage.getColorModel().hasAlpha();         }         // Use a pixel grabber to retrieve the image's color model;         // grabbing a single pixel is usually sufficient         PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);         try {             pg.grabPixels();         } catch (InterruptedException e) {         }         // Get the image's color model         ColorModel cm = pg.getColorModel();         return cm.hasAlpha();     }      public static void main(final String[] args) {         SwingUtilities.invokeLater(new Runnable() {             public void run() {                 try {                     ImageMain.setup();                 } catch (IOException ex) {                     ex.printStackTrace();                 }             }         });     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to be able to export PDF's that I am creating to JPEG,
i need to export a pages to pdf, the pages will have grids on
I need to export my nodes like this: function recursive_simplify(node){ if(node.children){ for(var i =0;i<node.children.length;i++){
I need a datepicker widget via ExtJs on my pages that works like this
I need to generate a ms-word document from a pl/sql query to export a
I need to export an HTML page with some charts in to a PDF,
I need to export the sheet 'GreatIdea' to a Word document. 'GreatIdea' is divided
I need to copy a menu from this wordpress installation http://bit.ly/rrWFMH into some non-wordpress
So, I have a need to export large-format paper sizes (33 x 44 inches)
In a web page button click event we need to export 2,00,000 to 5,00,000

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.