Solved

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

Posted on 2009-06-29
7
461 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

One of the questions I get asked again and again is how to validate a field value in an AcroForm with a custom validation script. Adobe provided a lot of infrastructure to do that with just a simple script. Let’s take a look at how to do that wit…
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…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now