Java アプリで DOCX ファイルを PDF に変換する必要があります。xDocReport lib を試しましたが、目次が変換されません。出力 PDF ファイルには、ToC の代わりに空のスペースがあります。
これが私のコードです、それは簡単です:
import java.io.*;
import org.apache.poi.xwpf.converter.pdf.PdfConverter;
import org.apache.poi.xwpf.converter.pdf.PdfOptions;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
public class DocxToPDFService {
public void generatePDF(String srcPath, String destPath) throws Exception {
XWPFDocument docx;
try {
docx = new XWPFDocument(new FileInputStream(srcPath));
} catch (IOException ioE) {
throw ioE;
}
PdfOptions options = PdfOptions.create().fontEncoding("windows-1250");
FileOutputStream pdf = new FileOutputStream(destPath);
PdfConverter.getInstance().convert(docx, pdf, options);
}
}
ToC に変換する回避策はありますか?