    public int convertObjectToPageNumber(final String ref) {
        
        return pageLookup.convertObjectToPageNumber(ref);
    }
    
    public void setLookup(final String currentPageOffset, final int tempPageCount) {
        pageLookup.put(currentPageOffset, tempPageCount);
        pagesReferences.put(tempPageCount, currentPageOffset);
    }
    
    public void dispose(){
        
        //this.objData=null;
        //this.lastRef=null;
        
        nameLookup=null;
        
        //this.fields=null;
        
        if(objectReader!=null) {
            objectReader.dispose();
        }
        objectReader=null;
        
        if(pageLookup!=null) {
            pageLookup.dispose();
        }
        pageLookup=null;
        
    }
    
    /**
     * open pdf file<br> Only files allowed (not http)
     * so we can handle Random Access of pdf
     */
    public final void openPdfFile( final InputStream in) throws PdfException
    {
        
        try
        {
            
            //use byte[] directly if small otherwise use Memory Map
            pdf_datafile = new RandomAccessMemoryMapBuffer(in );
            
            objectReader.init(pdf_datafile);
            
            //this.eof = pdf_datafile.length();
            //pdf_datafile = new RandomAccessFile( filename, "r" );
            
        }catch( final Exception e ){
            
            if(LogWriter.isOutput()) {
                LogWriter.writeLog("Exception " + e + " accessing file");
            }
            
            throw new PdfException( "Exception " + e + " accessing file" );
        }
        
    }
    
    /**
     * open pdf file<br> Only files allowed (not http)
     * so we can handle Random Access of pdf
     */
    public final void openPdfFile(final ImageInputStream iis ) throws PdfException
    {
        
        final RandomAccessBuffer pdf_datafile;
        
        try
        {
            
            //use byte[] directly if small otherwise use Memory Map
            pdf_datafile = new ImageInputStreamFileBuffer(iis);
            
            //pdf_datafile = new RandomAccessFileBuffer( filename, "r" );
            //pdf_datafile = new RandomAccessFCTest( new FileInputStream(filename));
            
            objectReader.init(pdf_datafile);
            
            //this.eof = pdf_datafile.length();
            
        }catch( final Exception e ){
            if(LogWriter.isOutput()) {
                LogWriter.writeLog("Exception " + e + " accessing file");
            }
            
            throw new PdfException( "Exception " + e + " accessing file" );
        }
        
    }
    
    public void checkParentForResources(final PdfObject pdfObject) {
        
        /**
         * if no resource, check parent for one
         * (in theory should recurse up whole tree)
         */
        if(pdfObject.getDictionary(PdfDictionary.Resources)==null){
            
            final String parent=pdfObject.getStringKey(PdfDictionary.Parent);
            
            if(parent!=null){
                final PdfObject parentObj=new PageObject(parent);
                readObject(parentObj);
                
                final PdfObject resObj=parentObj.getDictionary(PdfDictionary.Resources);
                
                if(resObj!=null){
                    pdfObject.setDictionary(PdfDictionary.Resources,resObj);
                }
            }
        }
    }
    
    /**
     * open pdf file<br> Only files allowed (not http)
     * so we can handle Random Access of pdf
     */
    public final void openPdfFile( final String filename ) throws PdfException
    {
        
        final RandomAccessBuffer pdf_datafile;
        
        try
        {
            
            pdf_datafile = new RandomAccessFileBuffer( filename, "r" );
            //pdf_datafile = new RandomAccessFCTest( new FileInputStream(filename));
            
            objectReader.init(pdf_datafile);
            
            //this.eof = pdf_datafile.length();
            
        }catch( final Exception e ){
            if(LogWriter.isOutput()) {
                LogWriter.writeLog("Exception " + e + " accessing file");
            }
            
            throw new PdfException( "Exception " + e + " accessing file" );
        }
        
    }
    
    /**
     * open pdf file using a byte stream - By default files under 16384 bytes are cached to disk
     * but this can be altered by setting PdfFileReader.alwaysCacheInMemory to a maximimum size or -1 (always keep in memory)
     */
    public final void openPdfFile( final byte[] data ) throws PdfException
    {
        
        final RandomAccessBuffer pdf_datafile;
        
        try
        {
            //use byte[] directly if small otherwise use Memory Map
            if(PdfFileReader.alwaysCacheInMemory ==-1 || data.length<PdfFileReader.alwaysCacheInMemory) {
                pdf_datafile = new RandomAccessDataBuffer(data);
            } else{ //cache as file and access via RandomAccess
                
                //pdf_datafile = new RandomAccessMemoryMapBuffer( data ); old version very slow
                
                try {
                    
                    final File file=File.createTempFile("page",".bin", new File(ObjectStore.temp_dir));
                    tempFileName=file.getAbsolutePath();
                    
                    //file.deleteOnExit();
                    
                    final java.io.FileOutputStream a =new java.io.FileOutputStream(file);
                    
                    a.write(data);
                    a.flush();
                    a.close();
                    
                    pdf_datafile = new RandomAccessFileBuffer( tempFileName,"r");
                } catch (final Exception e) {
                    throw new RuntimeException("Unable to create temporary file in "+ObjectStore.temp_dir+'' +e);
                }
            }
            
            objectReader.init(pdf_datafile);
            
            //eof = pdf_datafile.length();
            //pdf_datafile = new RandomAccessFile( filename, "r" );
            
        }catch( final Exception e ){
            
            if(LogWriter.isOutput()) {
                LogWriter.writeLog("Exception " + e + " accessing file");
            }
            
            throw new PdfException( "Exception " + e + " accessing file" );
        }
    }
    
    
    
    /**handle onto JS object*/
    private Javascript javascript;
    
    /**pass in Javascript object from JPedal*/
    public void setJavaScriptObject(final Javascript javascript) {
        this.javascript=javascript;
    }
    
    public void checkResolved(final PdfObject pdfObject) {
        final ObjectDecoder objectDecoder=new ObjectDecoder(this.objectReader);
        objectDecoder.checkResolved(pdfObject);
    }
    
    public void setJavascriptForObject(final FormObject formObject, final int parentType, final int actionType) {
        final String JSscript;
        
        final PdfObject actionObj ;
        final PdfObject JSobj;
        
        final PdfObject additionalObject=formObject.getDictionary(parentType);
        
        final ObjectDecoder objectDecoder=new ObjectDecoder(this.objectReader);
        objectDecoder.checkResolved(additionalObject);
        
        if(additionalObject==null) {
            return;
        }
        
        if(actionType==parentType){
            actionObj = additionalObject;
        }else {
            if(actionType==PdfDictionary.C2) //special case
            {
                actionObj = additionalObject.getDictionary(PdfDictionary.C);
            } else {
                actionObj = additionalObject.getDictionary(actionType);
            }
        }
        
        if(actionObj==null){
            //				throw new RuntimeException("Failed on actionType="+actionType+" "+formObject.getPDFRef()+
            //						"\nformObject="+formObject+" parentObject="+additionalObject+
            //						"\nadditionalObject="+additionalObject.getTextStreamValue(PdfDictionary.T)
            //						+"\nadditionalObject="+formObject.getTextStreamValue(PdfDictionary.T));
        }else{
            
            objectDecoder.checkResolved(actionObj);
            
            JSobj=actionObj.getDictionary(PdfDictionary.JS);
            
            if(JSobj!=null