$PBExportHeader$gf_imagetopdf.srf
global type gf_imagetopdf from function_object
end type

forward prototypes
global function string gf_imagetopdf (string as_image)
end prototypes

global function string gf_imagetopdf (string as_image);String ls_pdf, ls_format
nvo_scannerwia ln_wia
Long ll_rtn
Integer li_FormatLen

li_FormatLen = Len(as_image) - LastPos(as_image, ".") + 1

ls_format = lower(mid(as_image, LastPos(as_image, "."),  li_FormatLen))

ls_pdf = replace(as_image, pos(as_image, ls_format), li_FormatLen, ".pdf")
	
IF FileExists(ls_pdf) THEN FileDelete(ls_pdf)
	
ln_wia =  CREATE  nvo_scannerwia

ln_wia.of_ConvertPdf(as_image, ls_pdf)
	
//Checks the result
If ln_wia.il_ErrorType < 0 Then
  messagebox("Failed", ln_wia.is_ErrorText)
  ls_pdf =""
End If

DESTROY ln_wia

RETURN ls_pdf

end function

