1 31 package org.pdfbox.examples.pdmodel; 32 33 import org.pdfbox.pdmodel.PDDocument; 34 import org.pdfbox.pdmodel.PDPage; 35 import org.pdfbox.pdmodel.common.PDRectangle; 36 import org.pdfbox.pdmodel.interactive.annotation.PDAnnotationRubberStamp; 37 38 import java.io.IOException ; 39 import java.util.ArrayList ; 40 import java.util.List ; 41 42 48 public class RubberStamp 49 { 50 private RubberStamp() 51 { 52 } 54 55 62 public static void main( String [] args ) throws Exception 63 { 64 if( args.length != 2 ) 65 { 66 usage(); 67 } 68 else 69 { 70 PDDocument document = null; 71 try 72 { 73 document = PDDocument.load( args[0] ); 74 if( document.isEncrypted() ) 75 { 76 throw new IOException ( "Encrypted documents are not supported for this example" ); 77 } 78 List allpages = new ArrayList (); 79 document.getDocumentCatalog().getPages().getAllKids(allpages); 80 81 for (int i=0; i < allpages.size(); i++) 82 { 83 PDPage apage = (PDPage) allpages.get(i); 84 List annotations = apage.getAnnotations(); 85 86 PDAnnotationRubberStamp rs = new PDAnnotationRubberStamp(); 87 rs.setName(PDAnnotationRubberStamp.NAME_TOP_SECRET); 88 rs.setRectangle(new PDRectangle(100,100)); 89 rs.setContents("A top secret note"); 90 91 annotations.add(rs); 92 } 93 94 document.save( args[1] ); 95 } 96 finally 97 { 98 if( document != null ) 99 { 100 document.close(); 101 } 102 } 103 } 104 } 105 106 109 private static void usage() 110 { 111 System.err.println( "Usage: java org.pdfbox.examples.pdmodel.RubberStamp <input-pdf> <output-pdf>" ); 112 } 113 } | Popular Tags |