Solved

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

Posted on 2009-06-29
7
465 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
  • 3
  • 3
7 Comments
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 200 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 300 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 39

Assisted Solution

by:thenelson
thenelson earned 300 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 300 total points
ID: 24746044
Reader: 8
Don't use Adobe pro
I now use Foxit it as my default reader.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Update 21-May-2015: I temporarily removed the source code and the code snippets to make major changes to the program. Regards, Joe INTRODUCTION This Article is a follow-up to the Article entitled How To Rename-Move a Batch of PDF Files Based o…
PDF files have been in the limelight due to its unmatched features.  Personal documents, emails, business reports and eBooks are all converted into PDF files owing to peerless features provided by it. Adding watermark to a PDF file is a method to se…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

770 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