Package com.sun.pdfview

Examples of com.sun.pdfview.PDFObject


 
  private void parseAP(PDFObject dictRef) throws IOException {
    if(dictRef == null) {
      return;
    }
    PDFObject normalAP = dictRef.getDictRef("N");
    if(normalAP == null) {
      return;
    }
    cmd = parseCommand(normalAP);
  }
View Full Code Here


          PDFImage img = PDFImage.createImage(obj, new HashMap<String, PDFObject>() , false);         
          result.add(PDFPage.createImageCmd(img));
        } else if (type.equals("Form")) {
         
            // rats.  parse it.
            PDFObject bobj = obj.getDictRef("BBox");
            Float bbox = new Rectangle2D.Float(bobj.getAt(0).getFloatValue(),
                    bobj.getAt(1).getFloatValue(),
                    bobj.getAt(2).getFloatValue(),
                    bobj.getAt(3).getFloatValue());
            PDFPage formCmds = new PDFPage(bbox, 0);
            // stamp annotation transformation
            AffineTransform rectAt = getPositionTransformation();
            formCmds.addXform(rectAt);

            // form transformation
            AffineTransform at;
            PDFObject matrix = obj.getDictRef("Matrix");
            if (matrix == null) {
                at = new AffineTransform();
            } else {
                float elts[] = new float[6];
                for (int i = 0; i < elts.length; i++) {
                    elts[i] = (matrix.getAt(i)).getFloatValue();
                }
                at = new AffineTransform(elts);
            }
            formCmds.addXform(at);
           
            HashMap<String,PDFObject> r = new HashMap<String,PDFObject>(new HashMap<String, PDFObject>());
            PDFObject rsrc = obj.getDictRef("Resources");
            if (rsrc != null) {
                r.putAll(rsrc.getDictionary());
            }

            PDFParser form = new PDFParser(formCmds, obj.getStream(), r);
            form.go(true);
View Full Code Here

   * @throws IOException
   ************************************************************************/
  public LinkAnnotation(PDFObject annotObject) throws IOException {
    super(annotObject, ANNOTATION_TYPE.LINK);
    // a link annotation can either have an action (GoTo or URI) or a destination (DEST)
    PDFObject actionObj = annotObject.getDictRef("A");
    if (actionObj != null) {
      this.action = PDFAction.getAction(actionObj, annotObject.getRoot());
    } else {
      // if a destination is given, create a GoToAction from it
      PDFObject dest = annotObject.getDictRef("Dest");
      if(dest == null) {
        dest = annotObject.getDictRef("DEST");
      }
      if (dest != null) {
        this.action = new GoToAction(PDFDestination.getDestination(dest, annotObject.getRoot()));
View Full Code Here

 
  private void parseAP(PDFObject dictRef) throws IOException {
    if(dictRef == null) {
      return;
    }
    PDFObject normalAP = dictRef.getDictRef("N");
    if(normalAP == null) {
      return;
    }
    if(normalAP.getType() == PDFObject.DICTIONARY) {
      this.onAppearance = normalAP.getDictRef("On");
      this.offAppearance = normalAP.getDictRef("Off");
      PDFObject as = dictRef.getDictRef("AS");     
      this.appearanceStateOn = (as != null) && ("On".equals(as.getStringValue()));
    }else {
      this.onAppearance = normalAP;
      this.offAppearance = null;
      appearanceStateOn = true;
    }
View Full Code Here

          PDFImage img = PDFImage.createImage(obj, new HashMap<String, PDFObject>() , false);         
          result.add(PDFPage.createImageCmd(img));
        } else if (type.equals("Form")) {
         
            // rats.  parse it.
            PDFObject bobj = obj.getDictRef("BBox");
            Float bbox = new Rectangle2D.Float(bobj.getAt(0).getFloatValue(),
                    bobj.getAt(1).getFloatValue(),
                    bobj.getAt(2).getFloatValue(),
                    bobj.getAt(3).getFloatValue());
            PDFPage formCmds = new PDFPage(bbox, 0);
            // stamp annotation transformation
            AffineTransform rectAt = getPositionTransformation();
            formCmds.addXform(rectAt);

            // form transformation
            AffineTransform at;
            PDFObject matrix = obj.getDictRef("Matrix");
            if (matrix == null) {
                at = new AffineTransform();
            } else {
                float elts[] = new float[6];
                for (int i = 0; i < elts.length; i++) {
                    elts[i] = (matrix.getAt(i)).getFloatValue();
                }
                at = new AffineTransform(elts);
            }
            formCmds.addXform(at);
           
            HashMap<String,PDFObject> r = new HashMap<String,PDFObject>(new HashMap<String, PDFObject>());
            PDFObject rsrc = obj.getDictRef("Resources");
            if (rsrc != null) {
                r.putAll(rsrc.getDictionary());
            }

            PDFParser form = new PDFParser(formCmds, obj.getStream(), r);
            form.go(true);
View Full Code Here

   * @param parent
   * @return PDFAnnotation
   * @throws IOException
   ************************************************************************/
  public static PDFAnnotation createAnnotation(PDFObject parent) throws IOException{
    PDFObject subtypeValue = parent.getDictRef("Subtype");
    if(subtypeValue == null) {
      return null;
    }     
    String subtypeS = subtypeValue.getStringValue();
   
    ANNOTATION_TYPE annotationType = ANNOTATION_TYPE.getByDefinition(subtypeS);
    Class<?> className = annotationType.getClassName();
   
    Constructor<?> constructor;
View Full Code Here

     * @param obj a PDFObject that represents an Array of exactly four
     * Numbers.
     */
    public Rectangle2D.Float parseRect(PDFObject obj) throws IOException {
        if (obj.getType() == PDFObject.ARRAY) {
            PDFObject bounds[] = obj.getArray();
            if (bounds.length == 4) {
                return new Rectangle2D.Float(bounds[0].getFloatValue(),
                        bounds[1].getFloatValue(),
                        bounds[2].getFloatValue() - bounds[0].getFloatValue(),
                        bounds[3].getFloatValue() - bounds[1].getFloatValue());
View Full Code Here

        if (encryptDict == null) {
            // No encryption specified
            return IdentityDecrypter.getInstance();
        } else {
            PDFObject filter = encryptDict.getDictRef("Filter");
            // this means that we'll fail if, for example, public key
            // encryption is employed
            if (filter != null && "Standard".equals(filter.getStringValue())) {
                final PDFObject vObj = encryptDict.getDictRef("V");
                int v = vObj != null ? vObj.getIntValue() : 0;
                if (v == 1 || v == 2) {
                    final PDFObject lengthObj =
                            encryptDict.getDictRef("Length");
                    final Integer length =
                            lengthObj != null ? lengthObj.getIntValue() : null;
                    return createStandardDecrypter(
                            encryptDict, documentId, password, length, false,
                            StandardDecrypter.EncryptionAlgorithm.RC4);
                } else if (v == 4) {
                    return createCryptFilterDecrypter(
View Full Code Here

        // encryptMetadata is true if not present. Note that we don't actually
        // use this to change our reading of metadata streams (that's all done
        // internally by the document specifying a Crypt filter of None if
        // appropriate), but it does affect the encryption key.
        boolean encryptMetadata = true;
        final PDFObject encryptMetadataObj =
                encryptDict.getDictRef("EncryptMetadata");
        if (encryptMetadataObj != null
                && encryptMetadataObj.getType() == PDFObject.BOOLEAN) {
            encryptMetadata = encryptMetadataObj.getBooleanValue();
        }

        // Assemble decrypters for each filter in the
        // crypt filter (CF) dictionary
        final Map<String, PDFDecrypter> cfDecrypters =
                new HashMap<String, PDFDecrypter>();
        final PDFObject cfDict = encryptDict.getDictRef("CF");
        if (cfDict == null) {
            throw new PDFParseException(
                    "No CF value present in Encrypt dict for V4 encryption");
        }
        final Iterator<String> cfNameIt = cfDict.getDictKeys();
        while (cfNameIt.hasNext()) {
            final String cfName = cfNameIt.next();
            final PDFObject cryptFilter = cfDict.getDictRef(cfName);

            final PDFObject lengthObj = cryptFilter.getDictRef("Length");
            // The Errata for PDF 1.7 explains that the value of
            // Length in CF dictionaries is in bytes
            final Integer length = lengthObj != null ?
                    lengthObj.getIntValue() * 8 : null;

            // CFM is the crypt filter method, describing whether RC4,
            // AES, or None (i.e., identity) is the encryption mechanism
            // used for the name crypt filter
            final PDFObject cfmObj = cryptFilter.getDictRef("CFM");
            final String cfm = cfmObj != null ?
                    cfmObj.getStringValue() : "None";
            final PDFDecrypter cfDecrypter;
            if ("None".equals(cfm)) {
                cfDecrypter = IdentityDecrypter.getInstance();
            } else if ("V2".equals(cfm)) {
                cfDecrypter = createStandardDecrypter(
                        encryptDict, documentId, password, length,
                        encryptMetadata,
                        StandardDecrypter.EncryptionAlgorithm.RC4);
            } else if ("AESV2".equals(cfm)) {
                cfDecrypter = createStandardDecrypter(
                        encryptDict, documentId, password, length,
                        encryptMetadata,
                        StandardDecrypter.EncryptionAlgorithm.AESV2);
            } else {
                throw new UnsupportedOperationException(
                        "Unknown CryptFilter method: " + cfm);
            }
            cfDecrypters.put(cfName, cfDecrypter);
        }

        // always put Identity in last so that it will override any
        // Identity filter sneakily declared in the CF entry
        cfDecrypters.put(CF_IDENTITY, IdentityDecrypter.getInstance());

        PDFObject stmFObj = encryptDict.getDictRef("StmF");
        final String defaultStreamFilter =
                stmFObj != null ? stmFObj.getStringValue() : CF_IDENTITY;

        PDFObject strFObj = encryptDict.getDictRef("StrF");
        final String defaultStringFilter =
                strFObj != null ? strFObj.getStringValue() : CF_IDENTITY;

        return new CryptFilterDecrypter(
                cfDecrypters, defaultStreamFilter, defaultStringFilter);

    }
View Full Code Here

        if (keyLength == null) {
            keyLength = DEFAULT_KEY_LENGTH;
        }

        // R describes the revision of the security handler
        final PDFObject rObj = encryptDict.getDictRef("R");
        if (rObj == null) {
            throw new PDFParseException(
                    "No R entry present in Encrypt dictionary");
        }

        final int revision = rObj.getIntValue();
        if (revision < 2 || revision > 4) {
            throw new EncryptionUnsupportedByPlatformException(
                    "Unsupported Standard security handler revision; R=" +
                            revision);
        }

        // O describes validation details for the owner key
        final PDFObject oObj = encryptDict.getDictRef("O");
        if (oObj == null) {
            throw new PDFParseException(
                    "No O entry present in Encrypt dictionary");
        }
        final byte[] o = oObj.getStream();
        if (o.length != 32) {
            throw new PDFParseException("Expected owner key O " +
                    "value of 32 bytes; found " + o.length);
        }

        // U describes validation details for the user key
        final PDFObject uObj = encryptDict.getDictRef("U");
        if (uObj == null) {
            throw new PDFParseException(
                    "No U entry present in Encrypt dictionary");
        }
        final byte[] u = uObj.getStream();
        if (u.length != 32) {
            throw new PDFParseException(
                    "Expected user key U value of 32 bytes; found " + o.length);
        }

        // P describes the permissions regarding document usage
        final PDFObject pObj = encryptDict.getDictRef("P");
        if (pObj == null) {
            throw new PDFParseException(
                    "Required P entry in Encrypt dictionary not found");
        }

        return new StandardDecrypter(
                encryptionAlgorithm, documentId, keyLength,
                revision, o, u, pObj.getIntValue(), encryptMetadata, password);
    }
View Full Code Here

TOP

Related Classes of com.sun.pdfview.PDFObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.