Ibex PDF Creator

Changing the location of temporary files

Ibex creates temporary files during the PDF creation process. This is done to reduce the amount of memory used when processing massive FO files.

By default the temporary files are created using calls to java.io.File.createTempFile(), which will place the file in the system temp file location.

It is possible to specify where Ibex should create temporary files. This is done by creating an object which implements the ibex4.ITemporaryFileManager interface. This interface only contains the method getFileName().

Having created an instance of your object, you then pass it to the setTemporaryFileManager() method on the FODocument object use to create the PDF file. Any subsequest requests for a temporary file name are delegated to your object, giving you full control of where the temp file is placed.

Creating a temporary file manager object

An example of an object which implements the ITemporaryFileManager interface shown here:

import java.io.*;
import java.util.Hashtable;

import ibex4.logging.*;
import ibex4.*;

public class TempNameCreator implements ibex4.ITemporaryFileManager {

    public String getFileName() {

            String name = null ; 
            try  {
                File file = File.createTempFile( "localtemp" , ""); 

                name = file.getName( ); 

                Logger.getLogger().info( "using temp file " + name );
            }
            catch( IOException ex) {
                Logger.getLogger().info( "ioexception " + ex );
                throw new RuntimeException( ex); 
                
            }
            return name ; 
    }
}
      

The call to getFileName() should return the full name and path of the temporary file. This must be a location to which the process has write access. Every call to getFileName() must return a unique file name.

Using the temporary file manager object

To use the object create an instance of it and pass it to the setTemporaryFileManager() method of the FODocument object. An example of this is shown here:

import java.io.*;
import java.util.Hashtable;

import ibex4.logging.*;
import ibex4.*;

public class runibex {

  public static void main( String[] args ) {
    
    if(args.length < 1 ) {
        Logger.getLogger().info( "runibex fo-file pdf-file");
        return;
    }

    Logger.getLogger().setLevel( Level.INFO );

    FODocument doc = new FODocument();

    doc.setTemporaryFileManager( new TempNameCreator() );

    Logger.getLogger().info( doc.Settings.Version + " running" );
    
    InputStream xmlStream = null;
    OutputStream pdfStream = null;
    try {
        xmlStream = new FileInputStream( args[0] );
        pdfStream = new FileOutputStream( args[1] );
        
        Logger.getLogger().info ( args[0] + ")->" + args[1] );
        
        doc.generate( xmlStream, null, pdfStream );
        
        Logger.getLogger().info( "count of pages created = " + doc.getPageCount() );
    }
    catch( Exception e ) {
        
        Exception ex = e;
        
        Logger.getLogger().info("caught runtime exception:");
        ex.printStackTrace();
        }
        
    }
  }

}