FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Is it possible to save a pdf file into a memo field?
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM

Is it possible to save a pdf file into a memo field?

Posted: Tue Nov 06, 2012 08:09 AM

Hi,
Is it possible to save/retrieve a pdf file to a memo field (without having to resort to ADS)?

If it is could anyone share some code snippets?

TIA

FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 824
Joined: Thu Oct 13, 2005 07:39 AM

Re: Is it possible to save a pdf file into a memo field?

Posted: Tue Nov 06, 2012 09:13 AM

maybe you can do it with blob, but I have noe xperience with it.

kind regards

Stefan
Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM

Re: Is it possible to save a pdf file into a memo field?

Posted: Tue Nov 06, 2012 02:42 PM
Code (fw): Select all Collapse
#INCLUDE "DBINFO.CH"
#INCLUDE "FILEIO.CH"

function my_file2blob( cFileName, cFieldName )
   local nHandle, lReturn := .f., bFieldBlock, cFileBuf
   local nPos
   bFieldBlock := fieldblock( cFieldName )
   nHandle := fopen( cFileName )
   if nHandle = -1
      Alert("Cannot access file " + cFileName)
   else
      nPos := fseek( nHandle,0,FS_END)
      if nPos > 0
         fseek( nHandle,0,FS_SET)
         cFileBuf:=space(nPos)
         fread(nHandle,@cFileBuf,nPos)
      endif
      lReturn := fclose(nHandle)
      if lReturn
         eval( bFieldBlock, cFileBuf )
      endif
   endif
return( lReturn )

function my_blob2file( cFileName, cFieldName )
   local nHandle, lReturn := .f., bFieldBlock
   bFieldBlock := fieldblock( cFieldName )
   nHandle := fcreate( cFileName )
   if nHandle = -1
      Alert("Cannot create file " + cFileName + ", export failed!")
   else
      if fwrite( nHandle, eval( bFieldBlock ) ) > 0
         lReturn := fclose( nHandle )
      else
         fclose( nHandle )
      endif
   endif
return( lReturn )
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM

Re: Is it possible to save a pdf file into a memo field?

Posted: Wed Nov 07, 2012 01:14 AM

Thanks Stefan and Gale :)

FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour

Continue the discussion