idainfront.pdfcreator4j
Class PdfCreatorApi

java.lang.Object
  extended by idainfront.pdfcreator4j.PdfCreatorApi

public class PdfCreatorApi
extends Object

A simple API wrapping the exposed methods and properties in the PDFCreator COM API. An example of using the API:

PdfCreatorApi api = new PdfCreatorApi();

 try {
     api.start();
     boolean canPrint = api.isPrintable("c:\\tmp\\test.pdf");
     //...
 }
 catch(PdfCreatorException e){
     //...
 } finally {
     api.dispose();
 }
The call to disposeCOMThread() is important, and needs to be in a finally-clause. This will dispose of threads and resources relating to the COM bridge used.

Author:
Peter Isaksson & John Bäckstrand

Nested Class Summary
static class PdfCreatorApi.EventHandler
          Event handler for listening to COM-events generated by PdfCreator
 
Field Summary
static int STATUS_IN_PROGRESS
           
static int STATUS_READY
           
static int STATUS_WITH_ERRORS
           
 
Constructor Summary
PdfCreatorApi()
           
 
Method Summary
 void clearCache()
          Perform a clearcache call to the Pdf Creator Com-Interface.
 void close()
          Tries to close the process for pdf creator by invoking the method cClose on the pdf creator COM-interface.
 void disposeCOMThread()
          Dispose of any resources acquired for the COM bridge.
 String getDefaultPrinter()
          Get the default printer in OS from the Pdf Creator COM-interface
 PdfCreatorError getError()
           
 String getProperty(String property)
          Gets a property from the pdf creator options.
 int getStatus()
          Status state of PdfCreatorAPI.
 Variant invoke(String key, Object object)
           
 boolean isClosed()
          This method checks whether the ActiveXComponent has been released.
 boolean isPrintable(String file)
          Check whether a file can be printed by PdfCreator.
 boolean isRunning()
          A call to the PDF Creator COM-Api to see if the program (process) is running.
 void printFile(String filename)
           
 void setCoption(String property, Object value)
          Set a specific option parameter.
 void setCoptions(Map<String,Object> properties)
          Set an map of options.
 void setDefaultPrinter(String printer)
          Setter for default printer.
 void setPrinterStop(boolean stop)
          Flag that indicates whether printing should be enabled or not.
protected  void setStatus(int status)
          Method that sets the status of our PdfCreator.
 void setVisible(boolean value)
          Sets whether the application/tray icon should be visible when pdf creator is running
 void showLogFileDialog(boolean value)
          Calls the Pdf Creator Com Interface whether the log fil dialog should be visible or not.
 boolean start()
          Start PdfCreator with no additional options.
 boolean start(boolean forceIntialize)
          This starts the Pdf Creator process through a COM call.
 boolean start(String options)
           
 boolean start(String options, boolean forceIntialize)
           
 void writeToLogFile(String filePath)
          Calls the PDF Creator COM-Api with a file path to save a log fil to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATUS_IN_PROGRESS

public static final int STATUS_IN_PROGRESS
See Also:
Constant Field Values

STATUS_WITH_ERRORS

public static final int STATUS_WITH_ERRORS
See Also:
Constant Field Values

STATUS_READY

public static final int STATUS_READY
See Also:
Constant Field Values
Constructor Detail

PdfCreatorApi

public PdfCreatorApi()
Method Detail

disposeCOMThread

public void disposeCOMThread()
Dispose of any resources acquired for the COM bridge.


isPrintable

public boolean isPrintable(String file)
                    throws PdfCreatorException
Check whether a file can be printed by PdfCreator.

Parameters:
file - Filename to check
Returns:
Return true if the file is printable, false otherwise.
Throws:
PdfCreatorException

isRunning

public boolean isRunning()
                  throws PdfCreatorException
A call to the PDF Creator COM-Api to see if the program (process) is running.

Returns:
true if the program (process) is running, otherwise false
Throws:
PdfCreatorException - if COM call failed

writeToLogFile

public void writeToLogFile(String filePath)
Calls the PDF Creator COM-Api with a file path to save a log fil to.

Parameters:
filePath - The path to the file where the log should be saved.

showLogFileDialog

public void showLogFileDialog(boolean value)
                       throws PdfCreatorException
Calls the Pdf Creator Com Interface whether the log fil dialog should be visible or not.

Throws:
PdfCreatorException - if the call to COM-interface was unsuccessful

getStatus

public int getStatus()
Status state of PdfCreatorAPI. This value is set when the API has received a ready event from the Pdf Creator COM-Api. What it means is that Pdf Creator has finished printing the jobs in the queue and is ready to serve. This is useful to know when closing the Pdf Creator.

Returns:
PdfCreatorApi.STATUS_IN_PROGRESS if Pdf Creator hasn't sent any event, PdfCreatorApi.STATUS_WITH_ERRORS if the Pdf Creator has sent an eError event or PdfCreatorApi.STATUS_READY if the Pdf Creator has sent an eReady event.

setStatus

protected void setStatus(int status)
Method that sets the status of our PdfCreator. Either it is in a "ready to serve/shut me down/ state its value.

Parameters:
status - PdfCreatorApi.STATUS_IN_PROGRESS if Pdf Creator hasn't sent any event, PdfCreatorApi.STATUS_WITH_ERRORS if the Pdf Creator has sent an eError event or PdfCreatorApi.STATUS_READY if the Pdf Creator has sent an eReady event.

start

public boolean start(boolean forceIntialize)
              throws PdfCreatorException
This starts the Pdf Creator process through a COM call.

Parameters:
forceIntialize - this is useful if a process for Pdf creator is already started, true will take over this process, otherwise a new process will be created.
Returns:
true if the startup of the Pdf Creator process was successful
Throws:
PdfCreatorException - if the call to COM-interface was unsuccessful

start

public boolean start(String options,
                     boolean forceIntialize)
              throws PdfCreatorException
Parameters:
options -
forceIntialize -
Returns:
Throws:
PdfCreatorException - if the call to COM-interface was unsuccessful

start

public boolean start(String options)
              throws PdfCreatorException
Parameters:
options -
Returns:
Throws:
PdfCreatorException - if the call to COM-interface was unsuccessful

start

public boolean start()
              throws PdfCreatorException
Start PdfCreator with no additional options.

Returns:
Throws:
PdfCreatorException - if the call to COM-interface was unsuccessful

close

public void close()
           throws PdfCreatorException
Tries to close the process for pdf creator by invoking the method cClose on the pdf creator COM-interface. It also will release the ActiveXcomponent and the dispatcher that recieves the event. Note. After the call to this the api must be recreated by creating a new instance.

Throws:
PdfCreatorException - if the call to COM-interface was unsuccessful

clearCache

public void clearCache()
                throws PdfCreatorException
Perform a clearcache call to the Pdf Creator Com-Interface.

Throws:
PdfCreatorException - if the call to COM-interface was unsuccessful

getDefaultPrinter

public String getDefaultPrinter()
                         throws PdfCreatorException
Get the default printer in OS from the Pdf Creator COM-interface

Returns:
the default printer as a String
Throws:
PdfCreatorException - if the call to COM-interface was unsuccessful

setVisible

public void setVisible(boolean value)
Sets whether the application/tray icon should be visible when pdf creator is running

Parameters:
value - true if it should be visible.

setDefaultPrinter

public void setDefaultPrinter(String printer)
                       throws PdfCreatorException
Setter for default printer. Note, this changes the default printer for the OS.

Parameters:
printer - the printer to use.
Throws:
PdfCreatorException - if the call to COM-interface was unsuccessful

getProperty

public String getProperty(String property)
Gets a property from the pdf creator options. The properties to get values from is found in clsPdfCreatorOptions in the COM-Interface.

Parameters:
property - The property to get it's value from.
Returns:
the property value as a String

setCoption

public void setCoption(String property,
                       Object value)
                throws PdfCreatorException
Set a specific option parameter. The properties to set values from is found in clsPdfCreatorOptions in the COM-Interface.

Parameters:
property - the option key
value - the value for the property key
Throws:
PdfCreatorException - if the call to COM-interface was unsuccessful

setCoptions

public void setCoptions(Map<String,Object> properties)
                 throws PdfCreatorException
Set an map of options.

Parameters:
properties - as a map
Throws:
PdfCreatorException - if the call to COM-interface was unsuccessful

setPrinterStop

public void setPrinterStop(boolean stop)
                    throws PdfCreatorException
Flag that indicates whether printing should be enabled or not.

Parameters:
stop - true if printing should be disabled
Throws:
PdfCreatorException - if the call to COM-interface was unsuccessful

getError

public PdfCreatorError getError()
Returns:
The error with its error number and description.

printFile

public void printFile(String filename)
               throws PdfCreatorException
Parameters:
filename - the path to the file. Note: this must be a absolute path or PDF Creator will complain.
Throws:
PdfCreatorException - if the call to COM-interface was unsuccessful

invoke

public Variant invoke(String key,
                      Object object)
               throws PdfCreatorException
Parameters:
key - String representing the name of the method to call.
object - A parameter as an Object.
Throws:
PdfCreatorException - if the call to COM-interface was unsuccessful

isClosed

public boolean isClosed()
This method checks whether the ActiveXComponent has been released. If the component is closed properly the return value is true

Returns:
true if closed properly


Copyright © 2009. All Rights Reserved.