Menu

How to count Pages per PageGroup

How to ...
2015-05-28
2016-03-24
  • AFP Consultant

    AFP Consultant - 2015-05-28
    import java.io.BufferedInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStream;
    
    import com.mgz.afp.base.StructuredField;
    import com.mgz.afp.exceptions.AFPParserException;
    import com.mgz.afp.modca.BNG_BeginNamedPageGroup;
    import com.mgz.afp.modca.BPG_BeginPage;
    import com.mgz.afp.parser.AFPParser;
    import com.mgz.afp.parser.AFPParserConfiguration;
    
    public class CountPageGroupsAndPagesInPageGroup {
    
        public static void main(String[] args) throws FileNotFoundException, AFPParserException, IOException {
    
            InputStream is = new BufferedInputStream(new FileInputStream(new File(args[0])), 1024 * 1024);
            AFPParserConfiguration pc = new AFPParserConfiguration();
            pc.setInputStream(is);
            AFPParser parser = new AFPParser(pc);
    
            BNG_BeginNamedPageGroup currentBNG = null;
            int pageGroupCount = 0;
            int pageCount=0;
    
            StructuredField sf = null;
            do{
                sf = parser.parseNextSF();
                if(sf!=null){
                    if(sf instanceof BNG_BeginNamedPageGroup){
                        if(currentBNG!=null){
                            System.out.println("PageGroup #" + pageGroupCount + " '" + currentBNG.getName()!=null ? currentBNG.getName() : "" + "' has " + pageCount + " pages." );
                        }
                        currentBNG = (BNG_BeginNamedPageGroup) sf;
                        pageGroupCount++;
                        pageCount=0;
                    }else if(sf instanceof BPG_BeginPage){
                        pageCount++;
                    }
                }
            }while(sf!=null);
    
            // Print out last Page Group.
            if(currentBNG!=null){
                System.out.println("PageGroup #" + pageGroupCount + " '" + currentBNG.getName()!=null ? currentBNG.getName() : "" + "' has " + pageCount + " pages." );             
            }
    
            // Close input stream.
            is.close();
        }
    
    }
    
     

    Last edit: AFP Consultant 2015-05-28
  • gunasekaran

    gunasekaran - 2016-03-24

    I am newly joined in this afp forum. After i downloaded all the source and various committed sources, i am not able to build the source. It shows lots of errors in many files.Please explain about to compile and run this alpheusAFPParser whole files.

     
    • AFP Consultant

      AFP Consultant - 2016-03-24

      Try to use directory src as your only source directory.
      What kind of errors do you get?

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.