1 52 53 package com.lowagie.text.pdf; 54 55 import java.io.IOException ; 56 import java.io.PrintStream ; 57 import java.util.Iterator ; 58 62 63 public class PdfLister { 64 65 66 PrintStream out; 67 68 72 public PdfLister(PrintStream out) { 73 this.out = out; 74 } 75 76 80 public void listAnyObject(PdfObject object) 81 { 82 switch (object.type()) { 83 case PdfObject.ARRAY: 84 listArray((PdfArray)object); 85 break; 86 case PdfObject.DICTIONARY: 87 listDict((PdfDictionary) object); 88 break; 89 case PdfObject.STRING: 90 out.println("(" + object.toString() + ")"); 91 break; 92 default: 93 out.println(object.toString()); 94 break; 95 } 96 } 97 101 public void listDict(PdfDictionary dictionary) 102 { 103 out.println("<<"); 104 PdfName key; 105 PdfObject value; 106 for (Iterator i = dictionary.getKeys().iterator(); i.hasNext(); ) { 107 key = (PdfName) i.next(); 108 value = dictionary.get(key); 109 out.print(key.toString()); 110 out.print(' '); 111 listAnyObject(value); 112 } 113 out.println(">>"); 114 } 115 116 120 public void listArray(PdfArray array) 121 { 122 out.println('['); 123 for (Iterator i = array.getArrayList().iterator(); i.hasNext(); ) { 124 PdfObject item = (PdfObject)i.next(); 125 listAnyObject(item); 126 } 127 out.println(']'); 128 } 129 134 public void listStream(PRStream stream, PdfReaderInstance reader) 135 { 136 try { 137 listDict(stream); 138 out.println("startstream"); 139 byte[] b = PdfReader.getStreamBytes(stream); 140 int len = b.length - 1; 150 for (int k = 0; k < len; ++k) { 151 if (b[k] == '\r' && b[k + 1] != '\n') 152 b[k] = (byte)'\n'; 153 } 154 out.println(new String (b)); 155 out.println("endstream"); 156 } catch (IOException e) { 157 System.err.println("I/O exception: " + e); 158 } 161 } 162 166 public void listPage(PdfImportedPage iPage) 167 { 168 int pageNum = iPage.getPageNumber(); 169 PdfReaderInstance readerInst = iPage.getPdfReaderInstance(); 170 PdfReader reader = readerInst.getReader(); 171 172 PdfDictionary page = reader.getPageN(pageNum); 173 listDict(page); 174 PdfObject obj = PdfReader.getPdfObject(page.get(PdfName.CONTENTS)); 175 if (obj == null) 176 return; 177 switch (obj.type) { 178 case PdfObject.STREAM: 179 listStream((PRStream)obj, readerInst); 180 break; 181 case PdfObject.ARRAY: 182 for (Iterator i = ((PdfArray)obj).getArrayList().iterator(); i.hasNext();) { 183 PdfObject o = PdfReader.getPdfObject((PdfObject)i.next()); 184 listStream((PRStream)o, readerInst); 185 out.println("-----------"); 186 } 187 break; 188 } 189 } 190 } 191 | Popular Tags |