Results 1 to 5 of 5

Thread: Printing Problem - Please Help!!

  1. #1

    Thread Starter
    Registered User
    Join Date
    Mar 2002
    Location
    Nashville, TN
    Posts
    103

    Exclamation Printing Problem - Please Help!!

    I have been all over the internet trying to find a way to send a file to the printer and I cannot find an answer anywhere! I know how to display the printer dialog boxes to set the printer the user wishes to use, but I cannot figure out how to physically send a file (in this case a .pdf file) to the printer the user has selected. This is a HUGE piece of my application. I have even looked for third party components and I cannot find one that will print files (lots of controls to MAKE pdf documents but not print them). Does anyone have ANY idea on how to simply send a file to a printer? Please help.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    VB Code:
    1. Dim intFN As Integer
    2. Dim strLine As String
    3.  
    4. intFN = FreeFile
    5.  
    6. Open "C:\temp\test.txt" For Input As #intFN
    7. Do While Not EOF(intFN)
    8.     Line Input #intFN, strLine
    9.     Printer.Print strLine
    10. Loop
    11.  
    12. Printer.EndDoc
    13. Close #intFN

  3. #3

    Thread Starter
    Registered User
    Join Date
    Mar 2002
    Location
    Nashville, TN
    Posts
    103

    Exclamation

    I know that works with text documents but these are .pdf files (Adobe Acrobat). Does this code work with that? I didn't think you could use freefile to import anything except text files.

  4. #4

  5. #5
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    Let me cut & paste some code I have:
    First, lets say you have a printer who's IP address is {string}:
    "192.168.33.99"

    And then, lets say you have a Queue on your printer, like:

    "XRX_Swop"

    Then this is the code I would use:

    VB Code:
    1. 'In a sub somewhere:
    2.  
    3. MyLPStr = "lpr -S " & "192.168.33.99" & " -P " & "XRX_Swop" & " "
    4. SyncShellCmd MyLPStr & "-J" & Chr$(34) & "p003456-save" & Chr$(34) & " " & Chr$(34) & "C:\p003456-duplex-save.pdf" & Chr$(34), 0
    5.  
    6.  
    7. 'Then, you have the function SyncShellCmd somewhere in your
    8. 'forms code:
    9.  
    10. Public Function SyncShellCmd(CmdStr As String, ByVal ApplicationFocus As Long) As Boolean
    11. 'Run the application by the CmdStr, and exit when the program terminated, Application focus specific
    12. 'the focus of the application. e.g vbNormalFocus
    13. Dim lPid As Long 'The task ID of the started program
    14. Dim lHnd As Long ' handle to object to wait for
    15. Dim lRet As Long 'Return value of WaitForSingleObject()
    16.  
    17. SyncShellCmd = False
    18. If CmdStr = "" Then Exit Function
    19. lPid = Shell(CmdStr, ApplicationFocus)
    20.     If lPid <> 0 Then
    21.     'Get a handle to the shelled process.
    22.     lHnd = OpenProcess(&H100000, 0, lPid)
    23.     'If successful, wait for the application to end and close the handle.
    24.         If lHnd <> 0 Then
    25.             lRet = WaitForSingleObject(lHnd, &HFFFF) 'no time out
    26.             CloseHandle (lHnd)
    27.             SyncShellCmd = True
    28.         End If
    29.        
    30.     End If
    31.  
    32. End Function
    33. 'Either put these three in a Bas, declared as public,
    34. 'or at the top of your forms code module:
    35.  
    36. Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
    37. Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    38. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

    -Hope this helps
    -Lou

    BTW, the point of all this is you are essentially shelling to the LPR.exe, if you happen to have it on your system.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width