1

I have built a PDF to Word converter using the document4j library but have a problem with the links. For example, in the PDF file you can click on a chapter name and it jumps there immediately, but after converting to a doc file it unfortunately doesn't work anymore. Does anyone have an idea how I can add this to the code?


import java.io.File;
import java.util.concurrent.ExecutionException;
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 
{
    final static String dir = "C:/Users/sakyildi/Desktop/fosTest/";
    
     
    public static void main( String[] args )
    {
        File pdfFile = new File(dir + "Sandbox_TopLevelTopic.pdf");
        File wordFile = new File(dir + "test.docx");
            IConverter converter = LocalConverter.builder()
                    .baseFolder(new File(dir))
                    .workerPool(20, 25, 2, TimeUnit.SECONDS)
                    .processTimeout(5, TimeUnit.SECONDS)
                    .build();
                
            Future<Boolean> conversion = converter
              .convert(pdfFile).as(DocumentType.PDF)
              .to(wordFile).as(DocumentType.DOCX)
              .schedule();
            
            System.out.println(wordFile.getPath());
            try {
                conversion.get();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ExecutionException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

       
    }
}
serkan45
  • 11
  • 1

1 Answers1

2

This is really controlled by Word, not documents4j. The Word conversion script takes many parameters, and maybe one of them can enable this behavior. You can set a custom conversion script via a command line parameter to see what works here.

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192