Package com.sun.pdfview

Examples of com.sun.pdfview.PDFObject


    /** Creates a new instance of PDFDecoder */
    private PDFDecoder() {
    }

    public static boolean isLastFilter(PDFObject dict, Set<String> filters) throws IOException {
        PDFObject filter = dict.getDictRef("Filter");
        if (filter == null) {
            return false;
        } else if (filter.getType() == PDFObject.NAME) {
            return filters.contains(filter.getStringValue());
        } else {
            final PDFObject[] ary = filter.getArray();
            return filters.contains(ary[ary.length - 1].getStringValue());
        }
    }
View Full Code Here


     * @param streamBuf the data in the stream, as a byte buffer
     */
    public static ByteBuffer decodeStream(PDFObject dict, ByteBuffer streamBuf, Set<String> filterLimits)
            throws IOException {

        PDFObject filter = dict.getDictRef("Filter");
        if (filter == null) {
            // just apply default decryption
            return dict.getDecrypter().decryptBuffer(null, dict, streamBuf);
        } else {
            // apply filters
            FilterSpec spec = new FilterSpec(dict, filter);

      // determine whether default encryption applies or if there's a
            // specific Crypt filter; it must be the first filter according to
            // the errata for PDF1.7
            boolean specificCryptFilter =
                    spec.ary.length != 0 && spec.ary[0].getStringValue().equals("Crypt");
            if (!specificCryptFilter) {
                // No Crypt filter, so should apply default decryption (if
                // present!)
                streamBuf = dict.getDecrypter().decryptBuffer(
                        null, dict, streamBuf);
            }

            for (int i = 0; i < spec.ary.length; i++) {
                String enctype = spec.ary[i].getStringValue();
                if (filterLimits.contains(enctype)) {
                    break;
                }
                if (enctype == null) {
                } else if (enctype.equals("FlateDecode") || enctype.equals("Fl")) {
                    streamBuf = FlateDecode.decode(dict, streamBuf, spec.params[i]);
                } else if (enctype.equals("LZWDecode") || enctype.equals("LZW")) {
                    streamBuf = LZWDecode.decode(streamBuf, spec.params[i]);
                } else if (enctype.equals("ASCII85Decode") || enctype.equals("A85")) {
                    streamBuf = ASCII85Decode.decode(streamBuf, spec.params[i]);
                } else if (enctype.equals("ASCIIHexDecode") || enctype.equals("AHx")) {
                    streamBuf = ASCIIHexDecode.decode(streamBuf, spec.params[i]);
                } else if (enctype.equals("RunLengthDecode") || enctype.equals("RL")) {
                    streamBuf = RunLengthDecode.decode(streamBuf, spec.params[i]);
                } else if (enctype.equals("DCTDecode") || enctype.equals("DCT")) {
                    streamBuf = DCTDecode.decode(dict, streamBuf, spec.params[i]);
                } else if (enctype.equals("JPXDecode")) {
                    streamBuf = JPXDecode.decode(dict, streamBuf, spec.params[i]);
                } else if (enctype.equals("CCITTFaxDecode") || enctype.equals("CCF")) {
                    streamBuf = CCITTFaxDecode.decode(dict, streamBuf, spec.params[i]);
                } else if (enctype.equals("Crypt")) {
                    String cfName = PDFDecrypterFactory.CF_IDENTITY;
                    if (spec.params[i] != null) {
                        final PDFObject nameObj = spec.params[i].getDictRef("Name");
                        if (nameObj != null && nameObj.getType() == PDFObject.NAME) {
                            cfName = nameObj.getStringValue();
                        }
                    }
                    streamBuf = dict.getDecrypter().decryptBuffer(cfName, null, streamBuf);
                } else if (enctype.equals("JBIG2Decode")) {
                    streamBuf = JBig2Decode.decode(dict, streamBuf, spec.params[i]);
View Full Code Here

     * @throws IOException if there's a problem reading the objects
     */
    private static String getCryptFilterName(PDFObject param) throws IOException {
        String cfName = PDFDecrypterFactory.CF_IDENTITY;
        if (param != null) {
            final PDFObject nameObj = param.getDictRef("Name");
            if (nameObj != null && nameObj.getType() == PDFObject.NAME) {
                cfName = nameObj.getStringValue();
            }
        }
        return cfName;
    }
View Full Code Here

     * @throws IOException if the stream dictionary can't be read
     */
    public static boolean isEncrypted(PDFObject dict)
            throws IOException {

        PDFObject filter = dict.getDictRef("Filter");
        if (filter == null) {
            // just apply default decryption
            return dict.getDecrypter().isEncryptionPresent();
        } else {

View Full Code Here

                ary[0] = filter;
                params = new PDFObject[1];
                params[0] = dict.getDictRef("DecodeParms");
            } else {
                ary = filter.getArray();
                PDFObject parmsobj = dict.getDictRef("DecodeParms");
                if (parmsobj != null) {
                    params = parmsobj.getArray();
                } else {
                    params = new PDFObject[ary.length];
                }
            }
        }
View Full Code Here

       
        // get the pattern type
        int type = patternObj.getDictRef("PatternType").getIntValue();
        
        // read the pattern transform matrix
        PDFObject matrix = patternObj.getDictRef("Matrix");
  AffineTransform xform = null;
        if (matrix == null) {
            xform = new AffineTransform();
        } else {
            float elts[]= new float[6];
            for (int i = 0; i < elts.length; i++) {
                elts[i] = (matrix.getAt(i)).getFloatValue();
            }
       
            xform = new AffineTransform(elts);
        }   
       
View Full Code Here

     */
    @Override
  public void parse(PDFObject shaderObj) throws IOException
    {
        // read the axis coordinates (required)
        PDFObject coordsObj = shaderObj.getDictRef("Coords");
        if (coordsObj == null) {
            throw new PDFParseException("No coordinates found!");
        }
        PDFObject[] coords = coordsObj.getArray();
        center1 = new Point2D.Float(coords[0].getFloatValue(),
                                          coords[1].getFloatValue());
        center2 = new Point2D.Float(coords[3].getFloatValue(),
                                          coords[4].getFloatValue());
        radius1 = coords[2].getFloatValue();
        radius2 = coords[5].getFloatValue();
       
        // read the domain (optional)
        PDFObject domainObj = shaderObj.getDictRef("Domain");
        if (domainObj != null) {
            PDFObject[] domain = domainObj.getArray();
            setMinT(domain[0].getFloatValue());
            setMaxT(domain[1].getFloatValue());
        }
       
        // read the functions (required)
        PDFObject functionObj = shaderObj.getDictRef("Function");
        if (functionObj == null) {
            throw new PDFParseException("No function defined for shader!");
        }
        PDFObject[] functionArray = functionObj.getArray();
        PDFFunction[] functions = new PDFFunction[functionArray.length];
        for (int i = 0; i < functions.length; i++) {
            functions[i] = PDFFunction.getFunction(functionArray[i]);
        }
        setFunctions(functions);
       
        // read the extend array (optional)
        PDFObject extendObj = shaderObj.getDictRef("Extend");
        if (extendObj != null) {
            PDFObject[] extendArray = extendObj.getArray();
            setExtendStart(extendArray[0].getBooleanValue());
            setExtendEnd(extendArray[1].getBooleanValue());
        }
    }
View Full Code Here

    // find the new window attribute and parse it if available
    this.newWindow = PdfObjectParseUtil.parseBooleanFromDict("NewWindow", obj, false);

    // parse the target dictionary
    PDFObject targetObj = obj.getDictRef("T");
    ArrayList<GoToETarget> list = new ArrayList<GoToETarget>();
    this.target = parseTargetDistionary(targetObj, list);
  }
View Full Code Here

        annot = ""+PdfObjectParseUtil.parseIntegerFromDict("A", targetObj, false);
      }
      target.setAnnotNo(annot);
     
      //find target dictionary and parse it
      PDFObject subTargetObj = targetObj.getDictRef("T");
      if(subTargetObj != null){
        // call this method recursive, in case the target was not already contained in the
        // list (this is checked for not getting into an infinite loop)
        if(list.contains(target) == false){
          list.add(target);
View Full Code Here

  }


  protected static byte[] decode(PDFObject dict, byte[] source) throws IOException {
    int width = 1728;
    PDFObject widthDef = dict.getDictRef("Width");
    if (widthDef == null) {
      widthDef = dict.getDictRef("W");
    }
    if (widthDef != null) {
      width = widthDef.getIntValue();
    }
    int height = 0;
    PDFObject heightDef = dict.getDictRef("Height");
    if (heightDef == null) {
      heightDef = dict.getDictRef("H");
    }
    if (heightDef != null) {
      height = heightDef.getIntValue();
    }

    //
    int columns = getOptionFieldInt(dict, "Columns", width);
    int rows = getOptionFieldInt(dict, "Rows", height);
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.