java源码pdf_pddocument.java 源代码在线查看 - 非常有用的操作pdf文件的java源码 资源下载 虫虫电子下载站...

} } return documentCatalog; } /** * This will tell if this document is encrypted or not. * * @return true If this document is encrypted. */ public boolean isEncrypted() { return document.isEncrypted(); } /** * This will get the encryption dictionary for this document. This will still * return the parameters if the document was decrypted. If the document was * never encrypted then this will return null. As the encryption architecture * in PDF documents is plugable this returns an abstract class, but the only * supported subclass at this time is a PDStandardEncryption object. * * @return The encryption dictionary(most likely a PDStandardEncryption object) * * @throws IOException If there is an error determining which security handler to use. */ public PDEncryptionDictionary getEncryptionDictionary() throws IOException { if( encParameters == null ) { if( isEncrypted() ) { encParameters = new PDEncryptionDictionary(document.getEncryptionDictionary()); } else { encParameters = new PDEncryptionDictionary(); } } return encParameters; } /** * This will set the encryption dictionary for this document. * * @param encDictionary The encryption dictionary(most likely a PDStandardEncryption object) * * @throws IOException If there is an error determining which security handler to use. */ public void setEncryptionDictionary( PDEncryptionDictionary encDictionary ) throws IOException { encParameters = encDictionary; } /** * This will determine if this is the user password. This only applies when * the document is encrypted and uses standard encryption. * * @param password The plain text user password. * * @return true If the password passed in matches the user password used to encrypt the document. * * @throws IOException If there is an error determining if it is the user password. * @throws CryptographyException If there is an error in the encryption algorithms. * * @deprecated */ public boolean isUserPassword( String password ) throws IOException, CryptographyException { return false; /*boolean retval = false; if( password == null ) { password = ""; } PDFEncryption encryptor = new PDFEncryption(); PDEncryptionDictionary encryptionDictionary = getEncryptionDictionary(); if( encryptionDictionary == null ) { throw new IOException( "Error: Document is not encrypted" ); } else { if( encryptionDictionary instanceof PDStandardEncryption ) { COSString documentID = (COSString)document.getDocumentID().get(0); PDStandardEncryption standard = (PDStandardEncryption)encryptionDictionary; retval = encryptor.isUserPassword( password.getBytes(), standard.getUserKey(), standard.getOwnerKey(), standard.getPermissions(), documentID.getBytes(), standard.getRevision(), standard.getLength()/8 ); } else { throw new IOException( "Error: Encyption dictionary is not 'Standard'" + encryptionDictionary.getClass().getName() ); } } return retval;*/ } /** * This will determine if this is the owner password. This only applies when * the document is encrypted and uses standard encryption. * * @param password The plain text owner password. * * @return true If the password passed in matches the owner password used to encrypt the document. * * @throws IOException If there is an error determining if it is the user password. * @throws CryptographyException If there is an error in the encryption algorithms. * * @deprecated */ public boolean isOwnerPassword( String password ) throws IOException, CryptographyException { return false; /*boolean retval = false; if( password == null ) { password = ""; } PDFEncryption encryptor = new PDFEncryption(); PDEncryptionDictionary encryptionDictionary = getEncryptionDictionary(); if( encryptionDictionary == null ) { throw new IOException( "Error: Document is not encrypted" ); } else { if( encryptionDictionary instanceof PDStandardEncryption ) { COSString documentID = (COSString)document.getDocumentID().get( 0 ); PDStandardEncryption standard = (PDStandardEncryption)encryptionDictionary; retval = encryptor.isOwnerPassword( password.getBytes(), standard.getUserKey(), standard.getOwnerKey(), standard.getPermissions(), documentID.getBytes(), standard.getRevision(), standard.getLength()/8 ); } else { throw new IOException( "Error: Encyption dictionary is not 'Standard'" + encryptionDictionary.getClass().getName() ); } } return retval;*/ } /** * This will decrypt a document. This method is provided for compatibility reasons only. User should use * the new security layer instead and the openProtection method especially. * * @param password Either the user or owner password. * * @throws CryptographyException If there is an error decrypting the document. * @throws IOException If there is an error getting the stream data. * @throws InvalidPasswordException If the password is not a user or owner password. * */ public void decrypt( String password ) throws CryptographyException, IOException, InvalidPasswordException { try { StandardDecryptionMaterial m = new StandardDecryptionMaterial(password); this.openProtection(m); document.dereferenceObjectStreams(); } catch(BadSecurityHandlerException e) { throw new CryptographyException(e); } } /** * This will tell if the document was decrypted with the master password. This * entry is invalid if the PDF was not decrypted. * * @return true if the pdf was decrypted with the master password. * * @deprecated use getCurrentAccessPermission instead */ public boolean wasDecryptedWithOwnerPassword() { return false; } /** * This will mark a document to be encrypted. The actual encryption * will occur when the document is saved. * This method is provided for compatibility reasons only. User should use * the new security layer instead and the openProtection method especially. * * @param ownerPassword The owner password to encrypt the document. * @param userPassword The user password to encrypt the document. * * @throws CryptographyException If an error occurs during encryption. * @throws IOException If there is an error accessing the data. * */ public void encrypt( String ownerPassword, String userPassword ) throws CryptographyException, IOException { try { StandardProtectionPolicy policy = new StandardProtectionPolicy(ownerPassword, userPassword, new AccessPermission()); this.protect(policy); } catch(BadSecurityHandlerException e) { throw new CryptographyException(e); } } /** * The owner password that was passed into the encrypt method. You should * never use this method. This will not longer be valid once encryption * has occured. * * @return The owner password passed to the encrypt method. * * @deprecated Do not rely on this method anymore. */ public String getOwnerPasswordForEncryption() { return null; } /** * The user password that was passed into the encrypt method. You should * never use this method. This will not longer be valid once encryption * has occured. * * @return The user password passed to the encrypt method. * * @deprecated Do not rely on this method anymore. */ public String getUserPasswordForEncryption() { return null; } /** * Internal method do determine if the document will be encrypted when it is saved. * * @return True if encrypt has been called and the document * has not been saved yet. * * @deprecated Do not rely on this method anymore. It is the responsibility of * COSWriter to hold this state */ public boolean willEncryptWhenSaving() { return false; } /** * This shoule only be called by the COSWriter after encryption has completed. * * @deprecated Do not rely on this method anymore. It is the responsability of * COSWriter to hold this state. */ public void clearWillEncryptWhenSaving() { //method is deprecated. } /** * This will load a document from a url. * * @param url The url to load the PDF from. * * @return The document that was loaded. * * @throws IOException If there is an error reading from the stream. */ public static PDDocument load( URL url ) throws IOException { return load( url.openStream() ); } /** * This will load a document from a url. * * @param url The url to load the PDF from. * @param scratchFile A location to store temp PDFBox data for this document. * * @return The document that was loaded. * * @throws IOException If there is an error reading from the stream. */ public static PDDocument load( URL url, RandomAccess scratchFile ) throws IOException { return load( url.openStream(), scratchFile ); } /** * This will load a document from a file. * * @param filename The name of the file to load. * * @return The document that was loaded. * * @throws IOException If there is an error reading from the stream. */

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值