/** * This will get the encryption dictionary for this document. This will still return the parameters if the document * was decrypted. 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) */ public PDEncryption getEncryption() { if (encryption == null && isEncrypted()) { encryption = new PDEncryption(document.getEncryptionDictionary()); } return encryption; }
if( document.isEncrypted() )
if (document.isEncrypted())
/** * This will print the documents data. * * @param args The command line arguments. * * @throws IOException If there is an error parsing the document. */ public static void main( String[] args ) throws IOException { if( args.length != 2 ) { usage(); } else { try (PDDocument document = PDDocument.load(new File(args[0]))) { PDActionJavaScript javascript = new PDActionJavaScript( "app.alert( {cMsg: 'PDFBox rocks!', nIcon: 3, nType: 0, cTitle: 'PDFBox Javascript example' } );"); document.getDocumentCatalog().setOpenAction( javascript ); if( document.isEncrypted() ) { throw new IOException( "Encrypted documents are not supported for this example" ); } document.save( args[1] ); } } }
if (!isEncrypted())
import org.apache.pdfbox.exceptions.COSVisitorException; import org.apache.pdfbox.exceptions.CryptographyException; import org.apache.pdfbox.exceptions.InvalidPasswordException; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDResources; import java.io.IOException; public class Main { public static void main(String[] argv) throws COSVisitorException, InvalidPasswordException, CryptographyException, IOException { PDDocument document = PDDocument.load("input.pdf"); if (document.isEncrypted()) { document.decrypt(""); } PDDocumentCatalog catalog = document.getDocumentCatalog(); for (Object pageObj : catalog.getAllPages()) { PDPage page = (PDPage) pageObj; PDResources resources = page.findResources(); resources.getImages().clear(); } document.save("strippedOfImages.pdf"); } }
if( !document.isEncrypted() )
if( document.isEncrypted() )
if (document.isEncrypted())
if( document.isEncrypted() )
if (document.isEncrypted())
if (document.isEncrypted())
pdfDocument = PDDocument.load(new CloseShieldInputStream(stream), password, memoryUsageSetting); metadata.set(PDF.IS_ENCRYPTED, Boolean.toString(pdfDocument.isEncrypted()));
if( document.isEncrypted() )
PDDocument pdfDoc = PDDocument.load(new File("path/to/pdf")); boolean hasOwnerPwd = false; boolean hasUserPwd = false; if(pdfDoc.isEncrypted()){ hasOwnerPwd = true; try{ StandardDecryptionMaterial sdm = new StandardDecryptionMaterial(null); pdfDoc.openProtection(sdm); hasUserPwd = true; } catch(Exception e){ // handle exception } }
/** * This will get the encryption dictionary for this document. This will still return the parameters if the document * was decrypted. 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) */ public PDEncryption getEncryption() { if (encryption == null && isEncrypted()) { encryption = new PDEncryption(document.getEncryptionDictionary()); } return encryption; }
try { PDDocument document = null; document = PDDocument.load(new File("test.pdf")); document.getClass(); if (!document.isEncrypted()) { PDFTextStripperByArea stripper = new PDFTextStripperByArea(); stripper.setSortByPosition(true); PDFTextStripper Tstripper = new PDFTextStripper(); String st = Tstripper.getText(document); System.out.println("Text:" + st); } } catch (Exception e) { e.printStackTrace(); }
try{ PDDocument document = null; document = PDDocument.load(new File("test.pdf")); document.getClass(); if( !document.isEncrypted() ){ PDFTextStripperByArea stripper = new PDFTextStripperByArea(); stripper.setSortByPosition( true ); PDFTextStripper Tstripper = new PDFTextStripper(); String st = Tstripper.getText(document); System.out.println("Text:"+st); } }catch(Exception e){ e.printStackTrace(); }
private void openPDFDoc(final File pdfFile) throws Exception { File originalPDF = pdfFile; PDFParser parser = new PDFParser(new BufferedInputStream(new FileInputStream( originalPDF))); parser.parse(); PDDocument originialPdfDoc = parser.getPDDocument(); boolean isOriginalDocEncrypted = originialPdfDoc.isEncrypted(); if (isOriginalDocEncrypted) { originialPdfDoc.openProtection(new StandardDecryptionMaterial("password")); } }
PDDocument document = PDDocument.load( args[0] ); if( document.isEncrypted() ) { document.decrypt( "" ); } PDFTextStripperByArea stripper = new PDFTextStripperByArea(); stripper.setSortByPosition( true ); Rectangle rect = new Rectangle( 10, 280, 275, 60 ); stripper.addRegion( "class1", rect ); List allPages = document.getDocumentCatalog().getAllPages(); PDPage firstPage = (PDPage)allPages.get( 0 ); stripper.extractRegions( firstPage ); System.out.println( "Text in the area:" + rect ); System.out.println( stripper.getTextForRegion( "class1" ) );