【问题标题】:JODConverter & LibreOffice: convert doc to html with embedded imagesJODConverter & LibreOffice:将 doc 转换为带有嵌入图像的 html
【发布时间】:2019-04-02 14:13:09
【问题描述】:

我正在使用 JODConverter 库 (4.2.2) 和 LibreOffice (6.2) 将 doc/docx 文件转换为 html。我需要的是将图像保存为嵌入在 html 文件中,但默认情况下它保存在单独的文件中。

为了做到这一点,我正在使用 LibreOffice 命令行界面:

soffice --convert-to html:HTML:EmbedImages example.docx

我想知道是否有任何方法可以通过 JODConverter 库传递选项 EmbedImages

我的java代码:

LocalConverter
    .make()
    .convert(new FileInputStream(docFile))
    .as(DefaultDocumentFormatRegistry.getFormatByMediaType(file.getMediaType().getName()))
    .to(htmlTempFile)
    .as(DefaultDocumentFormatRegistry.HTML)
    .execute();

【问题讨论】:

  • 将带有外部图像的 HTML 转换为嵌入图像非常简单,读取所有字节,1 次调用,Base64 字节到文本,1 次调用,tag/css 中的数据 url(mime 类型 png/jpeg )。

标签: java libreoffice jodconverter


【解决方案1】:

这可行:

final DocumentFormat format =
    DocumentFormat.builder()
        .from(DefaultDocumentFormatRegistry.HTML)
        .storeProperty(DocumentFamily.TEXT, "FilterOptions", "EmbedImages")
        .build();

LocalConverter
    .make()
    .convert(new FileInputStream(docFile))
    .as(DefaultDocumentFormatRegistry.getFormatByMediaType(file.getMediaType().getName()))
    .to(htmlTempFile)
    .as(format)
    .execute();

【讨论】:

  • 做同样的事情仍然不适合我。它仍在创建单独的图像
  • @DhirenSolanki 你能提供更多细节吗?您使用的是哪个版本?您可以创建一个示例项目并分享它吗?如果您可以轻松重现问题,也可以在 github 上使用示例项目打开问题。
猜你喜欢
  • 2015-12-30
  • 2013-02-24
  • 1970-01-01
  • 2013-04-24
  • 1970-01-01
  • 1970-01-01
  • 2012-11-28
  • 2013-06-13
  • 1970-01-01
相关资源
最近更新 更多