我正在使用xDocReport从Docx和Odt文件生成pdf,除IPdfWriterConfiguration似乎在转换时不会被确认或调用外,其他所有功能都很好。

PdfOptions pdfOptions = PdfOptions.create();
pdfOptions.setConfiguration(new IPdfWriterConfiguration() {
    // This is never called
    public void configure(PdfWriter writer) {
        try {
            writer.setEncryption("Hello".getBytes(), "Hello".getBytes(),
                PdfWriter.ALLOW_COPY,
                PdfWriter.STANDARD_ENCRYPTION_128 | PdfWriter.DO_NOT_ENCRYPT_METADATA);
            writer.createXmpMetadata();
        } catch (DocumentException ex) {
            throw new RuntimeException(ex);
        }
    }
});
Options options = Options.getTo(ConverterTypeTo.PDF).subOptions(pdfOptions);
OutputStream out = new FileOutputStream(tempPdfFile);
try {
    report.convert(context, options, out);
} finally {
    out.close();
}

最佳答案

添加此Maven依赖关系为我解决了这个问题

    <dependency>
        <groupId>org.bouncycastle</groupId>
        <artifactId>bcprov-jdk15</artifactId>
        <version>1.44</version>
    </dependency>

09-25 18:01