HOWTO: Use the Zetafax API to convert a Word document into a TIFF image file
Print
ZTN1583
ID: ZTN1583
This Zetafax technical note applies to:
Zetafax v2006
Summary
It is possible to use the Zetafax API and the Zetafax Printer to convert a document into a TIFF file, which could then be attached to a fax message. You might want to do this in the event that the file that you want to fax does not render correctly when attached directly to a fax message in the API.
This example will use Microsoft Word to convert a Word document by printing it to the Zetafax Printer when it is in API Print mode, thus converting it into a TIFF image file.
Here is a summary of the steps:
- Set up your project to use the Zetafax API (see code sample provided with the installation typically found in "C:\Program Files\Zetafax Server\ZFAPI\Examples").
- Put the Zetafax Printer into "API Print mode". This means that the printer will not launch the Zetafax Client when printed to, and will instead convert the print job into a TIFF file on disk.
- Print your document to the Zetafax Printer. In this example we do this programmatically using the Word Object Model.
- Attach the resultant TIFF file to a fax message for sending. (see code sample provided with the installation)
More information
Create an instance of the API object as in the code sample and logon to the Server.
ZfAPIClass oZfAPI = new ZfAPIClass();
ZfLib.UserSession oUserSession;
ZfLib.NewMessage oNewMessage;
ZfLib.APIPrint oAPIPrint;
oUserSession = oZfAPI.Logon(" MyUserName" , false);
oNewMessage = oUserSession.CreateNewMsg(); //message to be sent
oAPIPrint = oUserSession.APIPrint; //APIPrint object
oAPIPrint.StartPrint("C:\MyOutputFile.tif"); //put Zetafax Printer into APIPrint //mode, and the next print job spooled convert into this TIF file.
//now we invoke Word and print a document using the Zetafax Printer
CMyWordObj m_oWordObj; //wrapper class for COM, handle to Word instance
CMyWordApp m_oWordApp; //wrapper class for COM, "Word.Application" object
CMyWordDoc m_oWordDoc; //wrapper class for COM, "Word.Document" object
CMyWordDocs m_oWordDocs; //wrapper class for COM, "Word.Documents" object
m_oWordObj.CreateDispatch(_T(" Word.Application" ));
//get the Word.Application object
m_oWordApp = m_oWordObj.get_Application();
//get the Word.Documents collection
m_oWordDocs = m_oWordObj.get_Documents();
//opening and printing a document in Word depends on its version, please see the //specifics of the parameters in the Word Object library, but this can be //abstracted through the use of these wrapper classes that call the actual COM //functions
m_oWordDoc = oWordDocs.Open("myDocumentToBeFaxed.doc");
//ensure the active printer in Word is the Zetafax Printer setting the //Word.Application.ActivePrinter property to "Zetafax Printer" (recommended)
//something like m_oWordApp.setActivePrinter("Zetafax Printer")
m_oWordApp.PrintOut();
//after printing is complete, the APIPrint mode is cleared, so you will need to use APIPrint.StartPrint every time you want to do this
//use a timer to poll the APIPrint object to see if printing is complete
//and use oAPIPrint.IsComplete to check the status
//when printing is complete, attach the file to the message for faxing
oNewMessage.Files.Add("C:\MyOutputFile.tif");
References
ZTN1273 - INFO: Common Programming Problems with the COM API
Last updated: 18/04/07 (PF/GR)