1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| Public Function CallGS(ByRef astrGSArgs() As String) As Boolean
Dim intReturn As Long
Dim intGSInstanceHandle As Long
Dim aAnsiArgs() As String
Dim aPtrArgs() As Long
Dim intCounter As Long
Dim intElementCount As Long
Dim iTemp As Long
Dim callerHandle As Long
Dim ptrArgs As Long
' Print out the revision details.
' If we want to insist on a particular version of Ghostscript
' we should check the return value of CheckRevision().
CheckRevision (704)
' Load Ghostscript and get the instance handle
intReturn = gsapi_new_instance(intGSInstanceHandle, callerHandle)
If (intReturn < 0) Then
CallGS = False
Return
End If
' Capture stdio
intReturn = gsapi_set_stdio(intGSInstanceHandle, AddressOf gsdll_stdin, AddressOf gsdll_stdout, AddressOf gsdll_stderr)
If (intReturn >= 0) Then
' Convert the Unicode strings to null terminated ANSI byte arrays
' then get pointers to the byte arrays.
intElementCount = UBound(astrGSArgs)
ReDim aAnsiArgs(intElementCount)
ReDim aPtrArgs(intElementCount)
For intCounter = 0 To intElementCount
aAnsiArgs(intCounter) = StrConv(astrGSArgs(intCounter), vbFromUnicode)
aPtrArgs(intCounter) = StrPtr(aAnsiArgs(intCounter))
Next
ptrArgs = VarPtr(aPtrArgs(0))
intReturn = gsapi_init_with_args(intGSInstanceHandle, intElementCount + 1, ptrArgs)
' Stop the Ghostscript interpreter
gsapi_exit (intGSInstanceHandle)
End If
' release the Ghostscript instance handle
gsapi_delete_instance (intGSInstanceHandle)
If (intReturn >= 0) Then
CallGS = True
Else
CallGS = False
End If
End Function
Private Function ConvertFile(Ps_file As Variant, Pdf_file As Variant) As Boolean
Dim astrArgs(10) As String
astrArgs(0) = "ps2pdf" 'The First Parameter is Ignored
astrArgs(1) = "-dNOPAUSE"
astrArgs(2) = "-dBATCH"
astrArgs(3) = "-dSAFER"
astrArgs(4) = "-r300"
astrArgs(5) = "-sDEVICE=pdfwrite"
astrArgs(6) = "-sOutputFile=" & Trim(Pdf_file)
astrArgs(7) = "-c"
astrArgs(8) = ".setpdfwrite"
astrArgs(9) = "-f"
astrArgs(10) = Trim(Ps_file)
ConvertFile = CallGS(astrArgs)
End Function |