0

I have a very confusing problem about unicode support in the generated pie chart in my pdf. Here is what I have: I am generating pie chart (with jfreechart library) that need to add superscripts on the title of the pie chart. I tested and I know that jfreechart is generating correct title (superscripts are fine) and I also tested itext unicode support. There is a Graphics2D (from java awt) in between which turns the jfreechart into a template and then I can print this template into my pdf. according my tests I guess problem should be in between graphics2d and itext template.

PdfContentByte canvas = writer.getDirectContent();

PdfTemplate template = canvas.createTemplate(width, height);

FontMapper mapper = new DefaultFontMapper();

template.setFontAndSize(mapper.awtToPdf(new java.awt.Font("Arial Unicode MS", java.awt.Font.PLAIN, 7)) , 7);

Graphics2D graphics2d = template.createGraphics(width, height);

graphics2d.setFont(new java.awt.Font("Arial Unicode MS", java.awt.Font.PLAIN, 7));

JFreeChart chart = getPieChart("", title, value);


I found out the problem. Problem is template (PdfTemplate) does not show the unicode character. Although I embedded unicode fonts and set it for template, still not working. any ideas?

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
pms
  • 944
  • 12
  • 28
  • 1
    Is `"Arial Unicode MS"` accessible to the JVM? What happens if you specify `Font. SANS_SERIF`? – trashgod Mar 29 '13 at 02:25
  • That's a good question. I wrote a test class and tested Arial Unicode Ms and it worked. but that was simple class I am not sure if it is supported when I build the project.and I never tested SANS_SERIF – pms Mar 29 '13 at 16:22

1 Answers1

1

Actually finally I fixed the problem by removing superscript from pie chart and print it directly into template. This also eliminates the use of unicode font (which costs extra money):

template.beginText();

template.setFontAndSize(arial, 8);

// the fixed position of the xy coordinate that I want to print superscript template.moveText(97, 142);

template.showText(superscript);

template.setTextRise(5f);

template.endText();

pms
  • 944
  • 12
  • 28