Hello dear subscribers of the itext mailing list :-),

At first: my knowledge with frameworks like iText which you can use for pdf creation isn't the best. I'm still learning and for a moment can't get any further. Saying this, I am sorry if this question seems too easy for someone, I just couldn't find any answer so far.

I am using iText because I need a framework with which I can create pdf-files in java and (important!) place text at certain x and y coordinates. This text also needs a background color since I'm doing analysis on them. After a lot of research I experienced that I can realize this with iText.

Here is a small example of what I am doing (I read the rules :-) ). You can simply copy it as long as you have the iText jar added to your build path.

|import  java.io.FileOutputStream;

import  com.itextpdf.text.Document;
import  com.itextpdf.text.pdf.BaseFont;
import  com.itextpdf.text.pdf.PdfContentByte;
import  com.itextpdf.text.pdf.PdfWriter;

public  class  PDFTesting  {

public  static  void  main(String[]  args)  {
    Document  document=  new  Document();
    try  {
        PdfWriter  writer=  PdfWriter.getInstance(document,
                new  FileOutputStream("output.pdf"));
        document.open();
        PdfContentByte  cb=  writer.getDirectContent();

int x= 100; int y= 500; String text= "Hello";
        // now we can place content elements on the page
        BaseFont  bf=  BaseFont.createFont(BaseFont.HELVETICA,  
BaseFont.CP1252,  BaseFont.NOT_EMBEDDED);
        cb.saveState();
        cb.beginText();
        cb.moveText(x,  y);
        cb.setFontAndSize(bf,  12);
        cb.showText(text);
        cb.endText();
        cb.restoreState();

    }  catch  (Exception  e)  {
    }

    document.close();
}
}

I have added possibilities to add my text from my datasources to this method 
and it's really working great. The result looks very promising to me and so is 
only one task for me left at the moment:

I need to add specfic background colors to my text (not font color!) that I'm 
moving and placing in the method shown above.

My research didn't provide me any beginner-friendly information about this task 
so I would be really happy if you could help me solve this. I also read 
something during my research that it could be possible to (somehow) create a 
rectangle and write the text above it.

If possible: can you modify my example in a way that adds a background color to 
the added example-text (so at the same coordinates)?

If you need further information or have additional suggestions for me please 
feel free to contact me as well.

Thanks for every answer and thought you're sharing with me. Hopefully this 
isn't too much beginner style for you guys :-)

Best Regards
|


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to