0

I using Spring MVC web project and I need the documents4j library when converting the docx file to pdf. Documents4j can convert docx to pdf properly but then my web session is logged out. Does anyone know why?

I'am using Spring mvc web structure and i need documents4j for docx to convert pdf. the code I use to convert:

    File inputWord = new File("Tests.docx");
File outputFile = new File("Test_out.pdf");
try  {
    InputStream docxInputStream = new FileInputStream(inputWord);
    OutputStream outputStream = new FileOutputStream(outputFile);
    IConverter converter = LocalConverter.builder().build();
    converter.convert(docxInputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute();
    outputStream.close();
    System.out.println("success");
} catch (Exception e) {
    e.printStackTrace();
}

I am using following dependicies;

<dependency>
    <groupId>com.documents4j</groupId>
    <artifactId>documents4j-local</artifactId>
    <version>1.0.3</version>
</dependency>
<dependency>
    <groupId>com.documents4j</groupId>
    <artifactId>documents4j-api</artifactId>
    <version>1.0.3</version>
</dependency>
<dependency>
    <groupId>com.documents4j</groupId>
    <artifactId>documents4j-transformer-msoffice-word</artifactId>
    <version>1.0.3</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>1.7.13</version>
</dependency>

My output:

INFO com.documents4j.conversion.msoffice.MicrosoftWordBridge - From-Microsoft-Word-Converter was started successfully
INFO com.documents4j.job.LocalConverter - The documents4j local converter has started successfully
INFO com.documents4j.conversion.msoffice.MicrosoftWordBridge - Requested conversion from C:\a\b3106f03-c187-4059-bbd0-46b7bb4a1404\temp1 (application/vnd.com.documents4j.any-msword) to C:\a\b3106f03-c187-4059-bbd0-46b7bb4a1404\temp2 (application/pdf)
Ozdenur
  • 15
  • 7
  • It is really hard to guess what is your problem in 3 lines without any example... but the first thing that pop up on my mind is session timeout. – Lucas Campos May 12 '20 at 12:31
  • I edit my question. my problem is actually log out without any error, converting to pdf is being downloaded as pdf but when i refresh the page it wants me to log in again. – Ozdenur May 12 '20 at 14:32
  • You can supply the file references directly, rather then the streams. If the log does not produces any lines after, it seems like your conversion hung up, possibly due to a lock on a file. Make sure Word is not opened. – Rafael Winterhalter May 14 '20 at 07:15

0 Answers0