Results 1 to 12 of 12
  1. #1
    Join Date
    May 2005
    Posts
    150

    Unanswered: print external file to printer

    any ideas on how i can print an external file to a printer?

    please let me know

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    no idea if it still works but you used to be able to send a file to the printer using the pipe redirect in MS-DOS (god that ages me)

    copy myfile.ext > lpt1
    or type myfile > ltp1
    or it coulf be copy myfile | lpt1

  3. #3
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    A windows based solution (not that there is anything wrong with using DOS - DOS has a much MUCH better track record for reliability over the years) could be:

    Using "Automation", open the document in the appropiate program (hidden) and send to the printer using that program.

    For example, if it it RTF, DOC or TXT, create a WORD object, and then use that object to open Word (hidden), open the file, print it, then close everything and release the object.

    A simplier (but sometimes less reliable) method is to use the "Send Keys" command.

    Somewhere in this forum is instructions on how to use a Windows API to control the printer. Also, one for using the Shell command to open a file directly in it's parent application based on it's extension (similar to double clicking a document on the desktop).

    Come to think of it, if it's a text file, use DOS. Quick and easy.

    tc

  4. #4
    Join Date
    May 2005
    Posts
    150
    I guess to make the process one more in depth.. it is a pdf file that is being printed


    I have been Referencing different Acrobat plugins but haven't been able to find the one to print the pdf

    --- edit
    and the filename changes depending on the Reference#

  5. #5
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    I believe Acrobat has it's objects hidden. And, with Adobe version 6 and newer, the programming objects are hidden there as well (they want you to buy their *special* (translation: "expensive") software development tools.

    Couple of options:

    1. PDF has been cracked (I'm sorry, "DECODED") so there are numerous low to no cost programs on the web that read, write, create etc. PDF files. Search and use at your own risk, however.

    2. Use the API that allows you to Shell a file directly so that Windows will open the appropiate parent application (in this case, Acrobat). Then use the "SendKeys" command to send the Ctrl-P to print it. Then, Send Alt-F4 to close it.

    Good luck

  6. #6
    Join Date
    May 2005
    Posts
    150
    could you point me in the right direction to use that Shell Api and possibly a Send Keys Tutorial.. this will be my first time working with that

  7. #7
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    Oh yeah, I forgot - instead of the API call, use the shell command to open Acrobat itself with the filename in quotes as a command line option.

    For example:
    Code:
    Private Sub Command0_Click()
    
        Dim ReturnValue As Variant
        Dim Time As Single
        
        ReturnValue = Shell("C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe C:\Test.pdf")
        
        Time = Timer + 2 ' Give several seconds for Acrobat to open
        Do
        Loop Until Timer > Time
        
        AppActivate ReturnValue
        SendKeys "%FP", True
    End Sub
    have fun!

    Todd S.
    click to email


    Independent Development Consultant
    Biz db & reports - SQL, Access, Crystal, Seradex and more
    Small, custom, unique programs - Office, VBA, .NET


    _________________________________________________
    Favorite message from Windows:
    There was an error displaying the previous error message

    Sadly, there was no error number to look up ...

  8. #8
    Join Date
    May 2005
    Posts
    150
    Quote Originally Posted by tcace
    Oh yeah, I forgot - instead of the API call, use the shell command to open Acrobat itself with the filename in quotes as a command line option.

    For example:
    Code:
    Private Sub Command0_Click()
    
        Dim ReturnValue As Variant
        Dim Time As Single
        
        ReturnValue = Shell("C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe C:\Test.pdf")
        
        Time = Timer + 2 ' Give several seconds for Acrobat to open
        Do
        Loop Until Timer > Time
        
        AppActivate ReturnValue
        SendKeys "%FP", True
    End Sub
    This all worked well... except for the dialog box opening up

    the only reason i have a problem with this is because during batch invoicing it is going to print the PDF along with the invoice

    any ideas on how to A) Not have the dialog box open
    B) Close Acrobat after it chooses to print

    ----Forgot to say thank you.... it is really appreciated

  9. #9
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    The trick with "SendKeys" is that you are literally sending keystrokes to the active application. So, figure out how do do exactly what you want using the keyboard only (no mouse) and that defines what you send using the "SendKeys" command.

    For example, Alt-F opens the file menu and C is for Close, so the SendKeys string to close Acrobat is "%FC". For printing without the dialog, try "^P" (which is Ctrl-P.

    Look up in the help file of Access for tip/tricks on sending key combinations, such as Ctrl-P.

    Good luck
    have fun!

    Todd S.
    click to email


    Independent Development Consultant
    Biz db & reports - SQL, Access, Crystal, Seradex and more
    Small, custom, unique programs - Office, VBA, .NET


    _________________________________________________
    Favorite message from Windows:
    There was an error displaying the previous error message

    Sadly, there was no error number to look up ...

  10. #10
    Join Date
    May 2005
    Posts
    150
    tcace - Thank you for bringing me to the next level

    you the man!!!

  11. #11
    Join Date
    May 2005
    Posts
    150
    does SendKeys work with the Enter button?

  12. #12
    Join Date
    May 2005
    Posts
    150
    nevermind.. found the answer on msdn

    test code came out looking like this.. but will better format tomorrow to fit my needs

    thanks to all with the help

    Code:
    Public Sub modPrintPOD(ByVal poRef As String)
    
        Dim ReturnValue As Variant
        Dim Time As Single
        
        ReturnValue = Shell("C:\Program Files\Adobe\Acrobat 7.0\Acrobat\Acrobat.exe X:\Reference\" & poRef & "\" & poRef & "-POD.pdf")
        
        Time = Timer + 2 ' Give several seconds for Acrobat to open
        Do
        Loop Until Timer > Time
        
        AppActivate ReturnValue
        SendKeys "%FP", True
        SendKeys "~", True
        SendKeys "%{F4}", True
    End Sub

Posting Permissions

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