java 使用documents4J将office文件转换为pdf时出错:类路径包含多个SLF4J绑定

lx0bsm1f  于 2022-12-21  发布在  Java
关注(0)|答案(1)|浏览(1531)

我试图使用documents4j将Office文件和图像转换为PDF,但得到"* 类路径包含多个SLF4J绑定 *"。
下面是我目前的代码:

package documentsForJ;
import java.io.File;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import com.documents4j.api.DocumentType;
import com.documents4j.api.IConverter;
import com.documents4j.job.LocalConverter;

public class App {
    public static void main(String[] args) {

        File wordFile = new File("test.doc"), target = new File("test.pdf");

        IConverter converter = LocalConverter.builder().baseFolder(new File("G:\\documentsForJ\\target"))
                .workerPool(20, 25, 2, TimeUnit.SECONDS)
                .processTimeout(5, TimeUnit.SECONDS).build();

        Future<Boolean> conversion = converter.convert(wordFile).as(DocumentType.DOCX).to(target).as(DocumentType.PDF)
                // .prioritizeWith(1000) // optional
                .schedule();

    }
}

我已绑定以下广口瓶:

  • 文档4j-api-1.0.2.jar文档4j-client-1.0.2.jar
  • documents4j-client-standalone-1.0.2-shaded.jar
  • documents4j-local-1.0.2.jar
  • documents4j-server-standalone-1.0.2-shaded.jar
  • 文档4j-测试-1.0.2.jar文档4j-变压器-api-1.0.2.jar
  • documents4j-transformer-msoffice-base-1.0.2.jar
  • documents4j-transformer-msoffice-excel-1.0.2.jar
  • documents4j-transformer-msoffice-test-1.0.2.jar
  • documents4j-transformer-msoffice-word-1.0.2.jar
  • documents4j-util-standalone-1.0.2.jar
  • documents4j-util-transformer-process-1.0.2.jar
  • 文档4j实用程序ws1.0.2.jar文档4j服务器1.0.2.jar
  • 文档4j-转换器-1.0.2.jar文档4j-实用程序-全部-1.0.2.jar
  • documents4j-util-conversion-1.0.2.jar

当我运行应用程序时,我得到以下错误:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/G:/AdminPrgs/Code/Java/eclipse/workspaceTest/documentsForJ/lib/documents4j-client-standalone-1.0.2-shaded.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/G:/AdminPrgs/Code/Java/eclipse/workspaceTest/documentsForJ/lib/documents4j-server-standalone-1.0.2-shaded.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
16:28:49.030 [main] DEBUG o.z.exec.ProcessExecutor - Executing [cmd, /C, "C:\temp\excel_start1565707660.vbs"] in C:\temp.
16:28:49.038 [main] DEBUG o.z.exec.ProcessExecutor - Started java.lang.ProcessImpl@1bc6a36e
16:28:49.074 [WaitForProcess-java.lang.ProcessImpl@1bc6a36e] DEBUG o.zeroturnaround.exec.WaitForProcess - java.lang.ProcessImpl@1bc6a36e stopped with exit code 3
16:28:49.081 [main] INFO  c.d.c.msoffice.MicrosoftExcelBridge - From-Microsoft-Excel-Converter was started successfully
16:28:49.085 [main] DEBUG o.z.exec.ProcessExecutor - Executing [cmd, /C, "C:\temp\word_start2143216009.vbs"] in C:\temp.
16:28:49.086 [main] DEBUG o.z.exec.ProcessExecutor - Started java.lang.ProcessImpl@6fffcba5
16:28:49.121 [WaitForProcess-java.lang.ProcessImpl@6fffcba5] DEBUG o.zeroturnaround.exec.WaitForProcess - java.lang.ProcessImpl@6fffcba5 stopped with exit code 3
16:28:49.121 [main] INFO  c.d.c.msoffice.MicrosoftWordBridge - From-Microsoft-Word-Converter was started successfully
16:28:49.132 [main] INFO  com.documents4j.job.LocalConverter - The documents4j local converter has started successfully
fertig!
16:28:49.145 [pool-1-thread-1] INFO  c.d.c.msoffice.MicrosoftExcelBridge - Requested conversion from AbrechnungKFZ-Kosten.xls (application/vnd.ms-excel) to AbrechnungKFZ-Kosten.pdf (application/pdf)
16:28:49.148 [pool-1-thread-1] DEBUG o.z.exec.ProcessExecutor - Executing [cmd, /C, "C:\temp\excel_convert961528339.vbs G:\AdminPrgs\Code\Java\eclipse\workspaceTest\documentsForJ\AbrechnungKFZ-Kosten.xls G:\AdminPrgs\Code\Java\eclipse\workspaceTest\documentsForJ\AbrechnungKFZ-Kosten.pdf 999"] in C:\temp.
16:28:49.148 [pool-1-thread-1] DEBUG o.z.exec.ProcessExecutor - Started java.lang.ProcessImpl@39bd6b04
16:28:49.188 [WaitForProcess-java.lang.ProcessImpl@39bd6b04] DEBUG o.zeroturnaround.exec.WaitForProcess - java.lang.ProcessImpl@39bd6b04 stopped with exit code -4

生成的VBS C:\temp\excel_start1565707660.vbs出现以下错误:enter image description here
下面是生成的vbs的代码:

' See http://msdn.microsoft.com/en-us/library/bb243311%28v=office.12%29.aspx
Const WdExportFormatPDF = 17
Const MagicFormatPDF = 999

Dim arguments
Set arguments = WScript.Arguments

' Transforms a file using MS Excel into the given format.
Function ConvertFile( inputFile, outputFile, formatEnumeration )

  Dim fileSystemObject
  Dim excelApplication
  Dim excelDocument

  ' Get the running instance of MS Excel. If Excel is not running, exit the conversion.
  On Error Resume Next
  Set excelApplication = GetObject(, "Excel.Application")
  If Err <> 0 Then
    WScript.Quit -6
  End If
  On Error GoTo 0

  ' Find the source file on the file system.
  Set fileSystemObject = CreateObject("Scripting.FileSystemObject")
  inputFile = fileSystemObject.GetAbsolutePathName(inputFile)

  
  ' Convert the source file only if it exists.
  If fileSystemObject.FileExists(inputFile) Then

    ' Attempt to open the source document.
    On Error Resume Next
    Set excelDocument = excelApplication.Workbooks.Open(inputFile, , True, , , , , , , , , , , , 2)
    If Err <> 0 Then
        WScript.Quit -2
    End If
    On Error GoTo 0

    ' Convert: See http://msdn2.microsoft.com/en-us/library/bb221597.aspx
    On Error Resume Next
    If formatEnumeration = MagicFormatPDF Then
      excelDocument.ExportAsFixedFormat xlTypePDF, outputFile
    Else
      excelDocument.SaveAs outputFile, formatEnumeration
    End If

    ' Close the source document.
    excelDocument.Close False
    If Err <> 0 Then
        WScript.Quit -3
    End If
    On Error GoTo 0

    ' Signal that the conversion was successful.
    WScript.Quit 2

  Else

    ' Files does not exist, could not convert
    WScript.Quit -4

  End If

End Function

' Execute the script.
Call ConvertFile( arguments.Unnamed.Item(0), arguments.Unnamed.Item(1), CInt(arguments.Unnamed.Item(2)) )

为什么会发生此错误?如何修复此问题?

vmpqdwk3

vmpqdwk31#

最新发布的documents4j版本1.0.3很可能解决了这个问题,它为转换脚本参数添加了正确的转义。以前,没有转义任何参数,这可能会在VBScript处理脚本参数时引起混乱,正如您所观察到的那样。

相关问题