1 3 import org.faceless.pdf2.*; 4 import java.io.*; 5 import java.awt.Color ; 6 import java.util.List ; 7 8 public class Stamp 23 { 24 static PDFStyle stampstyle; 25 26 public static void main(String [] args) throws IOException 27 { 28 if (args.length==0) { 29 System.err.println("Usage: java Stamp <filename.pdf>"); 30 System.err.println(" Creates the file \"Stamp.pdf\""); 31 System.exit(0); 32 } 33 34 initstamp1(); 37 41 42 InputStream in = new FileInputStream(args[0]); 44 PDF pdf = new PDF(new PDFReader(in)); 45 in.close(); 46 47 List pages = pdf.getPages(); 49 for (int i=0;i<pages.size();i++) { 50 PDFPage page = (PDFPage)pages.get(i); 51 52 float midx = page.getWidth()/2; float midy = page.getHeight()/1.3f; 55 stamp1(page, midx, midy); 59 } 63 64 pdf.render(new FileOutputStream("Stamp.pdf")); 65 } 66 67 static void initstamp1() 88 { 89 } 90 91 static void stamp1(PDFPage page, float midx, float midy) 92 { 93 AnnotationStamp stamp = new AnnotationStamp("stamp.stencil.Confidential", 0.35f); 94 stamp.setReadOnly(true); 95 float w = stamp.getRecommendedWidth(); 96 float h = stamp.getRecommendedHeight(); 97 stamp.setRectangle(midx-(w/2), midy-(h/2), midx+(w/2), midy+(h/2)); 98 page.getAnnotations().add(stamp); 99 } 100 101 102 static void initstamp2() 114 { 115 stampstyle = new PDFStyle(); 116 stampstyle.setFont(new StandardFont(StandardFont.COURIERBOLD), 60); 117 stampstyle.setTextAlign(PDFStyle.TEXTALIGN_CENTER); 118 stampstyle.setFillColor(new Color (255, 210, 210)); 119 } 120 121 static void stamp2(PDFPage page, float midx, float midy) 122 { 123 page.seekStart(); page.setStyle(stampstyle); 125 page.rotate(midx, midy, -20); 126 page.drawText("Confidential", midx, midy); 127 } 128 129 130 static void initstamp3() 144 { 145 stampstyle = new PDFStyle(); 146 stampstyle.setFont(new StandardFont(StandardFont.COURIERBOLD), 60); 147 stampstyle.setTextAlign(PDFStyle.TEXTALIGN_CENTER); 148 stampstyle.setLineColor(new Color (0x00FF0000)); 149 stampstyle.setFontStyle(PDFStyle.FONTSTYLE_OUTLINE); } 151 152 static void stamp3(PDFPage page, float midx, float midy) 153 { 154 page.save(); 155 page.setStyle(stampstyle); 156 page.rotate(midx, midy, -20); 157 page.drawText("Confidential", midx, midy); 158 page.restore(); 159 } 160 161 162 static void initstamp4() 173 { 174 stampstyle = new PDFStyle(); 175 stampstyle.setFont(new StandardFont(StandardFont.COURIERBOLD), 60); 176 stampstyle.setTextAlign(PDFStyle.TEXTALIGN_CENTER); 177 stampstyle.setFillColor(new Color (0x80FF0000, true)); } 179 180 static void stamp4(PDFPage page, float midx, float midy) 181 { 182 page.save(); 183 page.setStyle(stampstyle); 184 page.rotate(midx, midy, -20); 185 page.drawText("Confidential", midx, midy); 186 page.restore(); 187 } 188 } 189 | Popular Tags |