简体   繁体   English

Java代码突出显示PDF文本的颜色

[英]java code to highlight the color of text in pdf

I am using com.lowagie.text in my pdf. 我在pdf中使用com.lowagie.text While generating it, I need to highlight a few text.This is the code i have.I need the code for Highlighting text in a chunk. 在生成它时,我需要突出显示一些文本。这是我的代码。我需要用于突出显示文本的代码。

PdfContentByte cb = writer.getDirectContent();
Chunk chunck = new Chunk(arraySpec[k],font);
Phrase phrase = new Phrase(8.0f+ 1);

phrase.add(chunck);

ColumnText columnText = new ColumnText(cb);
columnText.addText(phrase);     

//verify the bounding box size
if (attributeBoundingBoxTextWidth == 0){
    attributeBoundingBoxTextWidth  = (int) boardWidth;
}
float llx = xpos;
float lly = 0;
float urx = llx + width;  

float ury = refYPos - sizeOftext;
refYPos = ury;
float leading = 8.0f+ 1;
columnText.setSimpleColumn(llx, lly, urx, ury, leading, Element.ALIGN_LEFT);
columnText.go();

I got a solution for the above post. 我为上述职位找到了解决方案。

 columnText.getCanvas().setColorFill(Color.decode("#FFA500"));
 columnText.getCanvas().rectangle(llx, ury-(leading) ,columnText.getWidth(phrase) , sizeOftext);
 columnText.getCanvas().fill();      
 columnText.go();  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM