One of my colleagues had some problems with a PDF document generated using iText, as she didn't know how to have different fonts in the same PdfPTable cell. The code was something like this:
table.addCell("fixed normal test: " + variableToBeRenderedInBold + " " + anotherVariableToBeRenderedInBold);
It was quite simple to modify it: you can use another signature of the same method which accept a Phrase as a parameter and build the Phrase with different Chunks:
Chunk ch1 = new Chunk("chunk 1 ");
Chunk ch2 = new Chunk("(bold) chunk 2 ", FontFactory.getFont(FontFactory.HELVETICA, 11, Font.BOLD));
Chunk ch3 = new Chunk("chunk 3 ");
Phrase phrase = new Phrase();
phrase.add(ch1);
phrase.add(ch2);
phrase.add(ch3);
That's a starting point, you can decide to refactor as much as you like but that's "the simplest thing that could possibily work". The first refactor could be the elimination of duplicate code that occurs when you have to build another Phrase with normal and bold fonts, but I'll leave that to you.
Meno scroll, più risparmio in bolletta
1 week ago