2016-09-12 1 views
0

자바 프로젝트에서 JDK 1.6.0_35을 사용하고 있으며 속성 파일 (ISO8859-1으로 인코딩 됨)을 복구 할 때 java.util.ResourceBundle에 문제가 있습니다.재스퍼 생성 보고서가 자바에서 키릴 문자 (불가리아어)를 표시하지 않는 이유는 무엇입니까?

영어 라벨이있는 인보이스를 표시해야하지만 불가리아어로 작성해야합니다. 문제는 그것이 불가리아어로 작성되지 않은 텍스트 만 복구하고 표시한다는 것입니다.

\u0424\u0430\u043A\u0442\u0443\u0440\u0430\r\n\u041E\u0440\u0438\u0433\u0438\u043D\u0430\u043B 

"Фактура\r\nОригинал" 

을 나도 그들 중 일 :

나는 두 가지 방법으로 텍스트를 삽입 시도하지했습니다. 나는 인터넷 검색을하고 그것은 첫 번째 방법 (비록 불편하지만, 그것은 작동합니다)과 함께 작동해야하지만,이 같은 텍스트는 내 PDF (나는 Jasperreports를 사용하고)에 표시되지 않습니다 작성된 것 같습니다.

JasperFillManager.fillReport() 내 params 변수에 "INVOICE = INVOICE/XXXФактураXXX"가 포함되어 있지만 PDF를 열 때 "INVOICE/XXX"만 표시됩니다.

자바 코드는 :

Cyrillic comes correctly into Java

fontsfamily1365159936026.xml :

여기
Object obj = JRLoader.loadObject(new InputStream(someSource)); 
JasperReport reportMaster = (JasperReport) obj; 
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(data); 
JasperPrint jasperPrint = JasperFillManager.fillReport(reportMaster, params, ds); 
String pathArialFont = ""; 
String pathArialBFont = ""; 
String pathArialIFont = ""; 
String pathArialBIFont = ""; 
try { 
    pathArialFont = Thread.currentThread().getContextClassLoader().getResource("arial.ttf").toURI() 
     .toString(); 


    pathArialBFont = Thread.currentThread().getContextClassLoader().getResource("arialbd.ttf").toURI() 
     .toString(); 


    pathArialIFont = Thread.currentThread().getContextClassLoader().getResource("ariali.ttf").toURI() 
     .toString(); 


    pathArialBIFont = Thread.currentThread().getContextClassLoader().getResource("arialbi.ttf").toURI() 
     .toString(); 
    LOGGER.debug("pathArialBIFont:".concat(pathArialBIFont)); 

} catch (final URISyntaxException e) { 
    LOGGER.error("", e); 
} 

String arial = "Arial"; 
HashMap<FontKey, PdfFont> fontMap = new HashMap<FontKey, PdfFont>(); 
FontKey key1 = new FontKey(arial, false, false); 
PdfFont font1 = new PdfFont(pathArialFont, BaseFont.CP1252, true); 

FontKey key2 = new FontKey(arial, true, false); 
PdfFont font2 = new PdfFont(pathArialBFont, BaseFont.CP1252, true); 

FontKey key3 = new FontKey(arial, false, true); 
PdfFont font3 = new PdfFont(pathArialIFont, BaseFont.CP1252, true); 
FontKey key4 = new FontKey(arial, true, true); 
PdfFont font4 = new PdfFont(pathArialBIFont, BaseFont.CP1252, true); 

fontMap.put(key1, font1); 
fontMap.put(key2, font2); 
fontMap.put(key3, font3); 
fontMap.put(key4, font4); 

JRPdfExporter exporter = new JRPdfExporter(); 
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); 
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, informe); 
exporter.setParameter(JRExporterParameter.FONT_MAP, fontMap); 

reportMaster.setProperty("net.sf.jasperreports.awt.ignore.missing.font", "true"); 

exporter.exportReport(); 

당신은 문자열이 키릴에서 자바 코드에 도착 나의 debuggings 중 하나로 볼 수있다 :

<?xml version="1.0" encoding="UTF-8"?> 
<fontFamilies> 
    <fontFamily name="Arial"> 
     <normal><![CDATA[fonts/arial.ttf]]></normal> 
     <bold><![CDATA[fonts/arialbd.ttf]]></bold> 
     <italic><![CDATA[fonts/ariali.ttf]]></italic> 
     <boldItalic><![CDATA[fonts/arialbi.ttf]]></boldItalic> 
     <pdfEncoding><![CDATA[Cp1252]]></pdfEncoding> 
     <pdfEmbedded><![CDATA[false]]></pdfEmbedded> 
    </fontFamily> 
</fontFamilies> 

jasperreports_extension.properties :

net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory 
net.sf.jasperreports.extension.simple.font.families.ireportfamily1365159936026=fontsfamily1365159936026.xml 

어떤 단서?

+0

문자 인코딩 시도 UTF-8 –

+3

[font-extensions] (http://stackoverflow.com/documentation/jasper-reports/5773/font-extensions)가 누락되었습니다.이 http : // stackoverflow도 참조하십시오. com/questions/34041619/jasper-reports-pdf-doesnt-export-cyrillic-values ​​ –

+0

지금이 제품을 찾고 있습니다. – madtyn

답변

0

나는 그것을 성취했다. xml에서이 두 줄을 변경해야했습니다.

<pdfEncoding><![CDATA[Identity-H]]></pdfEncoding> 
<pdfEmbedded><![CDATA[true]]></pdfEmbedded> 

Java 코드에서 BaseFont 상수 BaseFont가 변경되었습니다. 이 라인에서 CP1252 :

label=\u0424\u0430\u043A\u0442\u0443\u0440\u0430\r\n\u041E\u0440\u0438\u0433\u0438\u043D\u0430\u043B 

그리고 디자이너 모드에서 나는 "굴림 유니 코드 MS 폰트에 필드를 편집 :

new PdfFont(pathArialFont, BaseFont.IDENTITY_H, true); 

과 같은 파일 내 ISO8859-1 속성에 텍스트를 입력 Pdf Encoding "Identity-H"로 "Pdf embedded"를 체크했다.

관련 문제