Code: Select all
PROCEDURE ConvertTIFToFax
LPARAMETERS cInFile, cOutFile
WITH oImaging AS GdPicturePro5.Imaging
LOCAL nImage,nPgCnt,nNewImage,lnPageCnt,n,nNewMultiPage,lcTmpFile
lcTmpFile = SYS(3)+SYS(2015)+'.TIF'
COPY FILE "&cInFile" TO "&lcTmpFile"
IF NOT DIRECTORY('.\WORK\')
MKDIR '.\WORK\'
ENDIF
DELETE FILE '.\WORK\*'
nImage = .TiffCreateMultiPageFromFile("&lcTmpFile")
nPgCnt = .TiffGetPageCount(nImage)
lnPageCnt = 0
FOR N = 1 TO nPgCnt
.TiffSelectPage(nImage,N)
.SetContrast(150)
.ConvertTo1Bpp()
.SaveAsTIFF(".\WORK\"+PADL(ALLTRIM(TRANSFORM(n)),2,'0')+'.tif',4)
ENDFOR
.CloseImage(nImage)
FOR n = 1 TO nPgCnt
nImage = .CreateImageFromFile(".\WORK\"+PADL(ALLTRIM(TRANSFORM(n)),2,'0')+'.tif')
IF lnPageCnt = 0
.TiffSaveAsNativeMultiPage("&cOutFile",4)
ELSE
.TiffAddToNativeMultipage(nImage)
ENDIF
lnPageCnt = lnPageCnt + 1
.CloseImage(nImage)
ENDFOR
.TiffCloseNativeMultiPage()
DELETE FILE "&lcTmpFile"
DELETE FilE ".\WORK\*"
ENDWITH
ENDPROC
In Windows XP, this code will take an input multipage tiff, convert each page to B&W, boost the contrast a bit, and save to the output file. Each page of the target TIFF is saved as Group 4 Fax encoding. In Windows 7, only the first page of the multipage tiff is saved as CCITT4, the rest are saved as LZW.