我正在尝试使用iTextPDF的XMLWorkerHelper生成一个PDF文件。最初,我使用Apache流速模板生成HTML代码(因此使用了XMLWorkerHelper ),但对于这个问题,我只提供一个简单的包含日语字符的HTML行。
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文件来显示日文字符。它只显示空白。以下是要注意的事项:
希望你能在这里帮助我,因为我已经在网上搜索了一个多星期了,而且我无法找到任何使用XMLWorkerHelper的解决方案。如果有任何信息我没有提到,或我提到了一个错误的信息,请告诉我,以便我可以更新。任何帮助都将不胜感激。
非常感谢。
发布于 2013-09-16 07:00:01
尝尝这个
XMLWorkerHelper.getInstance().parseXHtml(writer, document, stream,Charset.forName("ISO-8859-1"));发布于 2017-11-24 08:05:41
用下面的逻辑来尝试,它应该能工作
XMLWorkerHelper.getInstance().parseXHtml(writer, document, stream, Charset.forName("UTF-8"));请检查Adobe 9.5.5是否能够红色日语字符,如果没有安装语言支持从"http://supportdownloads.adobe.com/detail.jsp?ftpID=5877“。
Adobe将使用操作系统/计算机中的显示语言。下面的链接将显示为windows 7 https://www.wikihow.com/Change-the-Language-in-Windows-7设置的语言。
https://stackoverflow.com/questions/18821431
复制相似问题