【问题标题】:itext htmlworker not working for Myanmar characteritext htmlworker不适用于缅甸字符
【发布时间】:2019-10-21 05:46:55
【问题描述】:

我正在尝试将 HTMLWorker 用于 itext pdf,而对于缅甸字符它不起作用,而在纯 html 中它可以工作 HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href='https://mmwebfonts.comquas.com/fonts/?font=myanmar3' />
    <link rel="stylesheet" href='https://mmwebfonts.comquas.com/fonts/?font=zawgyi' />  
    <style type="text/css">
        .zawgyi{
            font-family:Zawgyi-One;
        }
        .unicode{
            font-family:Myanmar3,Yunghkio,'Masterpiece Uni Sans';
        }
    </style>
</head>
<body>
    <h3>This is for ZawGyI font</h3>
    <p class="zawgyi">၀န္ထမ္းလစာေပးေခ်လႊာ( လစာငွေ )
        သည္စာသည္ ေဇာ္ဂ်ီ ျဖင့္ေရးေသာစာျဖစ္သည္
    </p>
    <h3>This is for unicode (myanmar3) font</h3>
    <p class="unicode">၀န္ထမ္းလစာေပးေခ်လႊာ( လစာငွေ )
        သည်စာသည် unicode ဖြင့်ရေးသောစာဖြစ်သည်
    </p>
</body>
</html>

文本代码:

String str1="<html><head>\n" +
"   <meta charset=\"UTF-8\">\n" +
"   <title>Document</title>\n" +
"   <link rel=\"stylesheet\" href='https://mmwebfonts.comquas.com/fonts/?font=myanmar3' />\n" +
"   <link rel=\"stylesheet\" href='https://mmwebfonts.comquas.com/fonts/?font=zawgyi' />    \n" +
"   <style type=\"text/css\">\n" +
"       .zawgyi{\n" +
"           font-family:Zawgyi-One;\n" +
"       }\n" +
"       .unicode{\n" +
"           font-family:Myanmar3,Yunghkio,'Masterpiece Uni Sans';\n" +
"       }\n" +
"   </style>\n" +
"</head>\n" +
"<body>\n" +
"   <h3>This is for ZawGyI font</h3>\n" +
"   <p class=\"zawgyi\">\n" +
"       သည္စာသည္ ေဇာ္ဂ်ီ ျဖင့္ေရးေသာစာျဖစ္သည္\n" +
"   </p>\n" +
"   <h3>This is for unicode (myanmar3) font</h3>\n" +
"   <p class=\"unicode\">\n" +
"       သည်စာသည် unicode ဖြင့်ရေးသောစာဖြစ်သည်\n" +
"   </p>\n" +
"</body>\n" +
"</html>";

HTMLWorker worker = new HTMLWorker(document);
worker.parse(new StringReader(str1));

    document.close();

当我尝试 XMLWorker 时,它说 head 标签不能嵌套。 当我使用 FontSelector 时它工作正常,但我需要解析 html 并且无法将 FontSelector 与 HTML 一起使用。

【问题讨论】:

    标签: itext


    【解决方案1】:

    这似乎是 iText5 的问题,我将它升级到 iText7,现在它可以使用以下代码正常工作:

    File pdfDest = new File(pdfFile);
             String html = <>html;
            ConverterProperties converterProperties = new ConverterProperties();
            FontProvider fontProvider = new DefaultFontProvider(true, false, true);
            converterProperties.setFontProvider(fontProvider);
            try {
                HtmlConverter.convertToPdf(html,
                        new FileOutputStream(pdfDest), converterProperties);
            } catch (FileNotFoundException | IOException ex) {
            }
    

    【讨论】:

      猜你喜欢
      • 2014-04-26
      • 1970-01-01
      • 1970-01-01
      • 2020-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多