Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Start a PowerBuilder or a Visual BAsic application from
Message
De
29/08/2002 10:10:16
Patrick O'Neil
American Specialty Information Services
Roanoke, Indiana, États-Unis
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00694183
Message ID:
00694916
Vues:
16
> The example you showed, misses couple of function declarations and
> few custom functions code. Could you include them in your reply, please?


Hi Nadya -

sure. the portion i showed before only fires up distiller and waits
for it to complete.

my use of this feature was to send various VFP reports to the distiller,
generating postscript (.PS) files (and automatically generate the root
name for these .PS files by including a sequence number so i could
assure they appeared in the combined .PDF in the order they were
generated).

this procedure finds all those .PS files and builds a combiner script
by appending those names to a hard-coded command string you see in the
code. then distiller is run, supplying this combiner script as a
parameter, which generates the combined .PDF file.

i didn't include a couple utility functions (like Wildcard_Delete_Files).
i think those are obvious.
*--------------------------------------------------------------------
*  FILE define_api_constants.h
*--------------------------------------------------------------------

      #DEFINE NORMAL_PRIORITY_CLASS     32
      #DEFINE IDLE_PRIORITY_CLASS       64
      #DEFINE HIGH_PRIORITY_CLASS      128
      #DEFINE REALTIME_PRIORITY_CLASS 1600

      * Return code from WaitForSingleObject() if
      * it timed out.
      #DEFINE WAIT_TIMEOUT 0x00000102

      * This controls how long, in milli secconds, WaitForSingleObject()
      * waits before it times out. Change this to suit your preferences.
      #DEFINE WAIT_INTERVAL 200

      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

      DECLARE INTEGER GetLastError IN kernel32.DLL




*--------------------------------------------------------------------
*  PROCEDURE Combine_Postscript_Files_Into_PDF
*--------------------------------------------------------------------
PROCEDURE Combine_PostScript_Files_Into_PDF

  PARAMETER PARAM_Current_Form
  
  
  PARAM_Current_Form.ENABLED = .F.

  #INCLUDE Define_API_Constants.h

  LOCAL EVAL_PDF_Dir_Spec
  LOCAL PS_PDF_Combiner_File_Name
  LOCAL PS_PDF_Combiner_File_Spec
  LOCAL File_Handle
  LOCAL Pre_Output_String
  LOCAL Output_String
  LOCAL FPUTS_Status
  LOCAL Combined_PDF_File_Spec



  EVAL_PDF_Dir_Spec = ALLTRIM(PIX_DATA_Dir_Spec)              + ;
                      ALLTRIM(CATALOG_RECORD_OBJECT.mod_name) + ;
                      '\PDF\'

  Combined_PDF_File_Spec    = ALLTRIM(EVAL_PDF_Dir_Spec) + ALLTRIM(CATALOG_Record_Object.mod_name) + '.PDF'

  *----------------------------------------------get list of RPT*.PS files in EVAL_PDF_dir---
  LOCAL ARRAY File_Name_Array(1)

  LOCAL File_Name_Index
  LOCAL File_Name_Count
  LOCAL File_Name

  File_Name_Skeleton = ALLTRIM(EVAL_PDF_Dir_Spec) + 'RPT*.PS'
  File_Name_Count = ADIR ( File_Name_Array , File_Name_Skeleton )

  IF ( File_Name_Count = 0 )
    =MESSAGEBOX ( EVAL_PDF_Dir_Spec , 0 , 'There are no PostScript files to convert' )
    RETURN
  ENDIF

  
  PS_PDF_Combiner_File_Name = ALLTRIM(CATALOG_Record_Object.mod_name) + '.PS'
  PS_PDF_Combiner_File_Spec = ALLTRIM(EVAL_PDF_Dir_Spec) + ALLTRIM(PS_PDF_Combiner_File_Name)

    
  DELETE FILE (PS_PDF_Combiner_File_Spec)
  File_Handle = FCREATE ( PS_PDF_Combiner_File_Spec )
  
  IF ( File_Handle = -1 )
    IF ( FILE(PS_PDF_Combiner_File_Spec) )
      DELETE FILE (PS_PDF_Combiner_File_Spec)
    ENDIF
    =MESSAGEBOX ( PS_PDF_Combiner_File_Spec , 0 , 'Could not create PDF Combiner file' )
    RETURN
  ENDIF


  Output_String = '/prun { /mysave save def dup = flush RunFile clear cleardictstack mysave restore } def'
  FPUTS_Status = FPUTS( File_Handle , Output_String )

    
  FOR File_Name_Index = 1 TO File_Name_Count
    File_Name = ALLTRIM(File_Name_Array(File_Name_Index,1))
    Pre_Output_String = '(' + ALLTRIM(EVAL_PDF_Dir_Spec) + ALLTRIM(File_Name) + ') prun'   
    Output_String = STRTRAN(Pre_Output_String , '\' , '/' )
    FPUTS_Status = FPUTS( File_Handle , Output_String )
  ENDFOR

  FCLOSE ( File_Handle )


  *------------------------------------------------run distiller and wait for close the window--------------
  LOCAL Startup_Info
  LOCAL Process_Info
  LOCAL Command_String
  LOCAL Return_Code
  LOCAL hProcess
  

  Startup_Info = long2str(68) + REPLICATE(CHR(0), 64)
  Process_Info = REPLICATE(CHR(0), 16)
  Command_String = ALLTRIM(Distiller_EXE_Spec) + ' ' + ALLTRIM(PS_PDF_Combiner_File_Spec) + CHR(0)
  Return_Code = CreateProcess(0 , Command_String , 0 , 0 , 1 , NORMAL_PRIORITY_CLASS, 0, 0, @Startup_Info, @Process_Info )
  IF Return_Code = 0
     =MESSAGEBOX("Error occurred. Error code: ", GetLastError())
     RETURN
  ENDIF
  hProcess = str2long(SUBSTR(Process_Info, 1, 4))
  DO WHILE ( .T. )
    IF ( WaitForSingleObject(hProcess, WAIT_INTERVAL) != WAIT_TIMEOUT )
      EXIT
    ELSE
      DOEVENTS
    ENDIF
  ENDDO
  Return_Code = CloseHandle (hProcess)
  
    
  *------------------------------------------------run adobe acrobat reader so can print / fax / email-----
  IF ( 6 = MESSAGEBOX ('Do you want to view and/or print the PDF now?' , 4 , 'CONFIRMATION') )
    DO Open_Current_PDF_File WITH Combined_PDF_File_Spec
  ENDIF
  PARAM_Current_Form.ENABLED = .T.



  Wildcard_Delete_Files ( EVAL_PDF_Dir_Spec , '*.PS' )
  Wildcard_Delete_Files ( EVAL_PDF_Dir_Spec , '*.LOG' )

ENDPROC







*----------------------------------------------------------------------------------
* FUNCTION Long2str
*----------------------------------------------------------------------------------
FUNCTION long2str
  ********************
  * Passed : 32-bit non-negative numeric value (m.longval)
  * Returns : ASCII character representation of passed
  *           value in low-high format (m.retstr)
  * Example :
  *    m.long = 999999
  *    m.longstr = long2str(m.long)

  PARAMETERS m.longval

  PRIVATE i, m.retstr

  m.retstr = ""
  FOR i = 24 TO 0 STEP -8
    m.retstr = CHR(INT(m.longval/(2^i))) + m.retstr
    m.longval = MOD(m.longval, (2^i))
  NEXT
 
  RETURN m.retstr
ENDFUNC







*-------------------------------------------------------------------
* PROCEDURE Open_Current_PDF_File
*-------------------------------------------------------------------
PROCEDURE Open_Current_PDF_File
  PARAMETER PARAM_Combined_PDF_File_Spec

    #INCLUDE Define_API_Constants.h


    LOCAL Combined_PDF_File_Spec
    
    Combined_PDF_File_Spec = PARAM_Combined_PDF_File_Spec

    Startup_Info = long2str(68) + REPLICATE(CHR(0), 64)
    Process_Info = REPLICATE(CHR(0), 16)
    Command_String = ALLTRIM(Adobe_Acrobat_EXE_Spec) + ' ' + ALLTRIM(Combined_PDF_File_Spec) + CHR(0)
    Return_Code = CreateProcess(0 , Command_String , 0 , 0 , 1 , NORMAL_PRIORITY_CLASS, 0, 0, @Startup_Info, @Process_Info )
    IF Return_Code = 0
      =MESSAGEBOX("Error occurred. Error code: ", GetLastError())
      RETURN
    ENDIF
    hProcess = str2long(SUBSTR(Process_Info, 1, 4))
    DO WHILE ( .T. )
      IF ( WaitForSingleObject(hProcess, WAIT_INTERVAL) != WAIT_TIMEOUT )
        EXIT
      ELSE
        DOEVENTS
      ENDIF
    ENDDO
    Return_Code = CloseHandle (hProcess)

ENDPROC
hope that is of some use to you.
patrick
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform