Binary conversion of a big image leads to "java.lang.OutOfMemoryError"?

Hi,
My program loads a black and white 1 bit depth image of around 20 - 30mb. When I try to convert it to binary image, it gives the following error: java.lang.OutOfMemoryError: Java heap spaceI am converting a bufferedimage to binaryimage. I used the following conversion method:      
// This method converts an image to a binary image:
     public static BufferedImage convert (BufferedImage src, int type)
          int w = src.getWidth ();
          int h = src.getHeight ();
          BufferedImage dst = new BufferedImage (w, h, type);
        Graphics2D g = dst.createGraphics ();
        g.drawRenderedImage (src, null);
        g.dispose ();
          return dst;
     }The program was working well before but now it keeps giving the heap memory error which is really weird. Is there any way I can fix this? Can anybody suggest a better way to convert a black and white image to binary data. Thanks.

You could increase maximum memory (-Xmx): [http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html]

Similar Messages

  • Large images --java.lang.OutOfMemoryError browser

    Hello,
    i am loading a tif file of 174MB into an signed applet.Problem is its not loading very large images in browser,but works fine in appletviewer(1 min) bcus(if i am correct) appletviewer use more JVM memory and i think browsers JVM use 16mb(whihc is not sufficient for loading large images) ,but i increased memory,still its not loading.Anybody has any solution for this,please help me
    thanks
    hithesh

    Hi Everyone.
    i forced my java console which is used by both IE and NN to use 256m
    like -Xmx256m.now its loading large images of 175MB.
    but any of u guys know how to force it in applet code,so that user who is using my applet doesnt have to bother about doing it?
    thanks
    Hithesh Gazzala

  • Big ANE causes java.lang.OutOfMemoryError when packaging Air application

    Hi,
    I'm working on an Air mobile game that uses ANE on iOS and Android. I'm in the process of creating a new ANE and face a problem on the Android side.
    My ANE requires an external framework (Burstly, http://burstly.com). If I just link the Android project to Burstly's .jar file, I get errors in "adb logcat", like:
    I/dalvikvm(16074): Could not find method com.burstly.lib.BurstlySdk.init, referenced from method com.freshplanet.burstly.functions.InitBurstlyFunction.call
    In order to include Burstly's files in my own .jar, I unzip Burstly's .jar file and repackage them with my compiled code in a unique .jar (following advice on http://stackoverflow.com/questions/7732742/air-3-native-extensions-for-android-can-i-how-t o-include-3rd-party-libraries).
    Problem: Burstly's SDK includes thousands of files. It doesn't create any trouble when packaging the ANE, but when I try to package the Air application, I get the following error:
    dx tool failed:
    UNEXPECTED TOP-LEVEL ERROR:
    java.lang.OutOfMemoryError: Java heap space
              at com.android.dx.util.IntList.<init>(IntList.java:87)
              at com.android.dx.rop.code.RopMethod.calcPredecessors(RopMethod.java:174)
              at com.android.dx.rop.code.RopMethod.labelToPredecessors(RopMethod.java:95)
              at com.android.dx.ssa.back.IdenticalBlockCombiner.process(IdenticalBlockCombiner.java:74)
              at com.android.dx.ssa.back.SsaToRop.convert(SsaToRop.java:132)
              at com.android.dx.ssa.back.SsaToRop.convertToRopMethod(SsaToRop.java:76)
              at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:103)
              at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:74)
              at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:269)
              at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:131)
              at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:85)
              at com.android.dx.command.dexer.Main.processClass(Main.java:299)
              at com.android.dx.command.dexer.Main.processFileBytes(Main.java:278)
              at com.android.dx.command.dexer.Main.access$100(Main.java:56)
              at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:229)
              at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:244)
              at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:130)
              at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:108)
              at com.android.dx.command.dexer.Main.processOne(Main.java:247)
              at com.android.dx.command.dexer.Main.processAllFiles(Main.java:183)
              at com.android.dx.command.dexer.Main.run(Main.java:139)
              at com.android.dx.command.dexer.Main.main(Main.java:120)
              at com.android.dx.command.Main.main(Main.java:89)
    I read that the solution to eliminate this error is to give Java the parameters "-Xms...M -Xmx...M", with "..." being a high-enough number. Note that I'm working on a machine with 8GB of RAM. I tried to package the app in command line to be able to pass these parameters:
    /usr/bin/java -Xms512M -Xmx4096M -jar "/Applications/Adobe Flash Builder 4.6/sdks/4.6.0air31/lib/adt.jar" -package -target apk -storetype pkcs12 -keystore [...].p12 Main.apk Main-app.xml Main.swf -extdir "/Users/alex/Documents/Adobe Flash Builder 4.6/.metadata/.plugins/com.adobe.flexbuilder.project.ui/ANEFiles/front-end-mobile/com.ado be.flexide.multiplatform.ios.platform"
    But when I run a "ps -ef | grep java", I can see that adt runs another Java program (dx) without transmitting my -Xms -Xmx parameters:
    /usr/bin/java -jar /Applications/Adobe Flash Builder 4.6/sdks/4.6.0air31/lib/android/bin/dx.jar --dex --output=/private/var/folders/t9/3kw74cx14nv2xg9tgmx9m1jc0000gp/T/b5757d93-1e93-439c-8f6d -c93e4933f6f1/outputDEX.dex [... bunch of jars]
    Any idea to solve this issue?
    Thanks
    Alex

    I solved my issue by setting the _JAVA_OPTIONS environment variable. (Note: there are two underscores)
    I added the following line to my .bash_profile:
    export _JAVA_OPTIONS="-Xms1024m -Xmx4096m -XX:MaxPermSize=512m"
    Now everytime a Java program is launched from the command line, I see the following message:
    Picked up _JAVA_OPTIONS: -Xms1024m -Xmx4096m -XX:MaxPermSize=512m
    And my application packaging runs just fine now.
    I still have an issue though: this trick solved the problem for packaging the app from the command line, but the _JAVA_OPTIONS are not picked up when packaging from Flash Builder, so it still crashes there.
    Note that my Adobe Flash Builder 4.6.ini contains the following options:
    -Xms512m
    -Xmx1676m
    -XX:MaxPermSize=512m
    -XX:PermSize=64m
    1676m is the highest number I can put before Flash Builder refuses to launch. I'm not sure if these parameters are actually passed to the VM that runs de dx.jar program, or if it's just for the ActionScript compiler. But anyway my app packaging still crashes in Flash Builder.
    If someone knows a way to force Flash Builder to pickup the _JAVA_OPTIONS set in the command line, let me know :-)
    Thanks
    Alex

  • Printing big Image throws OutOfMemoryError

    Hello,
    I am new to "Java Printing", this is my first attempt to print somthing in Java, I am trying to print several JTextPanes and a big PNG image as a background for them. Sometimes everything work fine, but sometimes it throws java.lang.OutOfMemoryError, full message is: Exception in thread "Image Fetcher 0" java.lang.OutOfMemoryError: Java heap space. I use JDK 1.5_06.
    I use the following code to print Image and JTextPanes:
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    printerJob.setPrintService(servicesName);
    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
    pras.add(new PrinterResolution(200, 200, ResolutionSyntax.DPI));
    PageFormat pf = printerJob.defaultPage();
    Paper paper = pf.getPaper();
    paper.setSize(1654D,2339D);//A4 page size with 200 DPI
    paper.setImageableArea(0D,0D,1654D,2339D);
    pf.setPaper(paper);
    printerJob.setPrintable(documentPanel, pf);
    printerJob.print(pras);documentPanel is instance of class DocumentPanel:
    /*Panel that contains my JTextPanes */
    public class DocumentPanel extends JPanel implements Printable{
    /*overriden method print*/
    public int print(Graphics g, PageFormat pf, int index) throws PrinterException {
            if (index > 0) { /* We have only one page, and 'page' is zero-based */
                    return NO_SUCH_PAGE;
                Graphics2D g2d = (Graphics2D) g;
                g2d.translate(leftMargin, topMargin);
                //draw the background image
                g2d.drawImage(iipmt().getImage(),0,0,null);
                g2d.scale(1.667D, 1.667D); /*this is to make children  JTextPanes bigger.
                As I see after printing  this line doesn�t affect size of image, which is set above.*/
                /* Now print all children - JTextPanes without parent*/
                this.printChildren(g2d);
                /* tell the caller that this page is part of the printed document */
                return PAGE_EXISTS;
    static ImageIcon iipmt(){
             return  new ImageIcon("image.png");
    } If I change image to another one with smaller size and use 72 DPI instead of 200 my program always work fine. Also it seams that extending java heap space with -Xmx256 can solve this problem (I don't know exactly because error doesn't repeat always and I can�t determine some special conditions for this error).
    I don�t want to extend heap space and I think it is not necessary for printing images, so I would like to know, is there better way to print Images mixed with Swing components? Or what mistakes did I make?

    A printer setting of 600 dpi doesn't mean 600 pixels per inch. It's a relative quantity of how much ink you want the printer to use to faithfully reproduce the pixels on the page. So for example, you start to achieve photo quality around 250 pixels per inch, but would need to set the printer to 1200+ dpi if you ever hope for it to print out correctly. Trying to achieve 600 pixels per inch would be suicide for your printer.
    That being said, you're not actually doing anything with this dpi or ppi stuff. In your code you're ultimately just drawing the image, scaled to the page's size using nearest neighbor interpolation, and printing it at 72 pixels per inch. In the code you commented out, you have the interpolation fine but miss the mark on the scaling. Specifically, you scale the graphics correctly, but then two lines later you set the transform to something else.
    Try this:
    double scale = 72/...;  //be reasonable, 600 won't work, 72 pixels-per-inch may be just fine
    Graphics2D g2d = (Graphics2D) printerGraphics;
    g2d.scale(scale,scale);
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                         RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2d.drawImage(image,xMargin,yMargin,
            (int) Math.floor(pageFormat.getWidth()/scale),
            (int) Math.floor(pageFormat.getHeight()/scale),null); This should (in theory) scale the image to the page's size using bicubic interpolation, and print it at what ever pixels-per-inch you specify. The crappy output you were getting could of been the nearest neighbor interpolation, the 72 ppi, or some combination of both.

  • How to getPixels of a big image

    Hello,
    How to getPixels of a big image?
    for(int i = 0; i < planarImage.getHeight();i++) {
        planarImage.getData().getPixel(0,i,tab);
    }This code works for a small image 1728 x 2592 but when we load an big image (7000x10000):
    java.lang.OutOfMemoryError: Java heap space
    Dumping heap to /Users/pierre/NetBeansProjects/projetTER/nbproject/private/profiler/java_pid486.hprof ...
    Heap dump file created [12872497 bytes in 0.133 secs]
    Exception in thread "Thread-15" java.lang.OutOfMemoryError: Java heap space
            at java.awt.image.DataBufferByte.<init>(DataBufferByte.java:59)
            at java.awt.image.ComponentSampleModel.createDataBuffer(ComponentSampleModel.java:397)
            at javax.media.jai.RecyclingTileFactory.createTile(RecyclingTileFactory.java:397)
            at javax.media.jai.PlanarImage.createWritableRaster(PlanarImage.java:1995)
            at javax.media.jai.PlanarImage.getData(PlanarImage.java:2173)
            at javax.media.jai.PlanarImage.getData(PlanarImage.java:2029)
            at javax.media.jai.RenderedOp.getData(RenderedOp.java:2277)
            at jai.scale.RenderableScale$2.run(RenderableScale.java:175)
            at java.lang.Thread.run(Thread.java:637)Can I load a part of image?
    Thanks.

    You should check out tiling, if the image is tiled it doesnt need to be in memory all at once.
    Of course you probably need to set the heapsize to a reasonable value eg
    -Xmx256m
    I would suggest about half your main memory.

  • Java.lang.Outof Memory Exception for Image

    Hi
    I am having an applet which displays some tiff image. when i am trying to print that image , iam getting OutOf Memory exception ....
    I increased heap size by setting the environment variable...
    i.e Variable : JAVA_OPTS
    Value : -Xms128m -Xmx 512m
    Even though i increased the heap size, i am getting the same exception...
    Can any body solve it ....
    Exception is :..........
    Java.lang.OutOfMemoryError
    Thanks

    Hello,
    I have the same pb... (see "TIFF : how to read with tiles")
    I just know that we have to divide the tiff into a grid of "tiles".
    By playing with tiles, images are processed gradually instead of being entirely stored in the memory.
    But I don't know how to do...

  • Binary Conversion of file in Emigall(why)

    Can any one tell me what is the purpose of converting the file to binary before loading through EMIGALL?Why is it necessary?I have checked the file On application server in the directory where file after binary conversion is placed.I was expecting it to be in binary format i mean combination of 0's and 1's.But it was not.So can anyone please elaborate.
    Thanks

    Hi Arya
    Very strange question.
    There's only one valid file format for the EMIGALL upload files at the moment, so obviously the file has to match that particular format.
    Not absolutely sure why we chose this file format instead of a delimited TXT file (it was a very long time ago), two things spring to mind:
    Inclusion of "special" characters in the content, that could also be used as column delimiter, without compromising the file layout
    Incorrect file layout, like missing or additional columns compared to the EMIGALL customising, easier to identify and more likely to fail
    Please note, I don't want to start a discussion here why one format is better than another. Simply accept it, it's not a big deal and move on.
    I am certain your file is in binary format, you only use the wrong editor to display the file
    Yep
    Jürgen

  • How convert a big image to parts of images? means split a jpg image to several sub imges.(thi​s sub image can joint into that big image)

    hi friends..
    how convert a big image to parts of images? means split a jpg image to several sub imges.(this sub images can joint into that big image) any help
    Solved!
    Go to Solution.

    In the example, i have created two images and added them together, and the converse can be done in the same way.
    Thanks
    uday,
    Please Mark the solution as accepted if your problem is solved and help author by clicking on kudoes
    Certified LabVIEW Associate Developer (CLAD) Using LV13

  • Safari 7.0 does not loading big image.

    Hi. I have Mac book pro (13-inch Early 2013).
    I'm Korean. and my english level is very terrible.
    but, My MacBook has some problem.
    My Mac installed OSX10.9. and safari ver is 7.0.
    If loading big image, safari is show black box.
    But other brower is show image.
    thanks for reading, my broken text.

    Please read this whole message before doing anything.
    This procedure is a test, not a solution. Don’t be disappointed when you find that nothing has changed after you complete it.
    Step 1
    The purpose of this step is to determine whether the problem is localized to your user account.
    Enable guest logins* and log in as Guest. Don't use the Safari-only “Guest User” login created by “Find My Mac.”
    While logged in as Guest, you won’t have access to any of your personal files or settings. Applications will behave as if you were running them for the first time. Don’t be alarmed by this; it’s normal. If you need any passwords or other personal data in order to complete the test, memorize, print, or write them down before you begin.
    Test while logged in as Guest. Same problem?
    After testing, log out of the guest account and, in your own account, disable it if you wish. Any files you created in the guest account will be deleted automatically when you log out of it.
    *Note: If you’ve activated “Find My Mac” or FileVault, then you can’t enable the Guest account. The “Guest User” login created by “Find My Mac” is not the same. Create a new account in which to test, and delete it, including its home folder, after testing.
    Step 2
    The purpose of this step is to determine whether the problem is caused by third-party system modifications that load automatically at startup or login, by a peripheral device, by a font conflict, or by corruption of the file system or of certain system caches.
    Disconnect all wired peripherals except those needed for the test, and remove all aftermarket expansion cards. Boot insafe mode and log in to the account with the problem. Note: If FileVault is enabled on some models, or if a firmware password is set, or if the boot volume is a software RAID, you can’t do this. Ask for further instructions.
    Safe mode is much slower to boot and run than normal, and some things won’t work at all, including sound output and Wi-Fi on certain models.  The next normal boot may also be somewhat slow.
    The login screen appears even if you usually log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin.
    Test while in safe mode. Same problem?
    After testing, reboot as usual (i.e., not in safe mode) and verify that you still have the problem. Post the results of steps 1 and 2.

  • Error "Failed to Export PDF" with big image on CS6 (32) and CC (64)

    Hi everyone,
    I'm on indesign CS6 (v8.0.2) and when I try to export pdf with a very big image ( *.tiff, 25000*35000 pixels, ) , the action failed with this message :" Failed to export a PDF".
    To be sure that there is no any corrupted elements, I made a very simple layout (one page , and just one element for my image,I turnoff prefilgth and all  ressource intensive options, and export with no downsampling or resampling) and try to export with different size image:with 20000*30000 -or smaller -image the export works, always failed with image .The export failed to in scripting mode.
    If I diveded my image in four , the export works but this solution is not convenient (I actually made tests for a fully automatised process, and we want to be sure that the indesign  component is  enough "safe")
    I try the same action with an evaluation version of indesign CC 64 bits (v9.2) and have the same behavior.
    I can imagine that there is a memory issue there, but my config seems to be strong ( windows server 64 with  16GB ram, DD with more than 100GB free). I don't undersant why-in a "full" 64 bit environnement- it is not possible to manipulate and export very large image ?
    I'm wonder If the background task is a part of the problem, and if it 's possible to disable it in CS6 or CC as in cs5 ( creates an  “DisableAsyncExports.txt” file in  Adobe InDesign executable directoty don't seems to disable it  in CC or CS6).
    Thank you for your help and good ideas..
    DC.

    this is a .tif (not a "big"tiff) compressed in LZW or ZIP.
    I just tried with another format (png), the error is the same...

  • Converting a binary string into a JPEG image in Crystal Reports 2008

    Hi Gang
    Iu2019m having problems converting a binary string into an image in Crystal Reports 2008
    I have JPEG images stored in ECC.  ECC stores the data in binary format.
    Iu2019m using the ECC function module SKWF_PHIO_CONTENT_ACCESS_GET to retrieve the data.  This function module has an export table, FILE_CONTENT_BINARY, which returns several lines of data.  Each line contains a maximum of 1,024 characters.
    When I drop the T_ FILE_CONTENT_BINARY.LINE field into my Crystal Report detail section, I wind up with a report that displays all the lines in FILE_CONTENT_BINARY table.  (in my case, 19 lines are displayed.)
    I created a formula to collect all the data into a single string.
    whileprintingrecords;
    stringvar data:= data & {SKWF_PHIO_CONTENT_ACCESS_GET.T_FILE_CONTENT_BINARY.LINE}
    I added the formula to the detail section and itu2019s doing a great job collecting the data.
    I then inserted a picture object in the report footer, opened the format editor, navigated to the u201Cpictureu201D tab, and inserted a formula for the u201Cgraphics locationu201D.
    whileprintingrecords;
    stringvar data:=data;
    data
    My clever idea turned out to be a disappointment . . . . my picture object is blank.
    Does anyone have a solution for converting a binary string into a JPEG image?

    Save the JPEG in a format CR supports. Refer to the help file for the file types.

  • My Lightroom CC always crash when it is trying to upload the preview of big images

    My Lightroom CC always crash when it is trying to upload the preview of big images like photo merge images from 3 or 4 RAW images together. Thank You. Marco

    When Lightroom first displays the image, it shows the JPG preview which includes your camera custom white balance settings. (This is probably also what you see in Finder)Then a few seconds later it renders the RAW image, with none of the JPG editing and with none of your camera settings applied. That is what you see in Lightroom.
    There is no way to turn this off.
    You then need to apply your own Lightroom edits to this RAW image to make it look pleasing.

  • How can i put one small image on another big image at particular point

    Hi,
    I have combined two images but new mask image is totally overwrite and come in whitecolored not in original color.....
    I have user CGImageMaskCreate, CGImageCreateWithMask......
    But i want to put small image on big image at particular point...... that i m tired to search but i can't find.......
    Any thing is remaining then pls tell me...
    Thanks,
    Haresh.

    Check the Quartz2D documents on Apple's site. Do a search in your examples folder in the developer folder and on Apple's site for Masks. I haven't used them under this API but that's probably the best place to start.

  • How to load big images in Java?

    Hello all,
    is there any possibility to load a big images about 200-500 Mb with Java Graphics API ?
    This code throws OutOfMemory Exception.
            try {
                BufferedImage img = ImageIO.read(new File("testpic1.bmp"));
                int w = img.getWidth(null);
                int h = img.getHeight(null);
                bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
                Graphics g = bi.getGraphics();
                g.drawImage(img, 0, 0, null);
            } catch (IOException e) {
                System.out.println("Image could not be read");
                System.exit(1);
      protected void paintComponent(Graphics g) {
       g2D.drawImage(bi, null, 0, 0);
      }I can't extend memory for the JVM because of my requirement. So I have to load a picture partly as user access to it.
    I am very thankful for every idea.

    I try to read an image like this:
    The size of the image is 10000x4000
    How can I read from Buffer 6000-5700 = 300 for width and 3000-2700 = 300 for heigth?
    If I do it like that
    bi = new BufferedImage(6000, 3000, BufferedImage.TYPE_INT_ARGB);
    I read more, than I need.
    Is there somthing like
    bi = new BufferedImage(5700, 2700, 6000, 3000, BufferedImage.TYPE_INT_ARGB);
    ??

  • Serverside conversion of PDF to Image (JPEG, GIF, PNG)

    Hello JDCers.....
    I am currently looking for a serverside component (or some info on how to build one).... that will allow on the fly conversion of pdf to an image format on my web server...
    Any help would be greatly appreciated....
    Thanks
    Fahim

    here is some code that does the trick...
    import java.awt.Graphics2D;
    import java.awt.RenderingHints;
    import java.awt.image.BufferedImage;
    import java.awt.image.RenderedImage;
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.File;
    import java.util.Vector;
    import javax.imageio.ImageIO;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletResponse;
    import com.sun.media.jai.codec.ImageCodec;
    import com.sun.media.jai.codec.ImageDecoder;
    import com.sun.media.jai.codec.ImageEncoder;
    import com.sun.media.jai.codec.PNGEncodeParam;
    import com.sun.media.jai.codec.SeekableStream;
    import com.sun.media.jai.codec.TIFFDecodeParam;
    import com.sun.media.jai.codec.TIFFDirectory;
    import multivalent.Behavior;
    import multivalent.Context;
    import multivalent.Document;
    import multivalent.Node;
    import multivalent.std.adaptor.pdf.PDF;
    public class PDFToPNG extends HttpServlet {
         private static final long serialVersionUID = 1L;
         public byte[] ConvertToPngImage(byte[] tiffRawData, HttpServletResponse res)
                   throws Exception {
              Vector pngs = new Vector();
              // set stream to the tiff url
              SeekableStream tiffStream = SeekableStream.wrapInputStream(
                        new ByteArrayInputStream(tiffRawData), true);
              // how many pages in one tiff
              int pageNumber = TIFFDirectory.getNumDirectories(tiffStream);
              TIFFDecodeParam decodeParam = new TIFFDecodeParam();
              decodeParam.setDecodePaletteAsShorts(true);
              ImageDecoder tiffDecoder = ImageCodec.createImageDecoder("tiff",
                        tiffStream, decodeParam);
              // for (int p = 0; p < pageNumber; p ++) {
              // render the current page
              RenderedImage tiffPage = tiffDecoder.decodeAsRenderedImage();
              PNGEncodeParam png = PNGEncodeParam.getDefaultEncodeParam(tiffPage);
              // The png stream is outputted to a file. Change the directory
              // accordingly.
              ByteArrayOutputStream baos = new ByteArrayOutputStream();
              // Gets a PNG encoder.
              ImageEncoder pngEncoder = ImageCodec.createImageEncoder("PNG", baos,png);
              // Encodes the RenderedImage object.
              pngEncoder.encode(tiffPage);
              byte[] content = baos.toByteArray();
              baos.close();
              return content;
         public static void main(String args[]) {
              File outfile = new File("c:\\file.png");
              try {
                   PDF pdf = (PDF) Behavior.getInstance("AdobePDF", "AdobePDF", null,
                             null, null);
                   File file = new File("c:\\somepdf.pdf");
                   pdf.setInput(file);
                   Document doc = new Document("doc", null, null);
                   pdf.parse(doc);
                   doc.clear();
                   doc.putAttr(Document.ATTR_PAGE, Integer.toString(1));
                   pdf.parse(doc);
                   Node top = doc.childAt(0);
                   doc.formatBeforeAfter(200, 200, null);
                   int w = top.bbox.width;
                   int h = top.bbox.height;
                   BufferedImage img = new BufferedImage(w, h,
                             BufferedImage.TYPE_INT_RGB);
                   Graphics2D g = img.createGraphics();
                   g.setClip(0, 0, w, h);
                   g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                             RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
                   g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);
                   g.setRenderingHint(RenderingHints.KEY_RENDERING,
                             RenderingHints.VALUE_RENDER_QUALITY);
                   Context cx = doc.getStyleSheet().getContext(g, null);
                   top.paintBeforeAfter(g.getClipBounds(), cx);
                   ImageIO.write(img, "png", outfile);
                   doc.removeAllChildren();
                   cx.reset();
                   g.dispose();
                   pdf.getReader().close();
                   outfile = null;
                   doc = null;
              } catch (Exception e) {
    }

Maybe you are looking for

  • Example: JDBC Callable Produre for Stored SQL in MS Access

    I searched the net to find how this works. Firing a select and getting a resultset. I found certain pointers but couldn't find a complete solution. Although this would seem as not necessary but could be needed by a student or someone working with Acc

  • Display turning off?

    hi the screen on my ibook just seems to randomly switch off. the computer will still be operating but the screen just stops working. sometimes after extended sleep the screen will flash then just be black. sometimes i can be working and it will just

  • How to bypass FORALL in SELECT .. BULK COLLECT

    Using Oracle 8.1.7 I developed a stored procedure LOT TYPE TIds IS Table of Integer; TYPE TFloats IS Table of Float; procedure LOT(Ids TIds) .... is Prices TFloats; Quantities TFloats; begin for I in 1..Ids.Count loop SELECT ... BULK COLLECT INTO Pri

  • Skype number payment taken three times and only wa...

    I have purchased a Skype number recently but on my account it shows three transactions for my Skype order but I only want one help please thanks guys and gals

  • SQL Query Question

    Hi, I am trying to filter my output from the query based on some conditions but not able to figure out how. May be I am just overlooking at the issue or is it something tricky. So, I have a query returning 4 rows of output out of which I need to filt