List of usage examples for org.apache.pdfbox.cos COSDocument getObjects
public List<COSObject> getObjects()
From source file:net.padaf.preflight.helpers.FileSpecificationValidationHelper.java
License:Apache License
@Override public List<ValidationError> innerValidate(DocumentHandler handler) throws ValidationException { List<ValidationError> result = new ArrayList<ValidationError>(0); PDDocument pdfDoc = handler.getDocument(); COSDocument cDoc = pdfDoc.getDocument(); List<?> lCOSObj = cDoc.getObjects(); for (Object o : lCOSObj) { COSObject cObj = (COSObject) o;//from w w w. j a va2s .c om // ---- If this object represents a Stream // The Dictionary must contain the Length key COSBase cBase = cObj.getObject(); if (cBase instanceof COSDictionary) { COSDictionary dic = (COSDictionary) cBase; String type = dic.getNameAsString(COSName.getPDFName(DICTIONARY_KEY_TYPE)); if (FILE_SPECIFICATION_VALUE_TYPE.equals(type)) { // ---- It is a file specification result.addAll(validateFileSpecification(handler, cObj)); } } } return result; }
From source file:net.padaf.preflight.helpers.FontValidationHelper.java
License:Apache License
@Override public List<ValidationError> innerValidate(DocumentHandler handler) throws ValidationException { List<ValidationError> result = new ArrayList<ValidationError>(0); PDDocument pdfDoc = handler.getDocument(); COSDocument cDoc = pdfDoc.getDocument(); List<?> lCOSObj = cDoc.getObjects(); List<FontValidator> lType3 = new ArrayList<FontValidator>(); for (Object o : lCOSObj) { COSObject cObj = (COSObject) o;//from www . j a va 2 s. c o m // If this object represents a Stream, the Dictionary must contain the // Length key COSBase cBase = cObj.getObject(); if (cBase instanceof COSDictionary) { COSDictionary dic = (COSDictionary) cBase; String type = dic.getNameAsString(COSName.getPDFName(DICTIONARY_KEY_TYPE)); if (type != null && FONT_DICTIONARY_VALUE_FONT.equals(type)) { FontValidator fontVal = fontValidationFactory.getFontValidator(cObj, handler); if (fontVal instanceof Type3FontValidator) { lType3.add(fontVal); } else { validateFont(handler, fontVal, result); } } } } // ---- Type 3 can contain other font, so type 3 are validated at the end. for (FontValidator t3FontVal : lType3) { validateFont(handler, t3FontVal, result); } return result; }
From source file:net.padaf.preflight.helpers.GraphicsValidationHelper.java
License:Apache License
@Override public List<ValidationError> innerValidate(DocumentHandler handler) throws ValidationException { List<ValidationError> result = new ArrayList<ValidationError>(0); PDDocument pdfDoc = handler.getDocument(); // ---- Checks all XObjects COSDocument cDoc = pdfDoc.getDocument(); List<?> lCOSObj = cDoc.getObjects(); for (Object o : lCOSObj) { COSObject cObj = (COSObject) o;// w w w . j ava 2 s. c o m COSBase cBase = cObj.getObject(); if (cBase instanceof COSDictionary) { COSDictionary dic = (COSDictionary) cBase; String type = dic.getNameAsString(COSName.getPDFName(DICTIONARY_KEY_TYPE)); if (type != null && DICTIONARY_KEY_XOBJECT.equals(type)) { result.addAll(validateXObject(handler, cObj)); } else if (type != null && DICTIONARY_KEY_PATTERN.equals(type)) { result.addAll(validatePattern(handler, cObj)); } } } return result; }
From source file:net.padaf.preflight.helpers.StreamValidationHelper.java
License:Apache License
@Override public List<ValidationError> innerValidate(DocumentHandler handler) throws ValidationException { List<ValidationError> result = new ArrayList<ValidationError>(0); PDDocument pdfDoc = handler.getDocument(); COSDocument cDoc = pdfDoc.getDocument(); List<?> lCOSObj = cDoc.getObjects(); for (Object o : lCOSObj) { COSObject cObj = (COSObject) o;//w ww .j a va 2 s . co m // If this object represents a Stream, the Dictionary must contain the // Length key COSBase cBase = cObj.getObject(); if (cBase instanceof COSStream) { // it is a stream result.addAll(validateStreamObject(handler, cObj)); } } return result; }
From source file:net.padaf.preflight.helpers.TrailerValidationHelper.java
License:Apache License
/** * According to the PDF Reference, A linearized PDF contain a dictionary as * first object (linearized dictionary) and only this one in the first * section.//from w ww . j av a 2 s .c o m * * @param document * @return */ protected COSDictionary isLinearizedPdf(PDDocument document) { // ---- Get Ref to obj COSDocument cDoc = document.getDocument(); List<?> lObj = cDoc.getObjects(); for (Object object : lObj) { COSBase curObj = ((COSObject) object).getObject(); if (curObj instanceof COSDictionary && ((COSDictionary) curObj).keySet().contains(COSName.getPDFName(DICTIONARY_KEY_LINEARIZED))) { return (COSDictionary) curObj; } } return null; }
From source file:org.apache.padaf.preflight.helpers.XRefValidationHelper.java
License:Apache License
@Override public List<ValidationError> innerValidate(DocumentHandler handler) throws ValidationException { List<ValidationError> errors = new ArrayList<ValidationError>(); COSDocument document = handler.getDocument().getDocument(); if (document.getObjects().size() > ValidationConstants.MAX_INDIRECT_OBJ) { errors.add(new ValidationError(ERROR_SYNTAX_INDIRECT_OBJ_RANGE, "Too many indirect objects")); }/*from w ww . j av a 2 s. c om*/ return errors; }
From source file:org.crossref.pdfmark.Main.java
License:Open Source License
/** * According to the PDF Reference Manual (appendix F) a linearized PDF * must have as its first object after the PDF header an indirect * dictionary containing only direct objects. Among these objects one * must be assigned the key "Linearized", representing the linearized PDF * version number./*from w w w . j av a 2 s . c o m*/ * * @return true if the PDF read by reader is a linearized PDF. */ public static boolean isLinearizedPdf(FileInputStream in) throws IOException { boolean isLinear = false; PDFParser parser = new PDFParser(in); parser.parse(); COSDocument doc = parser.getDocument(); for (Object o : doc.getObjects()) { COSObject obj = (COSObject) o; if (obj.getObject() instanceof COSDictionary) { COSDictionary dict = (COSDictionary) obj.getObject(); for (Object key : dict.keyList()) { COSName name = (COSName) key; if ("Linearized".equals(name.getName())) { isLinear = true; break; } } if (isLinear) break; } } doc.close(); return isLinear; }