簡體   English   中英

使用IPdfWriterConfiguration加密PDF xDocReport(iText)無效

[英]Encryption of pdfs xDocReport (iText) using IPdfWriterConfiguration does not work

我正在使用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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM