Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I need to generate a PostScript file from Visual Basic automatically. I would like to automate this so that I can specify the filename/path in code such that the dialog box that prompts for the filename is bypassed. i.e. I can select the printer automatically and assign the port FILE: but I can't stop the enter filename prompt.
Platform: VB6 on Windows NT4.

Whew, this is an old post, but I am working on a similar issue. If you found a good solution, please email me.
Try using REDMON (http://www.ghostgum.com.au)
REDMON has some cool utilities for redirecting print functions to a postscript driver and then to a file.if you need more customization, try using it to launch the following VB code
:Option Explicit
Public Const STD_INPUT_HANDLE = -10&
Public Const STD_OUTPUT_HANDLE = -11&Public Const CGI_AUTH_TYPE As String = "AUTH_TYPE"
Public Const CGI_CONTENT_LENGTH As String = "CONTENT_LENGTH"
Public Const CGI_CONTENT_TYPE As String = "CONTENT_TYPE"
Public Const CGI_GATEWAY_INTERFACE As String = "GATEWAY_INTERFACE"
Public Const CGI_HTTP_ACCEPT As String = "HTTP_ACCEPT"
Public Const CGI_HTTP_REFERER As String = "HTTP_REFERER"
Public Const CGI_HTTP_USER_AGENT As String = "HTTP_USER_AGENT"
Public Const CGI_PATH_INFO As String = "PATH_INFO"
Public Const CGI_PATH_TRANSLATED As String = "PATH_TRANSLATED"
Public Const CGI_QUERY_STRING As String = "QUERY_STRING"
Public Const CGI_REMOTE_ADDR As String = "REMOTE_ADDR"
Public Const CGI_REMOTE_HOST As String = "REMOTE_HOST"
Public Const CGI_REMOTE_USER As String = "REMOTE_USER"
Public Const CGI_REQUEST_METHOD As String = "REQUEST_METHOD"
Public Const CGI_SCRIPT_NAME As String = "SCRIPT_NAME"
Public Const CGI_SERVER_NAME As String = "SERVER_NAME"
Public Const CGI_SERVER_PORT As String = "SERVER_PORT"
Public Const CGI_SERVER_PROTOCOL As String = "SERVER_PROTOCOL"
Public Const CGI_SERVER_SOFTWARE As String = "SERVER_SOFTWARE"Public Declare Function Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long) As LongPublic Declare Function stdin Lib "kernel32" Alias "GetStdHandle" _
(Optional ByVal Handletype As Long = STD_INPUT_HANDLE) As LongPublic Declare Function stdout Lib "kernel32" Alias "GetStdHandle" _
(Optional ByVal Handletype As Long = STD_OUTPUT_HANDLE) As LongPublic Declare Function ReadFile Lib "kernel32" _
(ByVal hFile As Long, ByVal lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, _
lpNumberOfBytesRead As Long, Optional ByVal lpOverlapped As Long = 0&) As LongPublic Declare Function WriteFile Lib "kernel32" _
(ByVal hFile As Long, ByVal lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, _
lpNumberOfBytesWritten As Long, Optional ByVal lpOverlapped As Long = 0&) As LongSub Main()
Dim sReadBuffer As String
'Dim sWriteBuffer As String
Dim lBytesRead As Long
'Dim lBytesWritten As Long
Dim hStdIn As Long
'Dim hStdOut As Long
Dim fso As FileSystemObject
Dim ts As TextStream
Dim i As Long
Dim strWriteBuf As String
Dim bstrWriteBuf() As Byte
Dim strTerm As String
lBytesRead = 0
sReadBuffer = "4096"
i = 1
strWriteBuf = ""
Do
' Get STDIN handle
hStdIn = stdin()
' Read client's input
ReadFile hStdIn, sReadBuffer, Len(sReadBuffer), lBytesRead
strWriteBuf = strWriteBuf & sReadBuffer
i = i + 1
Loop Until lBytesRead = 0
'The terminating character are typically "EOF" & Chr(4) / 45 4F 46 04
ReDim bstrWriteBuf(LenB(strWriteBuf))
bstrWriteBuf = strWriteBuf
For i = (UBound(bstrWriteBuf)) To (UBound(bstrWriteBuf) - 200) Step -1
If bstrWriteBuf(i) = 4 Then
ReDim Preserve bstrWriteBuf(i)
End If
Next i
i = FreeFile(1)
Open "c:\\temp\\" & Environ("REDMON_DOCNAME") & ".PS" For Binary As #i
Put #i, , CStr(bstrWriteBuf)
Close #i
'Set fso = New FileSystemObject
'Set ts = fso.CreateTextFile("c:\temp\" & Environ("REDMON_DOCNAME") & ".PS", True)
'ts.Write (bstrWriteBuf)
'ts.Close
'Set fso = Nothing
End Sub

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |