【问题标题】:Convert HTML to PDF using XMLWorker library doesn't work使用 XMLWorker 库将 HTML 转换为 PDF 不起作用
【发布时间】:2018-02-15 06:06:04
【问题描述】:

我有一个HTML 文档,我需要将其转换为 PDF 格式。我已将 iText XMLWorker 库添加到我的项目中并编写了这个 sn-p:

OutputStream file = new FileOutputStream(new File("testing.pdf"));
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, file);
document.open();
InputStream is = new ByteArrayInputStream(docString.getBytes());
XMLWorkerHelper.getInstance().parseXHtml(writer, document, is);
document.close();
file.close();

但问题是我既不能包括Document 也不能包括PdfWriter。它们不包含在库中,当我尝试添加时

import com.itextpdf.text.Document;
import com.itextpdf.text.pdf.PdfWriter;

在添加的库中找不到.text

有什么问题?有什么遗漏吗?我应该添加其他内容吗?

【问题讨论】:

  • XML Worker 是 iText 的附加组件。您有 XML Worker 库,但没有 iText 库。在我们讨论的时候:为什么你使用旧的 iText 5 + 旧的 XML Worker,当它被 iText 7 和 pdfHTML 取代时?见developers.itextpdf.com/content/…
  • 我已将 iText 7.0 包含到我的应用程序中,但无法导入 HtmlConverter,尽管我已将所有子库添加到项目中!!
  • 我很确定缺少一些子库。向我们展示您的 POM。
  • @BrunoLowagie OP 不使用 Maven(或 Gradle,因为 Android),因为如果是,那么添加对 XMLWorker 的依赖项将自动引入所需的依赖项。因此我得出结论,他们不能也不会向您展示他们的 POM。

标签: android pdf itext xmlworker


【解决方案1】:

2019 年在 android iText7 和 pdfHtml 中使用它在你的 build.gradle 中可以正常工作

实现 'com.itextpdf:itext7-core:7.1.5' 实现 'com.itextpdf:html2pdf:2.1.2'

这是最新版本。

【讨论】:

    猜你喜欢
    • 2013-09-24
    • 2013-06-28
    • 2013-01-26
    • 2023-02-26
    • 2021-08-12
    • 2016-07-10
    • 2015-05-20
    • 1970-01-01
    • 2019-04-06
    相关资源
    最近更新 更多