2015-07-03 32 views
0

我正在使用xDocReport從Docx和Odt文件生成pdf,除了IPdfWriterConfiguration,在轉換時似乎不會被識別或調用發生。使用IPdfWriterConfiguration加密pdf的xDocReport(iText)不起作用

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(); 
} 
+0

看來,iText的使用庫,稱爲bountycastle用於加密和自bountycastle最新版本打破iText支持我不得不使用較低版本這個庫,以便這個工作。似乎xDocReport或更具體的iText使用一個庫,稱爲bountycastle加密和自bountycastle最新版本打破iText的支持,我不得不使用這個庫的較低版本,爲了這個工作[根據這個線程](http://stackoverflow.com/questions/10391271/itext-bouncycastle-classnotfound-org- BouncyCastle的-ASN1-derencodable和-ORG-奔) – soaP

回答

1

添加此Maven的依賴關係解決了這個問題對我來說

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