java代码,以突出显示文本的颜色在pdf
问题描述:
我在我的pdf中使用com.lowagie.text
。在生成它时,我需要突出显示几个文本。这是我的代码。我需要代码来突出显示块中的文本。java代码,以突出显示文本的颜色在pdf
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();
答
我得到了上述帖子的解决方案。
columnText.getCanvas().setColorFill(Color.decode("#FFA500"));
columnText.getCanvas().rectangle(llx, ury-(leading) ,columnText.getWidth(phrase) , sizeOftext);
columnText.getCanvas().fill();
columnText.go();
你的文章没有说你的问题实际上是什么。你需要什么帮助? –
上面的代码没有高亮代码,我不知道该把它放在哪里 – Jayanth