Package org.jpedal.objects.raw

Examples of org.jpedal.objects.raw.PdfArrayIterator


        }
       
  private void additionalAction_OCState(int eventType, PdfObject aData) {
    if (eventType == MOUSECLICKED) {

      PdfArrayIterator state = aData.getMixedArray(PdfDictionary.State);

      if (state != null && state.getTokenCount() > 0) {

        final PdfLayerList layers = (PdfLayerList)decode_pdf.getJPedalObject(PdfDictionary.Layer);

        int count = state.getTokenCount();

        final int action = state.getNextValueAsConstant(true);
        String ref;
        for (int jj = 1; jj < count; jj++) {
          ref = state.getNextValueAsString(true);

          final String layerName = layers.getNameFromRef(ref);

          // toggle layer status when clicked
          Runnable updateAComponent = new Runnable() {
View Full Code Here


        //then get the submit URL to use
        if(dict!=null)
    newSubmitURL = dict.getTextStreamValue(PdfDictionary.F);
       
    //get the fields we need to change
    PdfArrayIterator fieldList = aData.getMixedArray(PdfDictionary.Fields);
    if (fieldList != null) {
      if (fieldList.getTokenCount() < 1)
        fieldList = null;

      if (fieldList != null) {
        // code goes here
        int fieldIndex = 0;
        newListOfFields = new String[fieldList.getTokenCount()];

        // go through list of fields and store so we can send
        String formObject;
        String tok, preName = null;
        StringBuilder names = new StringBuilder();
        while (fieldList.hasMoreTokens()) {
          formObject = fieldList.getNextValueAsString(true);

          if (formObject.contains(".x")) {
            preName = formObject.substring(formObject.indexOf('.') + 1,
                formObject.indexOf(".x") + 1);
          }
View Full Code Here

            int page=-1;
           
        if (showMethods)
                System.out.println("DefaultActionHandler.gotoDest()");
           
            PdfArrayIterator Dest = aData.getMixedArray(PdfDictionary.Dest);
            if (Dest!=null) {
               
                if (eventType == MOUSECLICKED) {
                   
                    //allow for it being an indirect named object and convert if so
                    if(Dest.getTokenCount()==1){
                        //          System.out.println("val="+ Dest.getNextValueAsString(false));
                       
                        String ref=decode_pdf.getIO().convertNameToRef( Dest.getNextValueAsString(false));
                        if(ref!=null){
                           
                            //can be indirect object stored between []
                            if(ref.charAt(0)=='['){
                                if(debugDest)
                                    System.out.println("data for named obj "+ref);
                               
                                byte[] raw=StringUtils.toBytes(ref);
                                //replace char so subroutine works -ignored but used as flag in routine
                                raw[0]= 0;
                               
                                ArrayDecoder objDecoder=new ArrayDecoder(decode_pdf.getIO().getObjectReader(), 0, raw.length, PdfDictionary.VALUE_IS_MIXED_ARRAY,null, PdfDictionary.Names);
                                objDecoder.readArray(false, raw, aData, PdfDictionary.Dest);
                               
                                Dest=aData.getMixedArray(PdfDictionary.Dest);
                               
                            }else{
                                if(debugDest)
                                    System.out.println("convert named obj "+ref);
                               
                                aData=new OutlineObject(ref);
                                decode_pdf.getIO().readObject(aData);
                                Dest=aData.getMixedArray(PdfDictionary.Dest);
                            }
                        }
                    }
                   
                    String filename = aData.getTextStreamValue(PdfDictionary.F);

                    if(filename==null){
                        PdfObject fDic = aData.getDictionary(PdfDictionary.F);
                       
                        if(fDic!=null)
                            filename = fDic.getTextStreamValue(PdfDictionary.F);
                    }
                   
                    //add path if none present
                    if(filename!=null && filename.indexOf('/')==-1 && filename.indexOf('\\')==-1)
                        filename=decode_pdf.getObjectStore().getCurrentFilepath()+filename;
                   
                    //removed \\ checking from iff so slashIndex will work, and
                    //stop null pointer exceptions, \\ will also be quicker.
                    if(filename!=null){
                       
                        //if we have any \\ then replace with / for Windows
                        int index = filename.indexOf("\\");
                        while(index!=-1){
                            //for some reason String.replaceAll didnt like "\\" so done custom
                            filename = filename.substring(0,index)+
                                    '/' +filename.substring(index+("\\".length()),filename.length());
                            index = filename.indexOf("\\");
                        }
                       
                        //if we dont start with a /,./ or ../ or #:/ then add ./
                        int slashIndex = filename.indexOf(":/");
                        if((slashIndex==-1 || slashIndex>1) && !filename.startsWith("/")){
                            File fileStart = new File(decode_pdf.getFileName());
                            filename = fileStart.getParent()+ '/' +filename;
                        }
                       
                        //resolve any ../ by removing
                        //(ie /home/test/Downloads/hyperlinks2/Data/../Start.pdf to
                        // /home/test/Downloads/hyperlinks2/Start.pdf)
                        index=filename.indexOf("/../");
                        if(index!=-1){
                            int start=index-1;
                            while(start>0){
                                if((filename.charAt(start)=='/')|| start==0)
                                    break;
                                start--;
                            }
                       
                        if(start>0)
                            filename=filename.substring(0,start)+filename.substring(index+3,filename.length());
              
                        }
                    }
                   
                    // new version - read Page Object to jump to
                    String pageRef = "";
                   
                    if (Dest.getTokenCount() > 0){
                       
                       
                        //get pageRef as number of ref
                        int possiblePage=Dest.getNextValueAsInteger(false)+1;
                        pageRef = Dest.getNextValueAsString(true);
                       
                        //convert to target page if ref or ignore
                       
                        if(pageRef.endsWith(" R"))
                            page = decode_pdf.getPageFromObjectRef(pageRef);
                        else if(possiblePage>0){ //can also be a number (cant check range as not yet open)
                            page=possiblePage;
                        }
                       
                        if(debugDest)
                            System.out.println("pageRef="+pageRef+" page="+page+ ' ' +aData.getObjectRefAsString());
                       
                        //allow for named Dest
                        if(page==-1){
                            String newRef=decode_pdf.getIO().convertNameToRef(pageRef);
                           
                            //System.out.println(newRef+" "+decode_pdf.getIO().convertNameToRef(pageRef+"XX"));
                           
                            if(newRef!=null && newRef.endsWith(" R"))
                                page = decode_pdf.getPageFromObjectRef(newRef);
                           
                        }
                        //commented out by mark as named dest should now be handled and -1 shows no page
                        //if(page==-1){
                        //we probably have a named destination
                        //  page = 1;
                        //}
                    }
                   
                    //added by Mark so we handle these types of links as well in code below with no Dest
                    //<</Type/Annot/Subtype/Link/Border[0 0 0]/Rect[56 715.1 137.1 728.9]/A<</Type/Action/S/GoToR/F(test1.pdf)>>
                    if(Dest.getTokenCount()==0 && aData.getNameAsConstant(PdfDictionary.S)==PdfDictionary.GoToR)
                        command=PdfDictionary.GoToR;
                   
                    //        boolean openInNewWindow = aData.getBoolean(PdfDictionary.NewWindow);
                   
                    if(debugDest)
                        System.out.println("Command="+PdfDictionary.showAsConstant(command));
                   
                    switch(command){
                        case PdfDictionary.Dest :
                            //read all the values
                            if (Dest.getTokenCount()>1) {
                               
                                //get type of Dest
                                //System.out.println("Next value as String="+Dest.getNextValueAsString(false)); //debug code to show actual value (note false so does not roll on)
                                int type=Dest.getNextValueAsConstant(true);
                               
                                if(debugDest)
                                    System.out.println("Type="+PdfDictionary.showAsConstant(type));
                               
                                Integer scale = null;
                                Rectangle position=null;
                               
                                // - I have added all the keys for you and
                                //changed code below. If you run this on baseline,
                                //with new debug flag testActions on in DefaultAcroRender
                                // it will exit when it hits one
                                //not coded
                               
                                //type of Dest (see page 552 in 1.6Spec (Table 8.2) for full list)
                                switch(type){
                                    case PdfDictionary.XYZ: //get X,y values and convert to rectangle which we store for later
                                       
                                        //get x and y, (null will return 0)
                                        float x=Dest.getNextValueAsFloat();
                                        float y=Dest.getNextValueAsFloat();
                                       
                                        //third value is zoom which is not implemented yet
                                       
                                        //create Rectangle to scroll to
                                        position=new Rectangle((int)x,(int)y,10,10);
                                       
                                        break;
                                    case PdfDictionary.Fit: //type sent in so that we scale to Fit.
                                        scale = -3;//0 for width in scaling box and -3 to show its an index
                                        break;
                                       
                                    case PdfDictionary.FitB:
                                        /*[ page /FitB ] - (PDF 1.1) Display the page designated by page, with its contents
                                         * magnified just enough to fit its bounding box entirely within the window both
                                         * horizontally and vertically. If the required horizontal and vertical magnification
                                         * factors are different, use the smaller of the two, centering the bounding box
                                         * within the window in the other dimension.
                                         */
                                        //scale to same as Fit so use Fit.
                                        scale = -3;//0 for width in scaling box and -3 to show its an index
                                       
                                        break;
                                       
                                    case PdfDictionary.FitH:
                                        /* [ page /FitH top ] - Display the page designated by page, with the vertical coordinate
                                         * top positioned at the top edge of the window and the contents of the page magnified
                                         * just enough to fit the entire width of the page within the window. A null value for
                                         * top specifies that the current value of that parameter is to be retained unchanged.
                                         */
                                        //scale to width
                                        scale = -1;//2 for width in scaling box and -3 to show its an index
                                       
                                        //and then scroll to location
                                        float top=Dest.getNextValueAsFloat();
                                       
                                        //create Rectangle to scroll to
                                        position=new Rectangle(10,(int)top,10,10);
                                       
                                        break;
View Full Code Here

        int count=nameLists.length;
        if(isKid)
            count=1;

        PdfObject pdfObj;
        PdfArrayIterator namesArray;

        String name,value;

        for(int ii=0;ii<count;ii++){

            if(isKid)
                pdfObj=nameObject;
            else
                pdfObj=nameObject.getDictionary(nameLists[ii]);

            if(pdfObj==null)
                continue;

            //any kids
            byte[][] kidList = pdfObj.getKeyArray(PdfDictionary.Kids);
            if(kidList!=null){
                int kidCount=kidList.length;

                /** allow for empty value and put next pages in the queue */
                if (kidCount> 0) {

                    for (byte[] aKidList : kidList) {

                        String nextValue = new String(aKidList);

                        PdfObject nextObject = new NamesObject(nextValue);
                        nextObject.ignoreRecursion(false);

                        objectReader.readObject(nextObject);

                        readNames(nextObject, javascript, true);
                    }
                }
            }

            //get any names object
            namesArray = pdfObj.getMixedArray(PdfDictionary.Names);

            //read all the values
            if (namesArray != null && namesArray.getTokenCount()>0) {
                while (namesArray.hasMoreTokens()) {
                    name =namesArray.getNextValueAsString(true);
                    value =namesArray.getNextValueAsString(true);

                    //if Javascript, get full value and store, otherwise just get name
                    if(nameLists[ii]== PdfDictionary.JavaScript){

                        /**/
 
View Full Code Here

        //check type of filter and type and see if supported
        int v = encyptionObj.getInt(PdfDictionary.V);

        //get filter value
        PdfArrayIterator filters = encyptionObj.getMixedArray(PdfDictionary.Filter);
        int firstValue=PdfDictionary.Standard;
        if(filters!=null && filters.hasMoreTokens())
            firstValue=filters.getNextValueAsConstant(false);

        //throw exception if we have an unsupported encryption method
        if(v==3)
            throw new PdfSecurityException("Unsupported Custom Adobe Encryption method");
        else if (v > 4){
View Full Code Here

                            owner.add(type);

                            String filter = null;//sigObject.getName(PdfDictionary.Filter);

                            //@simon -new version to test
                            PdfArrayIterator filters = sigObject.getMixedArray(PdfDictionary.Filter);
                            if(filters!=null && filters.hasMoreTokens())
                                filter=filters.getNextValueAsString(true);

                            DefaultMutableTreeNode filterNode = new DefaultMutableTreeNode("Filter: " + filter);
                            type.add(filterNode);

                            String subFilter = sigObject.getName(PdfDictionary.SubFilter);
View Full Code Here

          insideBorder = BorderFactory.createLineBorder(borderColor, w);//solid
            break;
           
        case PdfDictionary.D:

            PdfArrayIterator dashPattern = BS.getMixedArray(PdfDictionary.D);

            int current_line_dash_phase =0;
            float[] current_line_dash_array=new float[1];
            int count=dashPattern.getTokenCount();

            if(count>0){
               current_line_dash_array=dashPattern.getNextValueAsFloatArray();
            }

            if(count>1){
              current_line_dash_phase=dashPattern.getNextValueAsInteger();
            }

            Stroke current_stroke = new BasicStroke( w, 0, 0, 1, current_line_dash_array, current_line_dash_phase );

            insideBorder=new DashBorder(current_stroke,borderColor);
View Full Code Here


      /**
       * handle differences from main encoding
       */
      PdfArrayIterator Diffs=Encoding.getMixedArray(PdfDictionary.Differences);
      if (Diffs != null && Diffs.getTokenCount()>0) {

        glyphs.setIsSubsetted(true);

        //needed to workout if values hex of base10
        //as we have examples with both

        //guess if hex or base10 by looking for numbers
        //if it has a number it must be base10
        byte[][] rawData=null;

        if(Encoding!=null)
          rawData=Encoding.getByteArray(PdfDictionary.Differences);


        if(rawData!=null){

          containsHexNumbers=true;
          allNumbers=true;
                for (byte[] aRawData : rawData) {

                    if (aRawData != null && aRawData[0] == '/') {

                        int length = aRawData.length;
                        byte[] data = aRawData;
                        char c, charCount = 0;

                        if (length == 3 && containsHexNumbers) {
                            for (int jj = 1; jj < 3; jj++) {

                                c = (char) data[jj];
                                if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F'))
                                    charCount++;
                            }
                        }
                        if (charCount != 2) {
                            containsHexNumbers = false;
                            //System.out.println("Failed on="+new String(data)+"<");
                            //ii=rawData.length;
                        }


                        if (allNumbers) {
                            if (length < 4) {
                                for (int jj = 2; jj < length; jj++) {

                                    c = (char) data[jj];
                                    if ((c >= '0' && c <= '9')) {
                                    } else {
                                        allNumbers = false;
                                        jj = length;
                                    }
                                }
                            }
                        }

                        //exit if poss
                        //if(!containsHexNumbers){
                        //    ii=rawData.length;
                        //}
                        /**/
                    }
                }
        }


        int pointer = 0,type;
        while (Diffs.hasMoreTokens()) {

          type=Diffs.getNextValueType();

          if(type==PdfArrayIterator.TYPE_KEY_INTEGER){
            pointer=Diffs.getNextValueAsInteger();
          }else{

            if(type==PdfArrayIterator.TYPE_VALUE_INTEGER){

              if(diffCharTable==null)
                diffCharTable = new  int[maxCharCount];

              //save so we can rempa glyph to get correct value for embedded font
              diffCharTable[pointer]=Diffs.getNextValueAsInteger(false);

            }

            putMappedChar( pointer,Diffs.getNextValueAsFontChar(pointer, containsHexNumbers, allNumbers));
            pointer++;
          }

          //allow for spurious values added which should not be there
          if(pointer==256)
            break;
        }

        //get flag
        isHex=Diffs.hasHexChars();

        //pick up space
        int spaceChar=Diffs.getSpaceChar();
        if(spaceChar!=-1)
          this.spaceChar=spaceChar;
      }

      /**
 
View Full Code Here

  public void createUniqueAnnotationIcons() {

    int p=commonValues.getCurrentPage();

    //new list we can parse
    PdfArrayIterator annotListForPage = decode_pdf.getFormRenderer().getAnnotsOnPage(p);
   
    //and place to store so we can test later
    //flush list if needed
    if(objs==null)
      objs=new HashMap();
    else
      objs.clear();

    if(annotListForPage!=null && annotListForPage.getTokenCount()>0){ //can have empty lists

      /**
       * new code to set Annot to have custom image
       *
       *  scan and overwrite images of certain types
       */
      int i=0;
      int count=annotListForPage.getTokenCount();
            int[] type=new int[count];
        Color[] colors=new Color[count];
      Object[] obj=new Object[count];
           
      while(annotListForPage.hasMoreTokens()){

        // Due to the way some pdf's are created it is necessery to take the offset of a page into account when addding custom objects
        // Variables mX and mY represent that offset and need to be taken in to account when placing any additional object on a page.

        int mX = decode_pdf.getPdfPageData().getMediaBoxX(p);
        int mY = decode_pdf.getPdfPageData().getMediaBoxY(p);


        //get ID of annot which has already been decoded and get actual object
        String annotKey=annotListForPage.getNextValueAsString(true);

        Object[] rawObj=decode_pdf.getFormRenderer().getCompData().getRawForm(annotKey);

                for (Object aRawObj : rawObj) {
                    if (aRawObj != null) {
View Full Code Here

TOP

Related Classes of org.jpedal.objects.raw.PdfArrayIterator

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.