Yet another image question

Help
Anonymous
2010-05-18
2013-04-17
  • Anonymous - 2010-05-18

    Sorry If I am missing something obvious, but I am unable to get am image to render on the page.
    This is what I have so far. This is what I have managed to construct from Google and the javadoc.
    In the DrawInlineImagePlain it has creator.transform() and creator.perform() but the javadoc does no
    help me understand those parts. Thanks.

    PDImage pdImage = (new ImageConverterAwt2Pdf( (BufferedImage)ImageIO.read(new File("Jane.png")))).getPDImage();

    pdImage.setHeight(208);

    pdImage.setWidth(672);

    CSCreator creator = CSCreator.createNew(page);

    creator.doXObject(null,pdImage);

    creator.close();

                    FileLocator locator = new FileLocator("test.pdf");

    doc.save(locator, null);

    doc.close();

    I get a blank PDF.

     
  • Elfi Heck

    Elfi Heck - 2010-05-18

    That should be easy. Your PDF only looks blank because the image is so small. Every image is 1x1 pixels internally in PDF. You need to apply a tranformation before drawing the image. Like this:

    creator.saveState();
    creator.transform(400, 0, 0, 400, 0, 0); // or whatever numbers you need
    creator.doXObject(null, pdImage);
    creator.restoreState();
    
     
  • Anonymous - 2010-05-19

    Thanks a bunch for the fast reply. I really appreciate this.

     
  • Anonymous - 2010-05-19

    I am sorry to ask another question, but I cannot for the life of me figure out how to move the image to a diffrent location. That is te method to do this?
    Thanks agin!

     
  • Elfi Heck

    Elfi Heck - 2010-05-19

    That's also "transform". Read up on the PDF operator "cm" in the spec if you want to know more about that. The javadoc for class java.awt.AffineTransform might help, too. Or any article about geometry transformations.

     

Log in to post a comment.