UTF-8 encoding characters not working with Spring

2019-08-17 02:14发布

问题:

In my spring's controller method , i am using lowagie api (2.1.7) to generate pdf. Expecting output after pdf generation is "Swapnil Shirke 병준 주 Тимофій Чепурний" instead of "Swapnil Shirke". special characters are not display in pdf.

UTF-8 encoding characters not working

String graphInfo =
 "<div style="" align="left">on: 09/14/2017<br/>Report generated by: Swapnil Shirke Тимофій Чепурний 병준 주<br/><br/>cd: kkEBM<br/>bbdre: EjydeBM<br/></div><br/><div align="center" style="font-size:14px;">test</div><br/> ";

String tblHtml="<tr><td>Swapnil Shirke Тимофій Чепурний 병준 주</td></tr>";

response.addHeader("Content-Type", "application/pdf; charset=UTF-8");
Document document = new Document();
document.setPageSize(PageSize.A3);
pdfWriter = PdfWriter.getInstance(document, response.getOutputStream());
document.open();
HTMLWorker htmlWorker = new HTMLWorker(document);
htmlWorker.parse(new StringReader(graphInfo.toString()));
htmlWorker.parse(new StringReader("<br/>" + tblHtml));
document.close();