我使用 document4j 库构建了一个 PDF 到 Word 转换器,但链接有问题。例如,在 PDF 文件中,您可以单击章节名称,它会立即跳转到那里,但在转换为 doc 文件后,不幸的是它不再起作用了。有谁知道如何将其添加到代码中?
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();
}
}
}