Itext 5.5 & XMLWorker のアラビア語テキストを含む HTML 文字列を変換しようとしています。変換後、アラビア文字は空白で表示されます。
使用されるコード スニペットは次のとおりです。
public class CreateArabic {
public static void main(String args[]) {
try {
Rectangle pagesize = new Rectangle(8.5f * 72, 11 * 72);
Document document = new Document(pagesize, 72, 72, 72, 72);
PdfWriter writer = PdfWriter.getInstance(document,
new FileOutputStream("c:\\report.pdf"));
writer.getAcroForm().setNeedAppearances(true);
document.open();
FontFactory.registerDirectories();
Font font = FontFactory.getFont("C:\\damase.ttf",
BaseFont.IDENTITY_H, true, 22, Font.BOLD);
document.open();
XMLWorkerHelper helper = XMLWorkerHelper.getInstance();
// CSS
CSSResolver cssResolver = new StyleAttrCSSResolver();
CssFile cssFile = helper.getCSS(new FileInputStream(
"D:\\Itext_Test\\Test\\src\\test.css"));
cssResolver.addCss(cssFile);
// HTML
XMLWorkerFontProvider fontProvider = new XMLWorkerFontProvider();
fontProvider.getFont("C:\\damase.ttf", BaseFont.IDENTITY_H,BaseFont.EMBEDDED);
fontProvider.register("C:\\damase.ttf");
CssAppliers cssAppliers = new CssAppliersImpl(fontProvider);
HtmlPipelineContext htmlContext = new HtmlPipelineContext(
cssAppliers);
htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
PdfWriterPipeline pdf = new PdfWriterPipeline(document, writer);
HtmlPipeline html = new HtmlPipeline(htmlContext, pdf);
CssResolverPipeline css = new CssResolverPipeline(cssResolver,
html);
XMLWorker worker = new XMLWorker(css, true);
XMLParser p = new XMLParser(worker);
String htmlString = "<html><head></head><body>"+"اب"+"</body></html>";
ByteArrayInputStream is = new ByteArrayInputStream(htmlString.getBytes("UTF-8"));
p.parse(is, Charset.forName("UTF-8"));
document.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}