【问题标题】:Encryption of pdfs xDocReport (iText) using IPdfWriterConfiguration does not work使用 IPdfWriterConfiguration 加密 pdf xDocReport (iText) 不起作用
【发布时间】:2015-07-03 06:56:26
【问题描述】:

我正在使用 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();
}

【问题讨论】:

  • 似乎 iText 使用了一个名为 bountycastle 的库进行加密,并且由于 bountycastle 最新版本破坏了 iText 支持,我不得不使用该库的较低版本才能使其正常工作。似乎 xDocReport 或更具体地说,iText 使用一个名为 bountycastle 的库进行加密,由于 bountycastle 最新版本打破了 iText 支持,我不得不使用该库的较低版本才能使其正常工作according to this thread

标签: java pdf itext xdocreport


【解决方案1】:

添加这个 maven 依赖项为我解决了这个问题

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-07
    • 1970-01-01
    • 1970-01-01
    • 2013-04-27
    • 1970-01-01
    • 2019-04-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多