Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

PDImage position

Help
Leitender
2011-09-07
2013-05-28
  • Leitender
    Leitender
    2011-09-07

    Hello again,

    it is possible to receive the coordinates/position of images (PDImage)?
    When I open the PDF with VIM I don't see coordinates for images (or I can not find them). How does a PDF-Reader know the position of a Image?

     
  • mtraut
    mtraut
    2011-09-08

    The position of an image is the result of interpreting the content stream. The position is derived from the current graphics state transformation at the moment of performing the "doImage" command.

    You can check this by creating a CSVirtualDevice subclass, redfine "doImage" and inspect the graphics state…

    protected void doImage(COSName name, PDImage image) throws CSException {
        CSImageElement element = new CSImageElement(img);
        AffineTransform transform = graphicsState.transform;
        System.out.prinln(transform.getTranslateX());
        System.out.prinln(transform.getTranslateY());
    }
    

    Interpreting a content stream using your device looks like this

    CSContent content = page.getContentStream();
    CSInterpreter interpreter = new CSDeviceBasedInterpreter(new HashMap(), device);
    interpreter.process(content, page.getResources());