首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iTextPDF没有显示来自XMLWorkerHelper的日语字符

iTextPDF没有显示来自XMLWorkerHelper的日语字符
EN

Stack Overflow用户
提问于 2013-09-16 06:13:08
回答 2查看 3.1K关注 0票数 2

我正在尝试使用iTextPDF的XMLWorkerHelper生成一个PDF文件。最初,我使用Apache流速模板生成HTML代码(因此使用了XMLWorkerHelper ),但对于这个问题,我只提供一个简单的包含日语字符的HTML行。

代码语言:javascript
复制
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文件来显示日文字符。它只显示空白。以下是要注意的事项:

  • CentOS 6.4
  • iTextPDF 5.4.3
  • XMLWorker 5.4.1
  • 9.5.5

希望你能在这里帮助我,因为我已经在网上搜索了一个多星期了,而且我无法找到任何使用XMLWorkerHelper的解决方案。如果有任何信息我没有提到,或我提到了一个错误的信息,请告诉我,以便我可以更新。任何帮助都将不胜感激。

非常感谢。

EN

回答 2

Stack Overflow用户

发布于 2013-09-16 07:00:01

尝尝这个

代码语言:javascript
复制
XMLWorkerHelper.getInstance().parseXHtml(writer, document, stream,Charset.forName("ISO-8859-1"));
票数 0
EN

Stack Overflow用户

发布于 2017-11-24 08:05:41

用下面的逻辑来尝试,它应该能工作

代码语言:javascript
复制
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设置的语言。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18821431

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档