I've reached a solution and it works with this sample code:
public prova(String filePath) throws IOException, DocumentException{
                
                Document document = new Document(PageSize.A4);
                File f = new File("C:\\tempPDF_GDF.pdf");
                FileOutputStream fileOutputStream = new FileOutputStream(f);
        PdfWriter writer = PdfWriter.getInstance(document,
fileOutputStream);
        writer.setPageCount(10);
        writer.setBoxSize("page", new Rectangle(36, 54, 559, 788));
        document.open();
                PdfContentByte cb = writer.getDirectContent();

                ColumnText ct = new ColumnText(cb);
                ct.setSimpleColumn(36, 54, 559, 788);
                
                Phrase p, p_r = new Phrase();
                float counter = 36;
                
                System.out.println("Y->"+ct.getYLine()+" - X->"+ct.getLastX());
                
                p = new Phrase("TRIAL TEXT: ", new Font(FontFamily.TIMES_ROMAN, 
14,
Font.NORMAL));
                System.out.println("PhraseWidth->"+ct.getWidth(p));
                counter+=ct.getWidth(p);
                ct.addText(p);
                
                System.out.println("Y->"+ct.getYLine()+" - X->"+ct.getLastX());
                
                p = new Phrase("I use it just to prove if it starts a new line 
in the
event that the text block overflows the line capacity ", new
Font(FontFamily.TIMES_ROMAN, 14, Font.NORMAL));
                System.out.println("PhraseWidth->"+ct.getWidth(p));
                ct.addText(p);

                PdfLayer lay1 = new PdfLayer("entity_highlighting", writer);
        cb.beginLayer(lay1);
        LineSeparator lineSeparator = new LineSeparator();
        lineSeparator.setLineColor(BaseColor.YELLOW);
        lineSeparator.setLineWidth(14);
        lineSeparator.drawLine(cb, counter, 559, 776);
        lineSeparator.drawLine(cb, 36, 188, 760);
//        p_r.add(new Chunk());
//        ct.showTextAligned(cb, 0, p_r, counter, 788, 0);
        cb.endLayer();
                
                System.out.println("Y->"+ct.getYLine()+" - X->"+ct.getLastX());
                
                p = new Phrase("and to check if it highlights text over two 
lines.", new
Font(FontFamily.TIMES_ROMAN, 14, Font.NORMAL));
                System.out.println("PhraseWidth->"+ct.getWidth(p));
                ct.addText(p);

                System.out.println("Y->"+ct.getYLine()+" - X->"+ct.getLastX());
                
                ct.go();
                
                System.out.println("Y->"+ct.getYLine()+" - X->"+ct.getLastX());
                
        document.close();
        }       

...now I have another issue, how can I create a multipage pdf?
I have tried to append a long block of text but in the case that the text
overflows the page's bounds.
The part of text which does't fit is cutted off. How can put this text into
another page?
Once again, thanks a lot!!

--
View this message in context: 
http://itext-general.2136553.n4.nabble.com/highlighting-text-parts-tp4391121p4394892.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
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