【问题标题】:Generation of Telugu PDF from HTML using ITextRenderer does not getting exact characters?使用 ITextRenderer 从 HTML 生成泰卢固语 PDF 没有得到准确的字符?
【发布时间】:2017-05-09 07:35:14
【问题描述】:

使用 ITextRenderer 从 HTML 生成泰卢固语 PDF 没有得到准确的字符? pdf 中的字符损坏(预期字符 వినియోగించుకోకపోయినట్లయితే )。附上屏幕截图。enter image description here

我们使用下面的代码来生成带有字体的 UTF-8 pdf

1) body * { font-family: "Vani", Georgia, Serif;}

2)Document doc = builder.parse(new ByteArrayInputStream(content.toString().getBytes("UTF-8")));

3)renderer.getFontResolver().addFont(contextPath+"fonts/VANI.TTF",BaseFont.IDENTITY_H,BaseFont.EMBEDDED); 4) jar itext 4.2 和 core-render.jar

请帮助获取 PDF 中的例外输出。

【问题讨论】:

    标签: java pdf pdf-generation flying-saucer xhtmlrenderer


    【解决方案1】:

    您使用的是ITextRenderer,这导致您认为您使用的是飞碟。 飞碟不是 iText。飞碟是使用旧版 iText 的第三方产品,未经 iText Group 认可。

    那个旧版本的 iText 不支持泰卢固语。支持天文体、泰米尔语、泰卢固语等书写系统需要pdfCalligraph add-on。此插件仅适用于 iText 7。我们已就该主题撰写了综合性的 white paper

    如果您想将使用泰卢固语的 HTML 转换为 PDF,使用飞碟是无法实现的。据我所知,唯一允许您执行此操作的工具是 iText 7、用于 Telugy 支持的 pdfCalligraph add-on 和用于将 HTML 转换为 PDF 的 pdfHTML add-on 的组合。

    更新:

    如果要使用pdfCalligraph,需要添加如下依赖:

    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>typography</artifactId>
        <version>[1.0,)</version>
        <scope>compile</scope>
    </dependency>
    

    由于 pdfCalligraph 是一个闭源插件,您还需要将我们的闭源存储库添加到您的存储库列表中:

    <repositories>
        <repository>
            <id>central</id>
            <name>iText Repository-releases</name>
            <url>https://repo.itextsupport.com/releases</url>
        </repository>
    </repositories>
    

    最后,需要引入许可密钥机制(否则pdfCalligraph会抛出com.itextpdf.licensekey.LicenseKeyExceptionjava.io.FileNotFoundException:itextkey.xml):

    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>itext-licensekey</artifactId>
        <version>[2.0,)</version>
        <scope>compile</scope>
    </dependency>
    

    您需要一个许可证密钥 (KEY),并且您需要像这样加载该密钥:

    LicenseKey.loadLicenseFile(new FileInputStream(KEY));
    

    KEY 包含 XML 文件的路径。此 XML 文件是您的许可证密钥。您可以在此处获取这样的 XML 文件:free trial

    【讨论】:

    • 此外,他们使用的是 iText 4.2.0,这是一个从未由 iText Software 发布但由 ymasory/InProTopia 发布的版本。
    • 能否请您解释更多...尝试使用 itext7 生成泰卢固语 pdf。我们仍然对差距感到满意。
    • @user1896803 如果你得到的内容有间隙,你没有使用 pdfCalligraph。请注意,pdfCalligraph 是封闭源代码。如果您想使用它,它需要试用许可证。你拿到试用许可证了吗?在教程第2章搜索pdfCalligraph这个词:developers.itextpdf.com/content/itext-7-building-blocks/…
    • 尝试了试用许可证,但找不到。您能否让我们知道在哪里可以找到试用版以及在 PDF 中获取泰卢固语所需的所有 jar 文件,如果您提供一些示例代码,这将对我们有所帮助。提前致谢。
    • 我会把它放在我的答案中。评论区太多了。
    猜你喜欢
    • 2022-10-04
    • 1970-01-01
    • 1970-01-01
    • 2012-05-02
    • 1970-01-01
    • 2017-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多