Thanx for the late night reply. It was not my intent to make you work on a
Weekend but thanx anyway.
Somehow I overlook the Chunk constructor with an Image as parameter.
Actually I never used Chunk or any basic building block in an application
before since my pdf's are based on existing templates and fill out only
acrofields.
But in this case I had to create a more dynamic pdf containing some pages
with fixed fields and pages with dynamic text which might not fit in one
page only.
Thanx also about the table width, I saw the behaviour of the PdfPTable but
this was something I would deal with on a later time.
Best regards
Yannis Iliadis
2009/4/11 1T3XT info <[email protected]>
> Iliadis Yannis wrote:
>
>> Here are the files I promised to send.
>>
>
> I see two problems:
>
> 1. you set the width of the table, but... that line is ignored:
> table.setTotalWidth(tblWidth);
> You forgot to lock the with:
> table.setLockedWidth(true);
> By adding this line right after setTotalWidth, you'll see that the
> tables now fill the complete area.
>
> It's even easier if you drop these two lines and use:
> table.setWidthPercentage(100);
>
>
> 2. you are using setAbsolutePosition AND you are adding the image to the
> column. You shouldn't do that. I suggest dropping setAbsolutePosition. If
> you do that, the image is aligned with the tables (assuming you fix the
> problem mentioned in 1). If you want to add some indentation, you can
> achieve this for instance by wrapping the image inside a chunk.
>
> I've adapted your example so that you can have a look at it.
> (It adds the logo twice, once aligned with the tables, once indented.)
> --
> This answer is provided by 1T3XT BVBA
> http://www.1t3xt.com/ - http://www.1t3xt.info
>
> import java.io.FileOutputStream;
>
> import com.lowagie.text.Chunk;
> import com.lowagie.text.Element;
> import com.lowagie.text.Image;
> import com.lowagie.text.Paragraph;
> import com.lowagie.text.Rectangle;
> import com.lowagie.text.pdf.AcroFields;
> import com.lowagie.text.pdf.ColumnText;
> import com.lowagie.text.pdf.PdfContentByte;
> import com.lowagie.text.pdf.PdfPCell;
> import com.lowagie.text.pdf.PdfPTable;
> import com.lowagie.text.pdf.PdfReader;
> import com.lowagie.text.pdf.PdfStamper;
>
> public class CreateColumns {
>
> /**
> * @param args
> */
> public static void main(String[] args) {
> try {
> PdfReader reader=new PdfReader("columnText.pdf");
> PdfStamper stamper=new PdfStamper(reader,new
> FileOutputStream("columnTextWithTable2.pdf"));
> AcroFields aFields=reader.getAcroFields();
> PdfContentByte cb=stamper.getOverContent(1);
> int numberOfPages=reader.getNumberOfPages();
>
> float[]
> fieldBounds=aFields.getFieldPositions("form1[0].#subform[0].field[0]");
> System.out.println(fieldBounds[1]+" "+fieldBounds[2]+"
> "+fieldBounds[3]+" "+fieldBounds[4]);
>
> ColumnText ct=new ColumnText(cb);
> ct.setSimpleColumn(fieldBounds[1], fieldBounds[2],
> fieldBounds[3], fieldBounds[4]);
>
> Paragraph p=new Paragraph();
> for (int i = 0; i < 10; i++) {
> PdfPTable table=new PdfPTable(1);
> table.setWidthPercentage(100);
> PdfPCell cell=new PdfPCell();
> p.add(new Chunk(String.valueOf(i)+"\n"));
> cell.addElement(p);
> table.addCell(cell);
> ct.addElement(table);
> ct.addElement(new Chunk(" "));
> ct.go();
> }
>
> Image img=Image.getInstance("mLogo.jpg");
> img.scaleAbsoluteWidth(cm2Pnts(6f));
> img.scaleAbsoluteHeight(cm2Pnts(0.6f));
> //img.setAbsolutePosition(cm2Pnts(2f),
> ct.getYLine()-cm2Pnts(1f));
> ct.addElement(img);
> //cb.addImage(img,cm2Pnts(6f),0,0,cm2Pnts(0.6f),fieldBounds[1],
> ct.getYLine()-cm2Pnts(1f));
>
> Chunk chunk = new Chunk(Image.getInstance("mLogo.jpg"),
> cm2Pnts(2f), 0);
> ct.addElement(chunk);
>
> while (true) {
> int status = ct.go();
> if (!ColumnText.hasMoreText(status))
> break;
> // we run out of column. Let's go to another one
> numberOfPages++;
> stamper.insertPage(numberOfPages,
> reader.getPageSizeWithRotation(1));
> ct.setSimpleColumn(fieldBounds[1], fieldBounds[2],
> fieldBounds[3], fieldBounds[4]);
> ct.setCanvas(stamper.getOverContent(numberOfPages));
> ct.go();
> }
>
> stamper.setFormFlattening(true);
> stamper.close();
> } catch (Exception e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
> public static float cm2Pnts(float cm){
> return (cm*72f)/2.54f;
> }
>
> }
>
>
> ------------------------------------------------------------------------------
> 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
>
------------------------------------------------------------------------------
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