1 17 18 19 20 package org.apache.fop.pdf; 21 22 import java.text.MessageFormat ; 23 24 32 public class PDFProfile { 33 34 38 protected PDFAMode pdfAMode = PDFAMode.DISABLED; 39 40 44 protected PDFXMode pdfXMode = PDFXMode.DISABLED; 45 46 private PDFDocument doc; 47 48 52 public PDFProfile(PDFDocument doc) { 53 this.doc = doc; 54 } 55 56 59 protected void validateProfileCombination() { 60 if (pdfAMode != PDFAMode.DISABLED) { 61 if (pdfAMode == PDFAMode.PDFA_1A) { 62 throw new UnsupportedOperationException ("PDF/A-1a is not implemented, yet"); 63 } 64 if (pdfAMode == PDFAMode.PDFA_1B) { 65 if (pdfXMode != PDFXMode.DISABLED && pdfXMode != PDFXMode.PDFX_3_2003) { 66 throw new PDFConformanceException( 67 pdfAMode + " and " + pdfXMode + " are not compatible!"); 68 } 69 } 70 } 71 } 72 73 74 public PDFDocument getDocument() { 75 return this.doc; 76 } 77 78 79 public PDFAMode getPDFAMode() { 80 return this.pdfAMode; 81 } 82 83 84 public boolean isPDFAActive() { 85 return getPDFAMode() != PDFAMode.DISABLED; 86 } 87 88 92 public void setPDFAMode(PDFAMode mode) { 93 if (mode == null) { 94 mode = PDFAMode.DISABLED; 95 } 96 this.pdfAMode = mode; 97 validateProfileCombination(); 98 } 99 100 101 public PDFXMode getPDFXMode() { 102 return this.pdfXMode; 103 } 104 105 106 public boolean isPDFXActive() { 107 return getPDFXMode() != PDFXMode.DISABLED; 108 } 109 110 114 public void setPDFXMode(PDFXMode mode) { 115 if (mode == null) { 116 mode = PDFXMode.DISABLED; 117 } 118 this.pdfXMode = mode; 119 validateProfileCombination(); 120 } 121 122 123 public String toString() { 124 StringBuffer sb = new StringBuffer (); 125 if (isPDFAActive() && isPDFXActive()) { 126 sb.append("[").append(getPDFAMode()).append(",").append(getPDFXMode()).append("]"); 127 } else if (isPDFAActive()) { 128 sb.append(getPDFAMode()); 129 } else if (isPDFXActive()) { 130 sb.append(getPDFXMode()); 131 } else { 132 sb.append(super.toString()); 133 } 134 return sb.toString(); 135 } 136 137 139 private String format(String pattern, Object arg) { 140 return MessageFormat.format(pattern, new Object [] {arg}); 141 } 142 143 144 public void verifyEncryptionAllowed() { 145 final String err = "{0} doesn't allow encrypted PDFs"; 146 if (isPDFAActive()) { 147 throw new PDFConformanceException(format(err, getPDFAMode())); 148 } 149 if (isPDFXActive()) { 150 throw new PDFConformanceException(format(err, getPDFXMode())); 151 } 152 } 153 154 155 public void verifyPSXObjectsAllowed() { 156 final String err = "PostScript XObjects are prohibited when {0}" 157 + " is active. Convert EPS graphics to another format."; 158 if (isPDFAActive()) { 159 throw new PDFConformanceException(format(err, getPDFAMode())); 160 } 161 if (isPDFXActive()) { 162 throw new PDFConformanceException(format(err, getPDFXMode())); 163 } 164 } 165 166 170 public void verifyTransparencyAllowed(String context) { 171 final String err = "{0} does not allow the use of transparency. ({1})"; 172 if (isPDFAActive()) { 173 throw new PDFConformanceException(MessageFormat.format(err, 174 new Object [] {getPDFAMode(), context})); 175 } 176 if (isPDFXActive()) { 177 throw new PDFConformanceException(MessageFormat.format(err, 178 new Object [] {getPDFXMode(), context})); 179 } 180 } 181 182 183 public void verifyPDFVersion() { 184 final String err = "PDF version must be 1.4 for {0}"; 185 if (getPDFAMode().isPDFA1LevelB() 186 && getDocument().getPDFVersion() != PDFDocument.PDF_VERSION_1_4) { 187 throw new PDFConformanceException(format(err, getPDFAMode())); 188 } 189 if (getPDFXMode() == PDFXMode.PDFX_3_2003 190 && getDocument().getPDFVersion() != PDFDocument.PDF_VERSION_1_4) { 191 throw new PDFConformanceException(format(err, getPDFXMode())); 192 } 193 } 194 195 196 public boolean isIDEntryRequired() { 197 return isPDFAActive() || isPDFXActive(); 198 } 199 200 201 public boolean isFontEmbeddingRequired() { 202 return isPDFAActive() || isPDFXActive(); 203 } 204 205 206 public void verifyTitleAbsent() { 207 if (isPDFXActive()) { 208 final String err = "{0} requires the title to be set."; 209 throw new PDFConformanceException(format(err, getPDFXMode())); 210 } 211 } 212 213 214 public boolean isModDateRequired() { 215 return getPDFXMode() == PDFXMode.PDFX_3_2003; 216 } 217 218 219 public boolean isTrappedEntryRequired() { 220 return getPDFXMode() == PDFXMode.PDFX_3_2003; 221 } 222 223 224 public boolean isAnnotationAllowed() { 225 return !isPDFXActive(); 226 } 227 228 229 public void verifyAnnotAllowed() { 230 if (!isAnnotationAllowed()) { 231 final String err = "{0} does not allow annotations inside the printable area."; 232 throw new PDFConformanceException(format(err, getPDFXMode())); 234 } 235 } 236 237 238 public void verifyActionAllowed() { 239 if (isPDFXActive()) { 240 final String err = "{0} does not allow Actions."; 241 throw new PDFConformanceException(format(err, getPDFXMode())); 242 } 243 } 244 245 } 246 | Popular Tags |