Visual Foxpro - Tips & Tricks

PDF - Report aus VFP erstellen

   
Autor : n.Olivier
Firma : Nachbagauer Olivier
Copyright 2002
Nutzungsbedingungen -
Homepage www.nOlivier.Com
eMail Nachbagauer Olivier
Allgemein -
Verwendung

Foxpro 6.0, 7.0, 8.0

 

   
   
 

1) Einen Postscript-Drucker installieren und die Ausgabe in 'File' umleiten
   ( z.B. HP Color LaserJet PS )

2) ghost (google: gs704w32 ghost)
    oder von GhostScript selbst.

3) Folgende Win-Appis werden benötigt :

  Declare Integer CreateProcess In kernel32.Dll ;
   INTEGER lpApplicationName, ;
   STRING lpCommandLine, ;
   INTEGER lpProcessAttributes, ;
   INTEGER lpThreadAttributes, ;
   INTEGER bInheritHandles, ;
   INTEGER dwCreationFlags, ;
   INTEGER lpEnvironment, ;
   INTEGER lpCurrentDirectory, ;
   STRING @lpStartupInfo, ;
   STRING @lpProcessInformation

  Declare Integer WaitForSingleObject In kernel32.Dll ;
   INTEGER hHandle, Integer dwMilliseconds

  Declare Integer CloseHandle In kernel32.Dll ;
   INTEGER hObject

4) Code zum erstellen:


cPrn = <Printer> && Druckername
cPrnFile = <c:\temp\Temp.ps> && Postscript-Datei
cPdf = <my.pdf> && Ausgabe-Name
cPdfPath = <c:\temp\> && Speicher-Pfad Ausgabe
cRep = <myVfpReport> && VFP - Reportname

report form &cRep noconsole to file &cPrnFile

if !file(cPrnFile)
  return .f.
endif

x = ADDBS(JUSTPATH(<PfadzuGsWin32>));
  + 'GsWin32.exe -q -dSAFER -dQUIT -dBATCH -dNOPAUSE -sDEVICE#pdfwrite ';
  + '-sOutputFile#"'; + cPdfPath+cPdf+'" -dnodisplay -dCompatibilityLevel#1.2 ';
  + '-c .setpdfwrite -f "'+cPrnFile +'"'+ Chr(0)

xStart = CHR(68) + CHR(0) + CHR(0) + CHR(0) ;
  + CHR(0) + CHR(0) + CHR(0) + CHR(0) + CHR(0) ;
  + CHR(0) + CHR(0) + CHR(0) + CHR(0) + CHR(0) ;
  + CHR(0) + CHR(0) + CHR(0) + CHR(0) + CHR(0) ;
  + CHR(0) + CHR(0) + CHR(0) + CHR(0) + CHR(0) ;
  + CHR(0) + CHR(0) + CHR(0) + CHR(0) + CHR(0) ;
  + CHR(0) + CHR(0) + CHR(0) + CHR(0) + CHR(0) ;
  + CHR(0) + CHR(0) + CHR(0) + CHR(0) + CHR(0) ;
  + CHR(0) + CHR(0) + CHR(0) + CHR(0) + CHR(0) ;
  + CHR(1) + CHR(0) + CHR(0) + CHR(0) + CHR(2) ;
  + CHR(0) + CHR(0) + CHR(0) + CHR(0) + CHR(0) ;
  + CHR(0) + CHR(0) + CHR(0) + CHR(0) + CHR(0) ;
  + CHR(0) + CHR(0) + CHR(0) + CHR(0) + CHR(0) ;
  + CHR(0) + CHR(0) + CHR(0) + CHR(0)

xProcess=Replicate(Chr(0), 16)
RetCode = CreateProcess(0, x, 0, 0, 1, 128, 0, 0, @xStart, @xProcess)
hProcess = str2long(Substr(xProcess, 1, 4))

Do While .T.
    If WaitForSingleObject(hProcess,200) != 0x00000102
      Exit
    Else
      DoEvents
    Endif
Enddo

nil = CloseHandle(hProcess)
delete file cPrnFile
if file(cPdfPath+cPdf)
  return .t.
else
  return .f.
endif