本文整理汇总了Java中org.apache.pdfbox.pdmodel.encryption.BadSecurityHandlerException类的典型用法代码示例。如果您正苦于以下问题:Java BadSecurityHandlerException类的具体用法?Java BadSecurityHandlerException怎么用?Java BadSecurityHandlerException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BadSecurityHandlerException类属于org.apache.pdfbox.pdmodel.encryption包,在下文中一共展示了BadSecurityHandlerException类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doExtractText
import org.apache.pdfbox.pdmodel.encryption.BadSecurityHandlerException; //导入依赖的package包/类
private String doExtractText(Exchange exchange) throws IOException, CryptographyException, InvalidPasswordException, BadSecurityHandlerException {
LOG.debug("Got {} operation, going to extract text from provided pdf.", pdfConfiguration.getOperation());
PDDocument document = exchange.getIn().getBody(PDDocument.class);
if (document.isEncrypted()) {
DecryptionMaterial decryptionMaterial = exchange.getIn().getHeader(DECRYPTION_MATERIAL_HEADER_NAME,
DecryptionMaterial.class);
if (decryptionMaterial == null) {
throw new IllegalArgumentException(String.format("%s header is expected for %s operation "
+ "on encrypted document",
DECRYPTION_MATERIAL_HEADER_NAME,
pdfConfiguration.getOperation()));
}
document.openProtection(decryptionMaterial);
}
PDFTextStripper pdfTextStripper = new PDFTextStripper();
return pdfTextStripper.getText(document);
}
示例2: protect
import org.apache.pdfbox.pdmodel.encryption.BadSecurityHandlerException; //导入依赖的package包/类
@Override
public void protect(final String inputUri, final String outputUri, final String password)
throws IOException, BadSecurityHandlerException, COSVisitorException {
if (StringUtils.isNotBlank(inputUri) && StringUtils.isNotBlank(outputUri)
&& StringUtils.isNotBlank(password)) {
final PDDocument doc = PDDocument.load(inputUri);
final StandardProtectionPolicy pp = new StandardProtectionPolicy(password, password,
new AccessPermission());
doc.protect(pp);
doc.save(outputUri);
doc.close();
} else {
throw new IllegalArgumentException(Constants.ILLEGAL_ARGUMENT_EXCEPTION_MESSAGE);
}
}
示例3: unProtect
import org.apache.pdfbox.pdmodel.encryption.BadSecurityHandlerException; //导入依赖的package包/类
@Override
public void unProtect(final String inputUri, final String outputUri, final String password)
throws IOException, COSVisitorException, BadSecurityHandlerException,
CryptographyException {
if (StringUtils.isNotBlank(inputUri) && StringUtils.isNotBlank(outputUri)
&& StringUtils.isNotBlank(password)) {
final PDDocument doc = PDDocument.load(inputUri);
final DecryptionMaterial decryptionMaterial = new StandardDecryptionMaterial(password);
doc.openProtection(decryptionMaterial);
final StandardProtectionPolicy pp = new StandardProtectionPolicy(null, null,
new AccessPermission());
doc.protect(pp);
doc.save(outputUri);
doc.close();
} else {
throw new IllegalArgumentException(Constants.ILLEGAL_ARGUMENT_EXCEPTION_MESSAGE);
}
}
示例4: doAppend
import org.apache.pdfbox.pdmodel.encryption.BadSecurityHandlerException; //导入依赖的package包/类
private Object doAppend(Exchange exchange) throws IOException, BadSecurityHandlerException, CryptographyException, InvalidPasswordException, COSVisitorException {
LOG.debug("Got {} operation, going to append text to provided pdf.", pdfConfiguration.getOperation());
String body = exchange.getIn().getBody(String.class);
PDDocument document = exchange.getIn().getHeader(PDF_DOCUMENT_HEADER_NAME, PDDocument.class);
if (document == null) {
throw new IllegalArgumentException(String.format("%s header is expected for append operation",
PDF_DOCUMENT_HEADER_NAME));
}
if (document.isEncrypted()) {
DecryptionMaterial decryptionMaterial = exchange.getIn().getHeader(DECRYPTION_MATERIAL_HEADER_NAME,
DecryptionMaterial.class);
if (decryptionMaterial == null) {
throw new IllegalArgumentException(String.format("%s header is expected for %s operation "
+ "on encrypted document",
DECRYPTION_MATERIAL_HEADER_NAME,
pdfConfiguration.getOperation()));
}
document.openProtection(decryptionMaterial);
document.setAllSecurityToBeRemoved(true);
}
ProtectionPolicy protectionPolicy = exchange.getIn().getHeader(
PROTECTION_POLICY_HEADER_NAME, ProtectionPolicy.class);
appendToPdfDocument(body, document, protectionPolicy);
OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
document.save(byteArrayOutputStream);
return byteArrayOutputStream;
}
示例5: doCreate
import org.apache.pdfbox.pdmodel.encryption.BadSecurityHandlerException; //导入依赖的package包/类
private OutputStream doCreate(Exchange exchange) throws IOException, BadSecurityHandlerException, COSVisitorException {
LOG.debug("Got {} operation, going to create and write provided string to pdf document.",
pdfConfiguration.getOperation());
String body = exchange.getIn().getBody(String.class);
PDDocument document = new PDDocument();
StandardProtectionPolicy protectionPolicy = exchange.getIn().getHeader(
PROTECTION_POLICY_HEADER_NAME, StandardProtectionPolicy.class);
appendToPdfDocument(body, document, protectionPolicy);
OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
document.save(byteArrayOutputStream);
return byteArrayOutputStream;
}
示例6: appendToPdfDocument
import org.apache.pdfbox.pdmodel.encryption.BadSecurityHandlerException; //导入依赖的package包/类
private void appendToPdfDocument(String text, PDDocument document, ProtectionPolicy protectionPolicy) throws IOException, BadSecurityHandlerException {
Collection<String> words = splitStrategy.split(text);
Collection<String> lines = lineBuilderStrategy.buildLines(words);
writeStrategy.write(lines, document);
if (protectionPolicy != null) {
document.protect(protectionPolicy);
}
}
示例7: decryptPDFN
import org.apache.pdfbox.pdmodel.encryption.BadSecurityHandlerException; //导入依赖的package包/类
public static void decryptPDFN(PDDocument document, String password) throws
IOException, CryptographyException, BadSecurityHandlerException {
if (document.isEncrypted()) {
DecryptionMaterial decryptionMaterial = new StandardDecryptionMaterial(password);
document.openProtection(decryptionMaterial);
} else {
throw new RuntimeException("Document not encrypted");
}
}
示例8: loadWithAutomaticDecryption
import org.apache.pdfbox.pdmodel.encryption.BadSecurityHandlerException; //导入依赖的package包/类
public static PDDocument loadWithAutomaticDecryption(InputStream inputStream) throws IOException {
PDDocument doc = PDDocument.load(inputStream);
if (doc.isEncrypted()) {
// try the empty string as user password
StandardDecryptionMaterial sdm = new StandardDecryptionMaterial("");
try {
doc.openProtection(sdm);
} catch (BadSecurityHandlerException | CryptographyException e) {
LOGGER.error("Cannot handle encrypted PDF: " + e.getMessage());
throw new EncryptedPdfsNotSupportedException();
}
}
return doc;
}
示例9: protect
import org.apache.pdfbox.pdmodel.encryption.BadSecurityHandlerException; //导入依赖的package包/类
/**
* This method password protects a PDF document. Parameter inputUri must
* contain the URI where the input PDF is stored. Parameter outputUri
* indicates the URI where resultant PDF must be stored. Parameter password
* contains the new password of the PDF.
*
* @param inputUri
* @param outputUri
* @param password
* @throws IOException
* @throws BadSecurityHandlerException
* @throws COSVisitorException
*/
public void protect(String inputUri, String outputUri, String password) throws IOException,
BadSecurityHandlerException, COSVisitorException;
示例10: unProtect
import org.apache.pdfbox.pdmodel.encryption.BadSecurityHandlerException; //导入依赖的package包/类
/**
* This method eliminates password protection into a PDF document. Parameter
* inputUri must contain the URI where the input PDF is stored. Parameter
* outputUri indicates the URI where resultant PDF must be stored. Parameter
* password contains the current password of the PDF.
*
* @param inputUri
* @param outputUri
* @param password
* @throws IOException
* @throws COSVisitorException
* @throws CryptographyException
* @throws BadSecurityHandlerException
*/
public void unProtect(String inputUri, String outputUri, String password) throws IOException,
COSVisitorException, BadSecurityHandlerException, CryptographyException;