Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Amyuni PDF Converter Problems
Message
From
01/06/2001 11:25:14
Patrick O'Neil
American Specialty Information Services
Roanoke, Indiana, United States
 
 
To
01/06/2001 04:49:26
General information
Forum:
Visual FoxPro
Category:
Third party products
Miscellaneous
Thread ID:
00513025
Message ID:
00513831
Views:
15
>Do you know if the API in the new version 5.0 allows you to specify a file
>name and append multiple jobs into it.
>
>The problem was I need to put many prints in one PDF file and Adobe forces
>you to type a file name each time. There was a work around but it does not work under windows nt, or 95, or 2000 I can't remember which one..



here's a flexible way to deal with that ...


1) specify output to go to Generic PostScript Printer and arrange for unique file names to be generated programatically. (here, PostScript_File_Name_Sequence_Number is a global variable used in my procedure Get_Next_PostScript_File_Spec, which combines fixed path info with the sequence number to create a file spec such as H:\PROJECT\REPORTS\TEMP_PS_DIR\RPT_01.PS (the sequence number gets incremented with each call to Get_Next_PostScript_File_Spec() )
--------------------------------------------------
PostScript_File_Name_Sequence_Number = 0
Report_Destination = 'NOCONSOLE TO FILE Get_Next_PostScript_File_Spec()'
Selected_Printer_Name = 'Generic PostScript Printer'
SET PRINTER TO NAME (Selected_Printer_Name)
-------------------------------------------------


2) produce PostScript files by the report like this:
------------------------------------------
...
REPORT FORM My_Report_A &Report_Destination
...
REPORT FORM My_Report_B &Report_Destination
...
---------------------------------------------
this creates a set of postscript files that not only have unique
names, but allows you to order them, based on the order in which
they were created. for example.
H:\PROJECT\REPORTS\TEMP_PS_DIR\RPT_01.PS
H:\PROJECT\REPORTS\TEMP_PS_DIR\RPT_02.PS
H:\PROJECT\REPORTS\TEMP_PS_DIR\RPT_03.PS (etc.)



3) since you know where you put those postscript files, use ADIR() to get a list of the postscript file names and build a postscript 'script' file, which when distilled, will combine all those postscript files into a single PDF file. there are options here that i have not exercised (even some that i need to use, but have not yet researched).
the name you give this script file determines the name of the resulting pdf file. here is a listing of my procedure, which of course has references to things unique to my app and i have not bothered to change.

--------------------------------------------------------------
PROCEDURE Combine_PostScript_Files_Into_PDF

PARAMETER PARAM_Current_Form


PARAM_Current_Form.ENABLED = .F. (i don't want them to do anything
else until distiller window is closed)

#INCLUDE Define_API_Constants.h (see below)

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


&& this stuff comes from adobe documentation ******

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.
ENDPROC



==========================================================
---the contents of the "script" file look like this-------
==========================================================
/prun { /mysave save def dup = flush RunFile clear cleardictstack mysave restore } def
(o:/images/new_lossctl/inspect/pdf_output/rpt_001.ps) prun
(o:/images/new_lossctl/inspect/pdf_output/rpt_002.ps) prun
(o:/images/new_lossctl/inspect/pdf_output/rpt_003.ps) prun
(o:/images/new_lossctl/inspect/pdf_output/rpt_004.ps) prun
(o:/images/new_lossctl/inspect/pdf_output/rpt_005.ps) prun
(o:/images/new_lossctl/inspect/pdf_output/rpt_006.ps) prun
(o:/images/new_lossctl/inspect/pdf_output/rpt_007.ps) prun
(o:/images/new_lossctl/inspect/pdf_output/rpt_008.ps) prun
(o:/images/new_lossctl/inspect/pdf_output/rpt_009.ps) prun
(o:/images/new_lossctl/inspect/pdf_output/rpt_010.ps) prun
(o:/images/new_lossctl/inspect/pdf_output/rpt_011.ps) prun










4) if the user desires, run acrobat (wouldn't have to be writer at this point
... could just as well use reader).
------------------------------------------------------
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
------------------------------------------------------





----------------------------------------------
PROCEDURE Declare_API_Functions

#INCLUDE Define_API_Constants.h

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

ENDPROC
---------------------------------------


-----------------------------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
----------------------------------------------------
patrick
Previous
Reply
Map
View

Click here to load this message in the networking platform