iTextPDF不显示来自XMLWorkerHelper的日语字符 [英] iTextPDF not showing Japanese characters from XMLWorkerHelper
问题描述
我正在尝试使用iTextPDF的XMLWorkerHelper生成PDF文件.最初,我使用Apache Velocity Template生成HTML代码(因此使用了XMLWorkerHelper),但是对于这个问题,我只提供其中包含日语字符的简单HTML行.
I'm trying to generate a PDF file using iTextPDF's XMLWorkerHelper. Originally, I am using Apache Velocity Template to generate an HTML code (hence the XMLWorkerHelper being used), but for this question I'll just provide a simple HTML line with Japanese Characters in it.
public class iTextJapChars {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
FileOutputStream fos = new FileOutputStream("iTextJapChars.pdf");
(new iTextJapChars()).generate(fos);
fos.close();
System.out.println("done!");
}
public void generate(OutputStream os) throws IOException
{
// create a document
Document document = new Document();
try
{
String content = "<html><head></head><body><div><p>begin てすと end</p></div></body></html>";
InputStream stream = new ByteArrayInputStream(content.getBytes("UTF-8"));
System.out.println(content);
System.out.println(Charset.defaultCharset());
// create a writer with an output stream passed as an argument
PdfWriter writer = PdfWriter.getInstance(document, os);
document.addTitle("身 元 保 証 書");
document.addAuthor("れお");
document.addSubject("");
document.addKeywords("iText, PDF");
document.addCreator("test.iTextPDF.generate() using iText");
document.open(); // open the document now
XMLWorkerHelper.getInstance().parseXHtml(writer, document, stream);
}
catch (DocumentException de) { throw new IOException(de.getMessage()); }
finally { document.close(); } // close the document
}
问题是,我无法获得显示为日语字符的结果PDF文件.它只显示空白.以下是注意事项:
The problem is, I can't get the resulting PDF file to show the Japanese characters. It only shows blank. Below are the things to note:
- CentOS 6.4
- iTextPDF 5.4.3
- XMLWorker 5.4.1
- Adobe Reader 9.5.5
希望您可以在这里为我提供帮助,因为我已经在网上搜索了一个多星期,并且无法使用XMLWorkerHelper获得任何解决方案.如果有任何我想提及的信息,或者我提到了错误的信息,请告诉我,以便我进行更新.任何帮助将不胜感激.
Hope you can help me out here as I have been searching the net for more than a week now and I can't get any of the solutions to work using XMLWorkerHelper. If there is any information I have missed to mention, or I have mentioned a wrong info, please do tell me so I can update. Any help would be much appreciated.
非常感谢您.
推荐答案
尝试以下逻辑即可工作
XMLWorkerHelper.getInstance().parseXHtml(writer, document, stream, Charset.forName("UTF-8"));
请检查Adobe Reader 9.5.5是否可以使用红色日语字符,如果未从" http://supportdownloads.adobe.com/detail.jsp?ftpID=5877 ".
pls check Adobe Reader 9.5.5 is able to red Japanese character, if not install language support from "http://supportdownloads.adobe.com/detail.jsp?ftpID=5877".
Adobe Reader将采用您的OS/计算机中存在的显示语言.下面给出的链接将显示为Windows 7设置的语言
Adobe Reader will take the display languages present in your OS / machine. Given below link will show the language set up for windows 7 https://www.wikihow.com/Change-the-Language-in-Windows-7
这篇关于iTextPDF不显示来自XMLWorkerHelper的日语字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!