0
Chunk amountLabel = new Chunk("Amount: ");
amountLabel.setFont(smallBold);
Chunk amountValue = new Chunk("Rs 25,000/-");
amountValue.setUnderline(0.1f, -2f); //0.1 thick, -2 y-location
amountValue.setFont(small);
Phrase phrase4 = new Phrase();
phrase4.add(amountLabel);
phrase4.add(amountValue);
PdfPCell cell5 = new PdfPCell(phrase4);
cell5.setBorder(Rectangle.NO_BORDER);
cell5.setPadding(padding);
cell5.setHorizontalAlignment(Element.ALIGN_RIGHT);
table.addCell(cell5);

在此,我需要一个方框来表示金额值,同时使用 itext 通过 java 生成 pdf,任何人都可以帮助我

4

1 回答 1

0

You don't want a border for the cell, you only want a border for a specific ´Chunk´. This can be achieved by using a page event, more specifically a generic tag event. Please that a look at movie_years.pdf. Where you see the year a movie was produced, you have a movie strip in the background; where you see IMDB, a blue oval is shown.

Now take a look at the generic tag code. You need to extend the PdfPageEventHelper class and implement the onGenericTag() method. Use the rect parameter to draw a rectangle. Create an instance of your custom page event helper (e.g. event) and declare it to the writer:

writer.setPageEvent(event);

Now set the generic tag for every ´Chunk´ that needs a rectangle. For instance:

amountValue.setGenericTag("some_tag_of_your_choice");

Now whenever such a ´Chunk´ is rendered, the onGenericTag() method will be executed.

于 2013-11-13T08:05:48.660 回答