How to generate asci file to virtual pdf printer in vb.net. I tried with the virtual printer "microsoft print to pdf" it didn't work. I also found the link below but I don't understand whether it can used with the language of the vb.net program. Please the best solution.
http://www.columbia.edu/~em36/ghostpcl.html
below is a link to share the asci file so it's easy to try Here's a link! I use a dosprinter evaluation copy and it can produce the same output according to the output of the dot matrix printer so I think there must be other ways or solutions to achieve the same result. below share the pdf file Here's a link!
Public Shared Function SendFileToPrinter(ByVal szPrinterName As String, ByVal szFileName As String) As Boolean
' Open the file.
'FileStream and BinaryReader are disposable objects. Hence you need to dispose of these objects Better if you declare them with a Using statement, so there's a very good chance they're disposed even when an exception is generated in the meanwhile. -- Disposing of disposable objects is not exactly optional.
Using fs As New FileStream(szFileName, FileMode.Open)
' Create a BinaryReader on the file.
Dim br As New BinaryReader(fs)
' Dim an array of bytes big enough to hold the file's contents.
Dim bytes(fs.Length - 1) As Byte
Dim bSuccess As Boolean = False
' Your unmanaged pointer.
Dim pUnmanagedBytes As New IntPtr(0)
Dim nLength As Integer
nLength = Convert.ToInt32(fs.Length)
' Read the contents of the file into the array.
bytes = br.ReadBytes(nLength)
' Allocate some unmanaged memory for those bytes.
pUnmanagedBytes = Marshal.AllocCoTaskMem(nLength)
' Copy the managed byte array into the unmanaged array.
Marshal.Copy(bytes, 0, pUnmanagedBytes, nLength)
' Send the unmanaged bytes to the printer.
bSuccess = SendBytesToPrinter(szPrinterName, pUnmanagedBytes, nLength)
' Free the unmanaged memory that you allocated earlier.
Marshal.FreeCoTaskMem(pUnmanagedBytes)
Return bSuccess
End Using
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim printer As String = "Microsoft Print to PDF"
For i As Integer = 1 To 1
SendFileToPrinter(printer, "C:\vDos\#LPT1.asc")
Next i
Me.Close()
End Sub