Hi to everybody,

I'm trying to place an image in a ColumnText object using composite mode
(based on the ColumnWithAddElement example) at a specific position but
without any luck.
What I'm actually do is to write some text, that might exceed the page
length and continue to a new page, and at the end to add a stamp plus a
signature both are Images.

The code snippet I'm using is the following:

        PdfReader polReader=new PdfReader(templateURL); //Read a PDF
Template
        int numberOfPages=polReader.getNumberOfPages();

        PdfStamper polStamp = new PdfStamper(polReader,
policyAsOutputStream); //Write to a ByteArrayOutputStream

        PdfContentByte cb=polStamp.getOverContent(1);
        Rectangle pageLayout=polReader.getPageSize(1);

        float[]
fieldBounds=polForm.getFieldPositions("F[0].P3[0].termText[0]"); //A
acroField used as the ColumnText boundaries

        ColumnText ct=new ColumnText(cb);
        ct.setSimpleColumn(fieldBounds[1], fieldBounds[2], fieldBounds[3],
fieldBounds[4]);

        Paragraph p=new Paragraph();

        for(int i = 0; i < 100; i++) {
             p.add(new Phrase("Test document"+i));
                ct.addElement(p);
        }

        float currentY=ct.getYLine();

        Image sfragida=new Image.getInstance(imageUrl1);
        sfragida.scaleToFit(cm2Pnt(2.5f), cm2Pnt(2.5f));
        sfragida.setAbsolutePosition(cm2Pnt(7.5f), currentY-cm2Pnt(3.5f));
        ct.addElement(sfragida);

        Image signature=new Image.getInstance(imageUrl2);
        signature.scaleToFit(cm2Pnt(4.2f), cm2Pnt(2.5f));
        signature.setAbsolutePosition(cm2Pnt(9.6f), currentY-cm2Pnt(4.1f));
        ct.addElement(signature);

        while (true) {
            int status = ct.go();
            if (!ColumnText.hasMoreText(status))
                break;
            // we run out of column. Let's go to another one
            numberOfPages++;
            polStamp.insertPage(numberOfPages,
polReader.getPageSizeWithRotation(3));
            ct.setSimpleColumn(fieldBounds[1], fieldBounds[2],
fieldBounds[3], fieldBounds[4]);
            ct.setCanvas(polStamp.getOverContent(numberOfPages));
            ct.go();
        }

The thing is that the images are place at the left boundary of the
columnText ignoring the position I'm setting to each image.

Additional info: cm2Pnt is just a helper method to convert cm to Points
                      I'm using iText 2.1.5. (same result also in 1.4.8)
with JVM 1.4

Yannis Iliadis
------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

Reply via email to