Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

print pdf to a printer - (picking up on another member's post of the last week)

Posted on 2009-06-29
7
Medium Priority
?
499 Views
Last Modified: 2013-11-28
Hi EE,

Requesting help on this recent EE post, please:
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_24520474.html?cid=238#a24739541


Providentially, I am working on the same problem and discovered this dialogue:
A few years ago (a2000) I received from another forum help to print a pdf using sendkeys.

Now, i am using a2003:, and the logic is not working to print the pdf to a real printer.
i followed Cap's advice, yet:
       the system is not understanding the foreground window to be Adobe -
      if i'm in breakpoint mode, it thinks the current window is vba
      if i run not in breakpoint mode (i'm running this mdb like a quasi vbs script),  it thinks it's in
       vbs mode.

     In the code window is code per Cap's instructions.
     AFterwards, the code window shows my old logic that opened pdf for printing, sendkeys
     to print, then closed pdf

     In this environment:
          I need to print to another network printer, so added sendkeys to change printer
          all of sudden the application.hyperlink is popping up a microsoft message box
          so i see that doing a shell to adobe is equivalent.

Please advise, tx, sandra    

   i will open a new post, i just wanted to catch your attention, if you have time....
  tx, sandra
Option Compare Database
 
Option Explicit
 
Public Declare Function GetForegroundWindow Lib "user32" () As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
 
Public Const WM_CLOSE = &H10
Public lngAdobehWnd As Long
 
Public Sub TestPDF()
 
Call g005_PrintPdfByHyperLink("C:\ARG_99_Scripts\ARG_99_DailyElectives_script\AutomatedDailyElectivesListing.pdf", _
                              False, _
                              "Y")
 
 
End Sub
 
 
 
Public Sub g005_PrintPdfByHyperLink(strFilePath As String, _
                                    blnRunDuringDay As Boolean, _
                                    strBackPrintTestPage As String)
 
Shell "C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe" & " " & strFilePath
 
 
SendKeys "%FP", True
SendKeys "Student Affairs", True
 
If strBackPrintTestPage = "Y" Then
   SendKeys "{TAB}", True
   SendKeys "{TAB}", True
   SendKeys "{TAB}", True
   SendKeys "{TAB}", True
   SendKeys "1", True    'for testing
End If
 
 
SendKeys "{enter}", True
 
DoEvents
lngAdobehWnd = GetForegroundWindow
 
'close adobe
Call SendMessage(lngAdobehWnd, WM_CLOSE, 0, 0)
 
End Sub
 
Public Sub old_g005_PrintPdfByHyperLink(ByVal strFilePath As String, _
                                          blnRunDuringDay As Boolean, _
                                          strBackPrintTestPage As String)
                                                                
' opening pdf via adobe
 
' FilePath is full path of .pdf file to be printed
 
   ' http://support.microsoft.com/default.aspx/kb/829072
   ' Application.FollowHyperlink strFilePath
   
   ' SendKeys "%FP{enter}^q", True
   
   Shell "C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe" & " " & strFilePath
    
    If blnRunDuringDay = False Then
    
'       g_strScreenMsg = "* * Please wait as PDF opens and self-prints * *  "
'       DisplayScreenMsg (enTypeScreenMsg.enTypeScreenInfoMsg)
 
    
      ' Allow time for opening of associated
      ' application and stabilization of display
      g010_p_wait 500
      ' Invoke print dialog box (Alt + f + p)
      SendKeys "%fp", True
      ' SendKeys "Diane's printer", True
       SendKeys "Student Affairs", True
      
      ' Allow time for stabilization
      g010_p_wait 100
      ' Press Enter (This is equivalent to clicking OK
      ' in the print dialog box)
      
      If strBackPrintTestPage = "Y" Then
         SendKeys "{TAB}", True
         SendKeys "{TAB}", True
         SendKeys "{TAB}", True
         SendKeys "{TAB}", True
         SendKeys "1", True    'for testing
      End If
      
      SendKeys "{ENTER}", True
      ' Allow time for stabilization
      g010_p_wait 100
      ' Close & Exit pdf application (Alt + f + x)
      SendKeys "^Q", True
      
'      g_strScreenMsg = "* * Successful Print * * "
'      DisplayScreenMsg (enTypeScreenMsg.enTypeScreenInfoMsg)
      
    Else
    
'      g_strScreenMsg = "* * Successful Preview * * "
'      DisplayScreenMsg (enTypeScreenMsg.enTypeScreenInfoMsg)
 
    End If
    
End Sub
 
Public Sub g010_p_wait(ByVal Tmr As Long)
' Introduces time delay of Tmr cycles
    Dim Cnt As Long
    
    For Cnt = 1 To Tmr
        DoEvents
    Next
End Sub

Open in new window

0
Comment
Question by:mytfein
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 800 total points
ID: 24743484
I thought the resolution was to not print the PDF, but to simply print the Report.
0
 
LVL 39

Assisted Solution

by:thenelson
thenelson earned 1200 total points
ID: 24743955
Why not use Foxit instead. You can print a pdf file with one safe line (without Sendkeys).  I can't imagine why someone would go all the complicity of the code listed and risk compromising computers using send keys when such a simple solution is available.

Sample, to the default printer:
Shell Chr(34) & "C:\Program Files\Foxit Software\Foxit R
eader\Foxit Reader.exe" & Chr(34) & " /p " & Chr(34) & "C:\Documents and Settings\Administrator\My Documents" & Chr(34)
\temp\fax.pdf"

Sample, to a specific printer:
Shell Chr(34) & "C:\Program Files\Foxit Software\Foxit R
eader\Foxit Reader.exe" & Chr(34) & " /t " & Chr(34) & "C:\Documents and Settings\Administrator\My Documents" & Chr(34) & " " & Chr(34) & "Lexmark X5400 Series" & Chr(34)

It is also faster than adobe reader and it is free:
http://www.foxitsoftware.com/pdf/reader/
0
 

Author Comment

by:mytfein
ID: 24745710
Hi guys,
a) I thorougly re-read bartzinc's posts, bec. boag200/Jeff said it was resolved.
I saw that bartzinc printed directly from access and not pdf.
Great, so I modified my code this morning to print from excel and not even open pdf.

b) Before I understood (a), I found a diff. post by TheNelson where he recommends foxit.
    So I downloaded it.  On Fri, I downloaded Adobe updates. Not sure if the updates or foxit
    changed my pc settings regarding Adobe. Pdfs now require me to confirm opening them
    in IE, or when I do an Application.followhyperlink in Access.

    You see, under A2000 i had sendkeys logic for pdf that worked off a form's button.
     Now under A2003, when running as quasi VBS script, the Access mdb has control over
     pdf screen, and sendkeys not working. Before sendkeys, i did an application.followhyperling
     with pdf path to open pdf, but as i said before, now i'm getting a confirm box to open pdf where
      before foxit install, pdf opened seamlessly.

     so I uninstalled foxit...
     so I may have to call IT to reinstall Adobe....

     so am hestitant in using foxit

c) so I explored EE other ideas of doing shell to adobe with pdf path
    (to avoid confirm msg box of Application.hyperlink)
    but, could not determine handle to close pdf.

d) I would be very interested in Capricorn1's idea of determining the handle of pdf
    to issue a close. This would be useful in opening/printing a pdf file that i did not create.
    Our dept has pdfs that other depts created, so i cannot print from its orig. app (for ex: publisher).

e)    that's why although (a) meets my needs for now,
      (d) would be very useful...

f) i googled and fond this to try to make (d) work,
    i pasted the logic from this link into module but it did not work for me...

    http://support.microsoft.com/kb/242308

if you have any ideas on d,e,f that would be great, tx, sandra



     
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 39

Assisted Solution

by:thenelson
thenelson earned 1200 total points
ID: 24745799
Foxit did not effect Adobe on my computer.
0
 

Author Comment

by:mytfein
ID: 24745845
Hi TheNelson,

just wondering:
   a) do you use reader (which vers) ?
   b) do you use adobe pro (which vers)
   c) do you use foxit simply to print via batch, or is foxit your "default" reader
   d) if foxit is just for batch, is your windows explorer setup to open pdf files with Adobe reader
       and not foxit?
  tx, s
0
 

Author Comment

by:mytfein
ID: 24746017
Hi guys,
I posted yesterday on another forum:

    MS_Access_Professionals@yahoogroups.com

Got a response that recommends this approach:
    http://accessblog.net/2008/01/printing-pdf-from-code.html

I have not tried it yet... just sharing... tx, sandra
0
 
LVL 39

Assisted Solution

by:thenelson
thenelson earned 1200 total points
ID: 24746044
Reader: 8
Don't use Adobe pro
I now use Foxit it as my default reader.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question