ImageToPDF COM
;==========================================================================================================================================
;
;   ImageToPDF.wbt  v.1.2
;
;   This is a WinBatch wrapper script for the 'Image Stream Object DLL'
;   envolved by FyTek, Inc. to convert an image or a group of images to PDF file.
;
;   This script makes use of the PDF Image Stream DLL Version 1.2.0.0
;   created 'Montag, 25. November 2002 18:09:27', size 2.301.952 Byte.
;
;   Detlev Dalitz.20020612.20030117
;
;==========================================================================================================================================
;
;   FyTek's PDF Image Stream is a program to convert an image or group of images to PDF.
;   Jpeg images are supported for the free version and
;   bitmap, jpeg, gif, png and tif (single or multi-page) for the commercial version.
;
;   Some features of this software product are:
;   - Combine multiple images into one PDF
;   - Create a PDF for each image
;   - Scan a directory and, optionally, its subdirectories for images
;   - Specify a list of images to convert from a file
;   - Size the image to the page or page to the image
;   - Include bookmarks, captions and page numbers
;
;   Each image occupies its own page in the PDF.
;   The image is centered on the page by default and not scaled unless it is larger than the page size.
;   You may chose to size the page to image size or vice-versa.
;
;
;   This WinBatch wrapper script "IMAGE2PDF.WBT" uses the free demo version of FyTek's "pdfimage.dll".
;   The demo version has not all methods activated but shows what is possible.
;
;   You may purchase a copy from FyTek, Inc. to work with more file formats and create thumbnail pages.
;   Feel free to visit FyTek's product showcase on "http://www.fytek.com/pdfprods.html".
;
;==========================================================================================================================================
;
;   This WinBatch script contains three sub modules and one main script.
;
;   sIPDF_Methods = udfIPDFGetMethods ()
;   - Returns a tab delimited itemlist containing all the method keywords of the current image stream object.
;
;   sIPDF_Options = udsIPDFGetOptions (mode)
;   - Returns a tab delimited itemlist containing only the options
;     resp. methods which are used and set in the main script.
;
;   iResult = udfIPDFPrint (IPDF_Options, mode)
;   - Evaluates the options set by the user and does the printing.
;   - Returns number of pages from pdf file on success or an error number on failure.
;
;   The 'mode' modifier describes what 'datapipe' is used
;   to submit user options from the main script into the print function:
;   mode = 1 ... uses an internal tabbed itemlist,
;   mode = 2 ... uses an external temporary ini-style textfile.
;
;==========================================================================================================================================
;
;   Note:
;   In order to run this script successfully you have to download FyTek's demo software
;   "FyTek PDF Image Stream". You will receive a file called "setupis.exe".
;   This file is a self extracting installation package and contains the "pdfimage.dll"
;   and further documentation about the software.
;
;   There exists also an "pdfimage.exe" Windows executable program.
;   It takes as input either a directory name followed by the types of images to include
;   or a file containing a list of images. The name of the output file comes next.
;   For example, run the following to convert all jpeg and gif images to a single
;   PDF in the directory "my documents":
;   pdfimage.exe "d:\my documents" *.jpg,*.gif mypics.pdffile
;   You see, there are many interesting things to play with.
;
;   FyTek's software is available as freeware with limited functionality.
;   The documentation covers all the commands available with the
;   commercial version.
;   The freeware version creates a PDF or PDFs from jpeg images only.
;   You can convert other image types such as bitmap, gif, png and tif images
;   but the words "FyTek, Inc. Image Stream Demo" will be printed across the page.
;   The commercial version does not print this.
;   In addition, the commercial version will allow you to convert
;   from one image type to another and create thumbnail pages from a set of images.
;
;   ---------------
;      Have fun!
;   --------------
;==========================================================================================================================================


;------------------------------------------------------------------------------------------------------------------------------------------
; udsIPDFGetOptions (__mode)
; udfIPDFGetMethods ()
; udfSubReturn (a, b)
; udfIPDFPrint (IPDF_Options, mode)  <== This is main user interface udf.
;------------------------------------------------------------------------------------------------------------------------------------------


;==========================================================================================================================================
If ItemLocate("udfipdfgetmethods",IntControl(77,103,0,0,0),@TAB) Then Goto skip_udfipdfgetmethods

#DefineFunction udfIPDFGetMethods ()
; Create a tab delimited list of all current methods, added user interface specific methods.

IPDF_MethodsList = ""
IPDF_MethodsList = ItemInsert("IPDF_pdfpages"           ,-1,IPDF_MethodsList,@TAB) ; pdfpages is a property.
IPDF_MethodsList = ItemInsert("IPDF_buildImage"         ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setBackground"      ,-1,IPDF_MethodsList,@TAB) ; Added 20030117.
IPDF_MethodsList = ItemInsert("IPDF_setBookmarks"       ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setBorder"          ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setBorderColor"     ,-1,IPDF_MethodsList,@TAB) ; Added 20030117.
IPDF_MethodsList = ItemInsert("IPDF_setBorderRaised"    ,-1,IPDF_MethodsList,@TAB) ; Added 20030117.
IPDF_MethodsList = ItemInsert("IPDF_setBorderSunken"    ,-1,IPDF_MethodsList,@TAB) ; Added 20030117.
IPDF_MethodsList = ItemInsert("IPDF_setCaption"         ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setCaptionText"     ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setCLA"             ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setDirectory"       ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setFit"             ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setForce"           ,-1,IPDF_MethodsList,@TAB) ; Added 20030117.
IPDF_MethodsList = ItemInsert("IPDF_setForceConv"       ,-1,IPDF_MethodsList,@TAB) ; Added 20030117.
IPDF_MethodsList = ItemInsert("IPDF_setImageRotate"     ,-1,IPDF_MethodsList,@TAB) ; Added 20030117.
IPDF_MethodsList = ItemInsert("IPDF_setImageSize"       ,-1,IPDF_MethodsList,@TAB) ; Splitted into separate Height and Width methods.
IPDF_MethodsList = ItemInsert("IPDF_setImageHeight"     ,-1,IPDF_MethodsList,@TAB) ; -->setImageSize.Height
IPDF_MethodsList = ItemInsert("IPDF_setImageWidth"      ,-1,IPDF_MethodsList,@TAB) ; -->setImageSize.Width
IPDF_MethodsList = ItemInsert("IPDF_setLandscape"       ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setLayout"          ,-1,IPDF_MethodsList,@TAB) ; Splitted into separate X, Y, Z methods.
IPDF_MethodsList = ItemInsert("IPDF_setLayoutAcross"    ,-1,IPDF_MethodsList,@TAB) ; Added 20030117.
IPDF_MethodsList = ItemInsert("IPDF_setLayoutDown"      ,-1,IPDF_MethodsList,@TAB) ; Added 20030117.
IPDF_MethodsList = ItemInsert("IPDF_setLayoutMargin"    ,-1,IPDF_MethodsList,@TAB) ; Added 20030117.
IPDF_MethodsList = ItemInsert("IPDF_setMake"            ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setMargin"          ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setMask"            ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setNotes"           ,-1,IPDF_MethodsList,@TAB) ; Added 20030117.
IPDF_MethodsList = ItemInsert("IPDF_setOpen"            ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setOutput"          ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setPageNum"         ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setPageRotate"      ,-1,IPDF_MethodsList,@TAB) ; Added 20030117.
IPDF_MethodsList = ItemInsert("IPDF_setPageSize"        ,-1,IPDF_MethodsList,@TAB) ; Splitted into separate Height and Width methods.
IPDF_MethodsList = ItemInsert("IPDF_setPageSizeHeight"  ,-1,IPDF_MethodsList,@TAB) ; -->setPageSize.Height
IPDF_MethodsList = ItemInsert("IPDF_setPageSizeWidth"   ,-1,IPDF_MethodsList,@TAB) ; -->setPageSize.Width
IPDF_MethodsList = ItemInsert("IPDF_setPDFAuthor"       ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setPDFCreator"      ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setPDFKeywords"     ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setPDFProducer"     ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setPDFSubject"      ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setPDFTitle"        ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setPoint"           ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setQuality"         ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setSearch"          ,-1,IPDF_MethodsList,@TAB) ; Added 20030117.
IPDF_MethodsList = ItemInsert("IPDF_setSearchOnly"      ,-1,IPDF_MethodsList,@TAB) ; Added 20030117.
IPDF_MethodsList = ItemInsert("IPDF_setSingle"          ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setSort"            ,-1,IPDF_MethodsList,@TAB) ; Splitted into separate SortBy method.
IPDF_MethodsList = ItemInsert("IPDF_setSortSortBy"      ,-1,IPDF_MethodsList,@TAB) ; Added 20030117.
IPDF_MethodsList = ItemInsert("IPDF_setSubDir"          ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setThumbnail"       ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setTNAcross"        ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setTNBGcolor"       ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setTNCap"           ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setTNFont"          ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setTNFrame"         ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setTNPoint"         ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setTNShadow"        ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setTrans"           ,-1,IPDF_MethodsList,@TAB) ; Added 20030117.
IPDF_MethodsList = ItemInsert("IPDF_setTransDir"        ,-1,IPDF_MethodsList,@TAB) ; Added 20030117.
IPDF_MethodsList = ItemInsert("IPDF_setTransMDir"       ,-1,IPDF_MethodsList,@TAB) ; Added 20030117.
IPDF_MethodsList = ItemInsert("IPDF_setTransSecs"       ,-1,IPDF_MethodsList,@TAB) ; Added 20030117.
IPDF_MethodsList = ItemInsert("IPDF_setXScale"          ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setYScale"          ,-1,IPDF_MethodsList,@TAB)
IPDF_MethodsList = ItemInsert("IPDF_setZoom"            ,-1,IPDF_MethodsList,@TAB)

Return (IPDF_MethodsList)

#EndFunction

:skip_udfipdfgetmethods
;==========================================================================================================================================


;==========================================================================================================================================
If ItemLocate("udfsubreturn",IntControl(77,103,0,0,0),@TAB) Then Goto skip_udfsubreturn

#DefineFunction udfSubReturn (a, b)
Return (a)
; Tricky use of WinBatch feature to get rid of global variables on return from a SubRoutine procedure
; but keep and return one variable prior to the dropping.
#EndFunction

:skip_udfsubreturn
;==========================================================================================================================================


;==========================================================================================================================================
If ItemLocate("udsipdfgetoptions",IntControl(77,103,0,0,0),@TAB) Then Goto skip_udsipdfgetoptions

#DefineSubRoutine udsIPDFGetOptions (__mode)

__MethodsList = udfIPDFGetMethods ()
__MethodsCount = ItemCount(__MethodsList, @TAB)

Select Min(2,Max(1,__mode))

Case 1 ; Use internal list variable.
   __Options = ""
   For __i=1 To __MethodsCount
      __Method = ItemExtract(__i, __MethodsList, @TAB)
      If IsDefined(%__Method%)
         __Options = ItemInsert(StrCat(__Method,"=",%__Method%), -1, __Options, @TAB)
      EndIf
   Next
   Break

Case 2 ; Use external ini file.
   __Options = FileCreateTemp("TMP")
   __section = "FyTek PDF Image Stream"
   For __i=1 To __MethodsCount
      __Method = ItemExtract(__i, __MethodsList,@TAB)
      If IsDefined(%__Method%)
         IniWritePvt(__section, __Method, %__Method%, __Options)
      EndIf
   Next
   IniWritePvt("","","",__Options) ; Flush inifile to disk.
   Break

EndSelect


Return (udfSubReturn(__Options,DropWild("__*")))
; Tricky use of WinBatch feature to get rid of global variables on return from a SubRoutine procedure
; but keep and return one variable prior to the dropping.

#EndSubRoutine

:skip_udsipdfgetoptions
;==========================================================================================================================================


;==========================================================================================================================================
If ItemLocate("udfipdfprint",IntControl(77,103,0,0,0),@TAB) Then Goto skip_udfipdfprint

#DefineFunction udfIPDFPrint (IPDF_Options, mode)

Select Min(2,Max(1,mode))

Case 1 ; Use internal list variable.
   If (IPDF_Options == "") Then Return (-3)

   keyname_count = ItemCount(IPDF_Options,@TAB)

   For i=1 To keyname_count
      option = ItemExtract(i,IPDF_Options,@TAB)
      keyname  = ItemExtract(1,option,"=")
      keyvalue = ItemExtract(2,option,"=")
      If (keyvalue == "") Then Return (-3)
      %keyname% = keyvalue  ; Create the variable and assign the value.
   Next

   Break

Case 2 ; Use external ini file.
   If (FileSize(IPDF_Options) == 0) Then Return (-4)

   ; Read the option values from inifile into variables.
   section = "FyTek PDF Image Stream Methods"
   keyname_list = IniItemizePvt(section,IPDF_Options)
   keyname_count = ItemCount(keyname_list,@TAB)

   For i=1 To keyname_count
      keyname = ItemExtract(i,keyname_list,@TAB)
      keyvalue = IniReadPvt(section,keyname,"",IPDF_Options)
      If (keyvalue == "") Then Return (-4)
      %keyname% = keyvalue  ; Create the variable and assign the value.
   Next

   FileDelete(IPDF_optionfile)

   Break

EndSelect

;------------------------------------------------------------------------------------------------------------------------------------------
; Register the scripting component.
sRegsvr32Exe = FileLocate("regsvr32.exe") ; Location of Windows Register Server.
sPdfimageDll = FileLocate("pdfimage.dll") ; Location of Fytek's "pdfimage.dll".
RunWait(sRegsvr32Exe,StrCat("/s ",sPdfimageDll)) ; Silent install and register "pdfimage.dll".
;------------------------------------------------------------------------------------------------------------------------------------------

IPDF_ = ObjectOpen("Image.Stream")

; If the script has not kicked off yet, then the component has been registered successfully,
; and we can go on working with the component.
; Here in this script we do not much error checking.
; Note: For productional purposes error handling is a must.

If IsDefined(IPDF_setCLA)
   ; Get the pseudo command line.
   ; Note: IPDF_setCLA string will be used as it is.
   ; We do no further evaluating here.
   If (IPDF_setCLA > "")
      iResult = IPDF_.setCLA (IPDF_setCLA)
   EndIf

Else
   ; Evaluate the user options.

   If IsDefined(IPDF_setDirectory)   Then iResult = IPDF_.setDirectory   (IPDF_setDirectory)

   If IsDefined(IPDF_setMask)        Then iResult = IPDF_.setMask        (IPDF_setMask)
   ; Do not use setMask if setDirectory uses an input listfile "@...", it may cause a  buildImage error = -1.
   ; This error has exist in dll versions prior to "pdfimage.ddl" v1.2.
   ; I do not know, if it still exists in "pdfimage.dll" v1.2, so check it for yourself!

   If IsDefined(IPDF_setOutput)                                      Then iResult = IPDF_.setOutput      (IPDF_setOutput)
   If IsDefined(IPDF_setSubDir)      Then If !!IPDF_setSubDir        Then iResult = IPDF_.setSubDir
   If IsDefined(IPDF_setOpen)        Then If !!IPDF_setOpen          Then iResult = IPDF_.setOpen
   If IsDefined(IPDF_setSingle)      Then If !!IPDF_setSingle        Then iResult = IPDF_.setSingle

   If IsDefined(IPDF_setSortSortBy)                                  Then iResult = IPDF_.setSort        (IPDF_setSortSortBy)

   If IsDefined(IPDF_setPageSizeWidth)
      If IsDefined(IPDF_setPageSizeHeight)
         iResult = IPDF_.setPageSize (IPDF_setPageSizeWidth,IPDF_setPageSizeHeight)
      EndIf
   EndIf

   If IsDefined(IPDF_setImageSizeWidth)
      If IsDefined(IPDF_setImageSizeHeight)
         iResult = IPDF_.setImageSize (IPDF_setImageSizeWidth,IPDF_setImageSizeHeight)
      EndIf
   EndIf

   If IsDefined(IPDF_setLayoutAcross)
      If IsDefined(IPDF_setLayoutDown)
         If IsDefined(IPDF_setLayoutMargin)
            iResult = IPDF_.setLayout (IPDF_setLayoutAcross,IPDF_setLayoutDown,IPDF_setLayoutMargin)
         EndIf
      EndIf
   EndIf

   If IsDefined(IPDF_setNotes)                                       Then iResult = IPDF_.setNotes(IPDF_setNotes)
   If IsDefined(IPDF_setSearch)      Then If !!IPDF_setSearch        Then iResult = IPDF_.setSearch
   If IsDefined(IPDF_setSearchOnly)  Then If !!IPDF_setSearchOnly    Then iResult = IPDF_.setSearchOnly

   If IsDefined(IPDF_setBackground)                                  Then iResult = IPDF_.setBackground  (IPDF_setBackground)
   If IsDefined(IPDF_setMargin)                                      Then iResult = IPDF_.setMargin      (IPDF_setMargin)
   If IsDefined(IPDF_setPageRotate)                                  Then iResult = IPDF_.setPageRotate  (IPDF_setPageRotate)
   If IsDefined(IPDF_setImageRotate)                                 Then iResult = IPDF_.setImageRotate (IPDF_setImageRotate)

   If IsDefined(IPDF_setCaption)     Then If !!IPDF_setCaption       Then iResult = IPDF_.setCaption
   If IsDefined(IPDF_setCaptionText)                                 Then iResult = IPDF_.setCaptionText (IPDF_setCaptionText)

   If IsDefined(IPDF_setBookmarks)   Then If !!IPDF_setBookmarks     Then iResult = IPDF_.setBookmarks
   If IsDefined(IPDF_setPageNum)     Then If !!IPDF_setPageNum       Then iResult = IPDF_.setPageNum
   If IsDefined(IPDF_setPoint)                                       Then iResult = IPDF_.setPoint       (IPDF_setPoint)

   If IsDefined(IPDF_setFit)                                         Then iResult = IPDF_.setFit         (IPDF_setFit)
   If IsDefined(IPDF_setZoom)                                        Then iResult = IPDF_.setZoom        (IPDF_setZoom)
   If IsDefined(IPDF_setLandscape)   Then If !!IPDF_setLandscape     Then iResult = IPDF_.setLandscape

   If IsDefined(IPDF_setBorder)                                      Then iResult = IPDF_.setBorder      (IPDF_setBorder)
   If IsDefined(IPDF_setBorderColor)                                 Then iResult = IPDF_.setBorderColor (IPDF_setBorderColor)
   If IsDefined(IPDF_setBorderRaised)                                Then iResult = IPDF_.setBorderRaised(IPDF_setBorderRaised)
   If IsDefined(IPDF_setBorderSunken)                                Then iResult = IPDF_.setBorderSunken(IPDF_setBorderSunken)

   If IsDefined(IPDF_setTrans)                                       Then iResult = IPDF_.setTrans       (IPDF_setTrans)
   If IsDefined(IPDF_setTransSecs)                                   Then iResult = IPDF_.setTransSecs   (IPDF_setTransSecs)
   If IsDefined(IPDF_setTransDir)                                    Then iResult = IPDF_.setTransDir    (IPDF_setTransDir)
   If IsDefined(IPDF_setTransMir)                                    Then iResult = IPDF_.setTransMir    (IPDF_setTransMir)

   If IsDefined(IPDF_setForce)       Then If !!IPDF_setForce         Then iResult = IPDF_.setForce

   If IsDefined(IPDF_setPDFTitle)                                    Then iResult = IPDF_.setPDFTitle    (IPDF_setPDFTitle)
   If IsDefined(IPDF_setPDFSubject)                                  Then iResult = IPDF_.setPDFSubject  (IPDF_setPDFSubject)
   If IsDefined(IPDF_setPDFAuthor)                                   Then iResult = IPDF_.setPDFAuthor   (IPDF_setPDFAuthor)
   If IsDefined(IPDF_setPDFKeywords)                                 Then iResult = IPDF_.setPDFKeywords (IPDF_setPDFKeywords)
   If IsDefined(IPDF_setPDFCreator)                                  Then iResult = IPDF_.setPDFCreator  (IPDF_setPDFCreator)
   If IsDefined(IPDF_setPDFProducer)                                 Then iResult = IPDF_.setPDFProducer (IPDF_setPDFProducer)

   ; The following options are used when creating images.
   ; These are features of the commercial version only.

   If IsDefined(IPDF_setMake)        Then iResult = IPDF_.setMake        (IPDF_setMake)
   If IsDefined(IPDF_setQuality)     Then iResult = IPDF_.setQuality     (IPDF_setQuality)
   If IsDefined(IPDF_setXScale)      Then iResult = IPDF_.setXScale      (IPDF_setXScale)
   If IsDefined(IPDF_setYScale)      Then iResult = IPDF_.setYScale      (IPDF_setYScale)
   If IsDefined(IPDF_setThumbnail)   Then iResult = IPDF_.setThumbnail   (IPDF_setThumbnail)
   If IsDefined(IPDF_setTNAcross)    Then iResult = IPDF_.setTNAcross    (IPDF_setTNAcross)
   If IsDefined(IPDF_setTNBGcolor)   Then iResult = IPDF_.setTNBGcolor   (IPDF_setTNBGcolor)
   If IsDefined(IPDF_setTNCap)       Then iResult = IPDF_.setTNCap       (IPDF_setTNCap)
   If IsDefined(IPDF_setTNPoint)     Then iResult = IPDF_.setTNPoint     (IPDF_setTNPoint)
   If IsDefined(IPDF_setTNFont)      Then iResult = IPDF_.setTNFont      (IPDF_setTNFont)

   If IsDefined(IPDF_setTNShadow)    Then If (1==IPDF_setTNShadow)      Then iResult = IPDF_.setTNShadow
   If IsDefined(IPDF_setTNFrame)     Then If (1==IPDF_setTNFrame)       Then iResult = IPDF_.setTNFrame
EndIf


; Create PDF document.
; iResult = -1 = Cannot open output file.
; iResult = -2 = No images to convert.
iResult = IPDF_.buildImage

If (iResult > -1) Then iResult = IPDF_.pdfPages

ObjectClose(IPDF_)

;------------------------------------------------------------------------------------------------------------------------------------------
; Un-Register the PDF Image component.
RunWait(sRegsvr32Exe,StrCat("/u /s ",sPdfimageDll)) ; Silent uninstall of "pdfimage.dll".
;------------------------------------------------------------------------------------------------------------------------------------------

Return (iResult)
;..........................................................................................................................................
; Returns iResult = -1  = Cannot open output file.
; Returns iResult = -2  = No images to convert.
;
; Returns iResult = -3  = Internal list variable has zero length.
; Returns iResult = -4  = External ini file has zero length.
;
; Returns iResult >= 0  = Number of pages enclosed in printed pdf file.
;
; For further documentation about "pdfimage.dll" and "PDF Image Stream"
; visit "FyTek, Inc. (http://www.fytek.com)"
;
; Detlev Dalitz.20020611.20030117
;..........................................................................................................................................
#EndFunction

:skip_udfistreamprint
;==========================================================================================================================================



; --- main ---

sMsgTitle = "Demo  IMAGE2PDF.WBT"
sMsgText  = " ... begins now ..."
Display(1,sMsgTitle,sMsgText)


; We have to start somewhere in the galaxy ...
sAFN_folder = DirWindows(0)

While @TRUE

   ; To leave the loop push cancel button in dialog AskFileName.
   sAFN_title     = StrCat(sMsgTitle," - choose image files -")
   sAFN_filetypes = "Image Files|*.jpg;*.bmp;*.gif|All Files|*.*"
   sAFN_filename  = "*.jpg;*.bmp;*.gif"
   sAFN_flag      = 2
   sAFN_filelist  = AskFilename(sAFN_title,sAFN_folder,sAFN_filetypes,sAFN_filename,sAFN_flag)
   If (sAFN_filelist == 0) Then Break
   sAFN_folder    = FilePath(ItemExtract(1,sAFN_filelist,@TAB))
   DirChange(sAFN_folder)

   sMsgTitle = "Demo  IMAGE2PDF.WBT"
   sMsgText  = "... please wait ..."
   Display(1,sMsgTitle,sMsgText)


   ; Write temporary listfile.
   sListfile = FileCreateTemp("TMP")
   hFW = FileOpen(sListfile,"WRITE")
   FileWrite(hFW,StrReplace(sAFN_filelist,@TAB,@CRLF))
   FileClose(hFW)


   ; Prepare a unique output filename.
   sYmdhms   = StrReplace(TimeYmdHms(),":","")
   sYYYYMMDD = StrSub(sYmdHms,1,8)
   sHHMMSS   = StrSub(sYmdHms,9,6)

;..........................................................................................................................................

   ; Create one multipage pdf.
   ; Use FyTek PDF Image Stream Object DLL.

   IPDF_setOutput          = FileFullname(StrCat(FilePath(sListfile),"FyTek.",sYYYYMMDD,".",sHHMMSS,".pdf"))
   IPDF_setDirectory       = StrCat("@",FileFullname(sListfile))

   IPDF_setPDFTitle        = "Title ............ Title ............ Title"
   IPDF_setPDFSubject      = "************* Subject **************"
   IPDF_setPDFAuthor       = "Author"
   IPDF_setPDFKeywords     = "Keywords Keywords Keywords Keywords Keywords Keywords"
   IPDF_setPDFCreator      = "PDF Image Stream"
   IPDF_setPDFProducer     = "FyTek, Inc. (http://www.fytek.com)"

   IPDF_setMargin          = 0.5        ;    0.5 inches = 12.7 mm
   IPDF_setPageSizeWidth   = 8.267      ;  8.267 inches = 210 mm
   IPDF_setPageSizeHeight  = 11.692     ; 11.692 inches = 297 mm

   IPDF_setImageSizeWidth  = 450        ; Pixel.
   IPDF_setImageSizeHeight = 450        ; Pixel.
   IPDF_setImageRotate     = 0          ; Angel clockwise. Must be either 0 (the default), 90, 180 or 270.

   ;   IPDF_setLayoutAcross    = 2          ; Number of images in horizontal direction.
   ;   IPDF_setLayoutDown      = 3          ; Number of images in vertival direction.
   ;   IPDF_setLayoutMargin    = 0.5        ;    0.5 inches = 12.7 mm

   IPDF_setFit             = "image"
   IPDF_setBookmarks       = 1
   IPDF_setCaption         = 1
   IPDF_setPoint           = 8

   ;   IPDF_setBorder          = 4          ; Places a border around each image of specified pixel size.
   IPDF_setBorderColor     = "#3366FF"  ; A shade of blue.
   IPDF_setBorderRaised    = 10         ; Pixel.

   IPDF_setTrans           = "Random"   ; Types: Split, Blinds, Box, Wipe, Dissolve, Glitter, Random.
   IPDF_setTransSecs       = 1          ; Seconds.
   IPDF_setTransDir        = "H"        ; Types: H, V.

   IPDF_setSortSortBy      = "fr"       ; Sort by filename in reverse order.
   IPDF_setZoom            = 120        ; Set zoomed view to 120 percent.
   IPDF_setOpen            = 1          ; Open pdf reader application after print.


   ; Now we have set all parameters, and the Print function can do the work.
   iResult = udfIPDFPrint(udsIPDFGetOptions(1),1)

;..........................................................................................................................................

   ; Message to the user.
   Select (iResult > 0)
   Case 1
      sMsgText  = StrCat("Success. ",@LF,iResult," pages printed into one PDF file.")
      Break
   Case 0
      sMsgText  = StrCat("No Success.",@LF,"Error number is: ",iResult)
      Break
   EndSelect
   Message(sMsgTitle,sMsgText)


   ; Cleaning.
   FileDelete(sListfile)

EndWhile

:CANCEL
sMsgText  = " ... ends now."
Display(1,sMsgTitle,sMsgText)

Exit



;==========================================================================================================================================
; Using the DLL (Dynamic Link Library) "pdfimage.dll"
;==========================================================================================================================================
; PDF Image Stream
; © 2000-2002 by FyTek, Inc. Excerpt from the manual.
;..........................................................................................................................................
;   The file pdfimage.dll is the dynamic link library.
;   This file should reside in your Windows or WinNT directory under the system32 sub-directory.
;   You first must register the DLL on your system (note this step happens automatically when you run the setup program).
;   Do this by running regsvr32 pdfimage.dll. You should see a message box that reads:
;   DllRegisterServer in pdfimage.dll succeeded.
;   Click OK to continue.
;   You are now ready to use the DLL.
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
; DLL Properties
; - Property
; - Description
;..........................................................................................................................................
;   pdfPages
;   Returns the total number of pages created in the PDF.
;   The property may be checked after the method buildImage has been called.
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
; DLL Methods
; - Method
; - Description
;..........................................................................................................................................
;   buildImage
;   Call this method create the PDF,
;   images or thumbnail. Set the
;   parameters described in the following
;   methods first then call this method.
;   This function returns the name of the
;   PDF file when using setOutput.
;   Otherwise it will return the PDF
;   stream which is useful if you want to
;   send it to a web browser.
;   The following are error codes which
;   may be returned so you'll need to
;   check for these:
;   -1 = Cannot open output file
;   -2 = No images to convert
;..........................................................................................................................................
;   setCLA(text)
;   Can be used as a shortcut to setting
;   the methods described below. Use
;   setCLA (set command line attributes)
;   to set a string of attributes that would
;   normally be sent to the executable
;   version.
;   For example, you can run
;   'setCLA("""d:\my pics\images"" *.jpg,*.gif d:\temp\output.pdf -s")'
;   and set everything at once or use
;   setDirectory, setMask, setOutput and setSubDir and set individually.
;   You can use all of the command line options with setCLA.
;..........................................................................................................................................
;   setDirectory(path or @file)
;   Provide either the path to use for scanning for images or a file name preceeded by an @ symbol.
;   For example, setDirectory ("d:\my documents") or setDirectory ("@d:\temp\mylist.dat").
;   This may also be a Web page or image.
;   For example, setDirectory ("http://www.fytek.com/pdfimg.html")
;   or setDirectory ("http://www.fytek.com/logo.jpg").
;   For Web pages, the page text is scanned for IMG tags.
;   Those images are placed in the PDF.
;   Using a web address will print "Demo" across each page in the free version.
;..........................................................................................................................................
;   setMask(comma separated list)
;   Provide a comma separated list of file
;   names to include. This option is only
;   necessary when a path is used for the
;   setDirectory method. You do not
;   need to set this when providing a file
;   to setDirectory.
;..........................................................................................................................................
;   setOutput(path-file)
;   Provide the path and name of the
;   output file. This should be a file with
;   a .pdf extension. This should be set to
;   a directory only when using the
;   setSingle method described below.
;   setSingle will create a separate PDF
;   file for each image. The directory
;   passed to setOutput will be used to
;   store the PDF files in. You may also
;   leave this blank if you want the PDF
;   contents returned as output from the
;   buildImage function.
;..........................................................................................................................................
;   setSubDir
;   Search in subdirectories as well when
;   specifying and input directory and file
;   mask. This is not used when a file
;   name is passed to setDirectory.
;..........................................................................................................................................
;   setOpen
;   Automatically opens the newly
;   created PDF. Only works when
;   creating a PDF and not using the
;   setSingle method.
;..........................................................................................................................................
;   setSingle
;   Create a single PDF for each image.
;   The files are created in the source
;   directory if the output file path is left
;   off. You set the output path with the
;   setOutput method when using this
;   option.
;..........................................................................................................................................
;   setSort(sortby)
;   Used to specify the sort order when creating the images in the PDF.
;   Pass in one of the following for sortby:
;      f = file name
;      b = file size in bytes
;      d = last modify date
;   You may also use an r along with any of the above to sort in decending order.
;   For example, rf or fr sorts by name in decending order.
;..........................................................................................................................................
;   setPageSize width, height
;   Sets the width and height of the page in inches. Default is 8.5, 11.
;..........................................................................................................................................
;   setImageSize width, height
;   Sets the width and height for all images in pixels.
;..........................................................................................................................................
;   setLayout across, down, margin
;   Sets the number of images across and down on each page.
;   The margin is in inches and is used to set the spacing around each image.
;   The default is one image per page.
;   Using this method will print "Demo" across each page in the free version.
;..........................................................................................................................................
;   setNotes(directory)
;   A directory containing .txt files with the same basename as the images.
;   For example, if an image is named sunset.jpg the program will look for sunset.txt
;   in the directory specified with this option.
;   A pop-up note is added to the page the image is on if the text file is found.
;   The contents of the note are taken from the text file.
;   Using this option will print "Demo" across each page in the free version.
;..........................................................................................................................................
;   setSearch
;   Use along with the setNotes method.
;   This option places the notes text as invisible text on the page behind the image.
;   This allows you to use the search feature to lookup an image in the PDF based on this text.
;..........................................................................................................................................
;   setSearchOnly
;   Use along with the setNotes method.
;   Works the same as the setSearch method except the pop-up notes are not placed in the PDF.
;   The notes are only used as searchable text in this case.
;..........................................................................................................................................
;   setBackground(file)
;   An image file to use as the background for each page.
;   Using this method will print "Demo" across each page in the free version.
;..........................................................................................................................................
;   setMargin(width)
;   Sets the width of the margin in inches. Default is .75.
;..........................................................................................................................................
;   setPageRotate(angle)
;   Sets the rotation angle (clockwise) for each page in the PDF.
;   Must be either 0 (the default), 90, 180 or 270.
;..........................................................................................................................................
;   setImageRotate(angle)
;   Sets the rotation angle (clockwise) for each image in the PDF.
;   Must be either 0 (the default), 90, 180 or 270.
;..........................................................................................................................................
;   setCaption
;   Displays the caption at the bottom of the image.
;   The caption is the file name unless specified using an input file.
;   A comma separates the caption from the file name in the input file.
;   For example:
;   d:\my images\pic1.jpg,At the cottage
;   d:\my images\pic2.gif,Ski trip - photo taken November 20, 2001
;   d:\my images\pic3.gif
;   d:\my images\pic4.jpg,View of the lake from porch
;   Each image must be on a separate line when using an input file.
;   The caption must be on the same line as the image and not span lines in the file.
;..........................................................................................................................................
;   setBookmarks
;   Add bookmarks. The description for the bookmark is the same as the caption.
;..........................................................................................................................................
;   setCaptionText(text)
;   The caption for each image.
;   The following may be used as variables in the string for the caption:
;      %f - file name
;      %d - directory
;      %b - file size
;      %w - width
;      %h - height
;   For example, "Image %f - %b, %wX%h"
;   will come out looking something like "Image abc.jpg - 25148, 200X350".
;..........................................................................................................................................
;   setPageNum
;   Adds page numbers centered at the bottom of each page.
;..........................................................................................................................................
;   setPoint(size)
;   Sets the point size used for captions and page numbers. Default is 12.
;..........................................................................................................................................
;   setFit("image" or "page")
;   Set to image to size each page to the size of the image + the margin.
;   Set to page to size each image to the size ofthe page - the margin.
;   Sizing to page will make the image large enough to fit either width or length wise
;   without losing the aspect ratio.
;   That is, the image will not be streched more in one direction than the other.
;   The default is to leave the image as is centered on the page and only reduce
;   in size if it doesn't fit on the page.
;..........................................................................................................................................
;   setZoom(percent)
;   Sets the zoom factor to use when the document is opened.
;   Setting to 100 means to open the document at 100%.
;..........................................................................................................................................
;   setLandscape
;   Sets page to landscape mode. This is 11 by 8.5 unless the -page option was used.
;..........................................................................................................................................
;   setBorder(width)
;   Places a border around each image at the specified width.
;..........................................................................................................................................
;   setBorderColor(color)
;   The color of the border as a hex value of red, green and blue values from 00 to FF.
;   Use a # in front of the value.
;   For example, black is #000000 while a shade of blue would be #3366FF.
;..........................................................................................................................................
;   setBorderRaised(width)
;   The width for a raised border.
;   You do not have to use the setBorder method along with this one.
;   The edges of the image are lightened/darkened to provide a raised effect.
;..........................................................................................................................................
;   setBorderSunken(width)
;   The width for a sunken border.
;   You do not have to use the setBorder method along with this one.
;   The edges of the image are lightened/darkened to provide a sunken effect.
;..........................................................................................................................................
;   setTrans(text)
;   One of the following transition types:
;      Split
;      Blinds
;      Box
;      Wipe
;      Dissolve
;      Glitter
;      Random
;   The default page transition is to just replace the current page with the new page.
;   The effects listed above can be used for presentation purposes.
;   The random option shown above will pick one of the transition types at random for each page.
;..........................................................................................................................................
;   setTransSecs(number)
;   The length of time in seconds to spend on the page transition.
;   Default is 1 if a transition type is used..
;..........................................................................................................................................
;   setTransDir(H or V)
;   The direction of the transition, horizontal or vertical (H or V).
;   Valid only for Split and Blinds transition types.
;..........................................................................................................................................
;   setTransMDir(I or O)
;   The direction of motion for the transition effect,
;   inward or outward (I or O) from the center of the page.
;   Valid only for Split and Box transition types.
;..........................................................................................................................................
;   setForce
;   Turns off the prompt to overwrite the output file if it already exists.
;..........................................................................................................................................
;   setPDFTitle(text)
;   Sets the title of the PDF.
;..........................................................................................................................................
;   setPDFAuthor(text)
;   Sets the author of the PDF.
;..........................................................................................................................................
;   setPDFSubject(text)
;   Sets the subject of the PDF.
;..........................................................................................................................................
;   setPDFCreator(text)
;   Sets the creator of the PDF.
;..........................................................................................................................................
;   setPDFProducer(text)
;   Sets the producer of the PDF.
;..........................................................................................................................................
;   setPDFKeywords(text)
;   Sets the keywords for the PDF.
;..........................................................................................................................................


;..........................................................................................................................................
;   The following options are used when creating images (these are features
;   of the commercial version only)
;..........................................................................................................................................
;   setMake(type)
;   Sets the type of images to create. One
;   of the following: bmp, jpg, gif, tif or
;   png. The output file name should be
;   set to the directory you want the
;   images placed in or the current
;   directory will be used. Images created
;   will be of the same base name as the
;   original but not overwrite any
;   existing images. For example, if you
;   converting jpges to gis and you have
;   a file called mypic.jpg you'll get a file
;   called mypic.gif. If you convert again,
;   you'll get an image called
;   mypic_1.gif and, if that name exists
;   mypic_2.gif and so on.
;..........................................................................................................................................
;   setQuality("high" or "low")
;   Sets the quality of jpeg images
;   created to high (larger file size but
;   better image quailty) or low (smaller
;   file size and less quailty).
;..........................................................................................................................................
;   setXScale(number)
;   amount to scale each image in the x
;   direction entered as a percentage. For
;   example, 50% will scale all images
;   by 50 percent in width while 50 will
;   set each image to 50 pixels wide.
;..........................................................................................................................................
;   setYScale(number)
;   amount to scale each image in the y
;   direction entered as a percentage. For
;   example, 50% will scale all images
;   by 50 percent in height while 50 will
;   set each image to 50 pixels high.
;..........................................................................................................................................
;   setThumbnail(size)
;   Use this option to create one
;   thumbnail image containing all the
;   individual images. Set to the size of
;   each image along with spacing in
;   pixels formatted as #x#+#+# where
;   the # sign is a number of pixels. For
;   example, 50x75+5+10 means create
;   images 50 pixels wide by 75 pixels
;   high and leave 5 pixels in the x
;   direction bewteen images and 10
;   pixels in the y direction.
;..........................................................................................................................................
;   The following options are available only when using the -thumbnail option
;..........................................................................................................................................
;   setTNAcross(number)
;   The number of thumbnail images to
;   place in a single row. For example,
;   setting to 5 means put five images
;   across from one another before
;   dropping down to the next row to
;   start another five images.
;..........................................................................................................................................
;   setTNBGcolor(color)
;   The background color in hex form -red,
;   green, blue pairs. For example,
;   #000000 is black and #FFFFFF is
;   white.
;..........................................................................................................................................
;   setTNCap(text)
;   The caption for each image in the
;   thumbnail. The following may be
;   used as variables in the string for the
;   caption:
;   %f - file name
;   %d - directory
;   %e - extension
;   %b - file size
;   %w - width
;   %h - height
;   For example, "Image %f - %b, %wX%h" will come out looking
;   something like "Image abc.jpg - 25K, 200X350".
;..........................................................................................................................................
;   setTNPoint(size)
;   The pointsize for the captions.
;   Default is 10.
;..........................................................................................................................................
;   setTNFont(path-file)
;   The truetype font file to use for the
;   caption.
;..........................................................................................................................................
;   setTNShadow
;   Set this to place a shadow behind
;   each thumbnail image.
;..........................................................................................................................................
;   setTNFrame
;   Set this to place a frame around each
;   thumbnail image.
;..........................................................................................................................................
; © 2000-2002 by FyTek, Inc.
;==========================================================================================================================================



;==========================================================================================================================================
; It is strongly recommended to read Fytek's manual!
; There are further examples how to use the component,
; e.g. 'Scan the directory "d:\my documents" and all subdirectories for jpegs
;       and create a single PDF for each image in the directory d:\pdfpics.'
;==========================================================================================================================================



;==========================================================================================================================================
; external ini-style options file
;------------------------------------------------------------------------------------------------------------------------------------------
;   [FyTek PDF Image Stream Properties]
;   IPDF_pdfPages=
;
;   [FyTek PDF Image Stream Methods]
;   IPDF_buildImage=
;   IPDF_setBackground=
;   IPDF_setBookmarks=
;   IPDF_setBorder=
;   IPDF_setBorderColor=
;   IPDF_setBorderRaised=
;   IPDF_setBorderSunken=
;   IPDF_setCaption=
;   IPDF_setCaptionText=
;   IPDF_setCLA=
;   IPDF_setDirectory=
;   IPDF_setFit=
;   IPDF_setForce=
;   IPDF_setForceConv=
;   IPDF_setImageRotate=
;   IPDF_setImageSize=
;   IPDF_setImageHeight=
;   IPDF_setImageWidth=
;   IPDF_setLandscape=
;   IPDF_setLayout=
;   IPDF_setLayoutX=
;   IPDF_setLayoutY=
;   IPDF_setLayoutZ=
;   IPDF_setMake=
;   IPDF_setMargin=
;   IPDF_setMask=
;   IPDF_setNotes=
;   IPDF_setOpen=
;   IPDF_setOutput=
;   IPDF_setPageNum=
;   IPDF_setPageRotate=
;   IPDF_setPageSize=
;   IPDF_setPageSizeHeight=
;   IPDF_setPageSizeWidth=
;   IPDF_setPDFAuthor=
;   IPDF_setPDFCreator=
;   IPDF_setPDFKeywords=
;   IPDF_setPDFProducer=
;   IPDF_setPDFSubject=
;   IPDF_setPDFTitle=
;   IPDF_setPoint=
;   IPDF_setQuality=
;   IPDF_setSearch=
;   IPDF_setSearchOnly=
;   IPDF_setSingle=
;   IPDF_setSort=
;   IPDF_setSortSortBy=
;   IPDF_setSubDir=
;   IPDF_setThumbnail=
;   IPDF_setTNAcross=
;   IPDF_setTNBGcolor=
;   IPDF_setTNCap=
;   IPDF_setTNFont=
;   IPDF_setTNFrame=
;   IPDF_setTNPoint=
;   IPDF_setTNShadow=
;   IPDF_setTrans=
;   IPDF_setTransDir=
;   IPDF_setTransMDir=
;   IPDF_setTransSecs=
;   IPDF_setXScale=
;   IPDF_setYScale=
;   IPDF_setZoom=
;==========================================================================================================================================


;==========================================================================================================================================
; Usage: regsvr32 [/u] [/s] [/n] [/i[:cmdline]] dllname
; /u - Unregister server
; /s - Silent; display no message boxes
; /c - Console output
; /i - Call DllInstall passing it an optional [cmdline]; when used with /u calls dll uninstall
; /n - do not call DllRegisterServer; this option must be used with /i
;==========================================================================================================================================
;*EOF*