1

I'm writing a small application to convert office documents to pdf. Now I found Documents4j and as of now it's my best choice for .docx documents. It works very good.

Now I also want to use it for .xlsx -> .pdf conversions, but I'm having some trouble. I have the following code:

class OfficeToPdfConverter {
    fun convert(input: File, output: File) = try {
        LocalConverter.builder().build().convert(input).`as`(determineInput(input)).to(output)
            .`as`(DocumentType.PDF)
            .execute()
    } catch (e: Exception) {
        e.printStackTrace()
    }

    private fun determineInput(input: File) = when (input.extension) {
        "docx" -> DocumentType.DOCX
        "pptx" -> DocumentType.PPTX
        "xlsx" -> DocumentType.XLSX
        else -> DocumentType.DOCX
    }
}

For .docx this works. When I try to convert .xlsx or .pptx I get the following error messages:

  1. No converter for conversion of application/vnd.openxmlformats-officedocument.presentationml.presentation to application/pdf available
  2. No converter for conversion of application/vnd.openxmlformats-officedocument.presentationml.presentation to application/pdf available

I thought .xlsx and .pptx would just work, but I was a bit naïve I think.

Does anyone have experience with this, and how should I implement it?

Ricardo de Vries
  • 113
  • 3
  • 11
  • Have you added `com.documents4j:documents4j-transformer-msoffice-excel` to maven? – tgdavies Jun 13 '22 at 10:12
  • Sometimes my own stupidity amazes even myself. I added the one for excel, and now it works. Thanks! – Ricardo de Vries Jun 13 '22 at 11:23
  • I am getting an error stating "No converter for conversion of application/vnd.openxmlformats-officedocument.presentationml.presentation to application/pdf available" when I try to convert .pptx to .pdf, although I added the dependency "documents4j-transformer-msoffice-powerpoint" to my pom. Do you know why this then happens? – Ricardo de Vries Jun 13 '22 at 11:30
  • See https://bytemeta.vip/index.php/repo/documents4j/documents4j/issues/131 – tgdavies Jun 13 '22 at 12:55

0 Answers0