2

I'm facing with character encoding issue while exporting PDF with using iText PDF Library despite I set exporter's CHARACTER_ENCODING property to UTF-8 as I added below :

Class clazz = Class.forName(User.class);
Document document = new Document();
PdfWriter.getInstance(document, baos);
document.open();
addMetaData(document);
addDate(document);
addTitlePage(document, className);
addEmptyLineToDocument(document, 2);
addContent(document, className, clazz);
addEmptyLineToDocument(document, 2);
addSignature(document);
return document;

Here's the addContent method sample:

private static FontFamily fontFamily = FontFamily.TIMES_ROMAN;
Font fontNormal10 = new Font(fontFamily, 10, Font.NORMAL);
Paragraph paragraph = new Paragraph();
Chunk chunk = new Chunk("Here is the list of " + className, fontNormal10);
paragraph.add(chunk);
// continues

Then I write the document with ServletOutputStream :

// **document** => which I created and returned above
document.close();
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "public");
response.setHeader("Content-Disposition", "attachment; filename=" + outputFileName);
response.setContentType("application/pdf; charset=UTF-8");
response.setContentLength(baos.size());
ServletOutputStream outputStream = response.getOutputStream();
baos.writeTo(outputStream); 
outputStream.flush();
outputStream.close();
  • I also added JVM parameter "file.encoding=UTF-8" too..
  • Set response content type with "charset=UTF-8;" property..

Any ideas? Thanks in advance..

Alex K
  • 22,315
  • 19
  • 108
  • 236
talha06
  • 6,206
  • 21
  • 92
  • 147
  • Are you talking about *JasperReports* issue? What is a problem? Did you try to use the [Font Extensions](http://jasperforge.org/uploads/publish/jasperreportswebsite/trunk/sample.reference/fonts/index.html) (if you are talking about JR)? – Alex K Jul 23 '12 at 06:31
  • Actually I have this problem both at JasperReports and also iText. Edited first post.. – talha06 Jul 23 '12 at 11:24
  • @talha06 did u find a solution for this? – Manish Apr 28 '16 at 13:30

0 Answers0