首页 > 解决方案 > JODConverter & LibreOffice:将 doc 转换为带有嵌入图像的 html

问题描述

我正在使用 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();

标签: javalibreofficejodconverter

解决方案


这会起作用:

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();

推荐阅读