How to automate Adobe Acrobat Reader Snapshot tool using vba?

Let say I have 8 pdf documents (8 pages each). Each one has the same graphs in the same places but the data in them is different. So, i want to write something on vba (it does not have to be vba), so I can automate the snapshot tool to take a snapshot (this will be just a part of the page) of the graphs on each page and paste it in a power point slide. So It will take the 4 graphs on the first 4 pages and paste them in a power point slide evenly (the graphs has to be reduced in size in order to fit 4 of them in one slide). It will do the same for each of the 8 pdf documents.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris Raisin(Retired Analyst/Programmer)Commented:
Can you post the PDF documents, or is the information confidential?
This could be quite involved, but I may have a =n answer for you.
awesomejohn19Author Commented:
Hmm, let me see about that. Can I send you via email so it wont stay on this thread forever.
Chris Raisin(Retired Analyst/Programmer)Commented:
Post it here. You cannot send via email since that ius outside the authorised actions allowed on this site.
We can then ask the moderator to remove the files.
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

awesomejohn19Author Commented:
Ok lets do that.
I am posting it now  First 4 pages are relevant. So tables and pictures on the first 4 pages.
awesomejohn19Author Commented:
any luck?
Chris Raisin(Retired Analyst/Programmer)Commented:
Today was the first time I received notification of a message for me in EE (I have been away for 5 days playing's a hard life!)
Will look into it today.
I now have the file. I have asked the moderator to remove the file so it no longer is available to others. Once we have resolved this issue I will delete my copy.
Chris Raisin(Retired Analyst/Programmer)Commented:
I have worked out a way, but it will take me a while to code it.
Basically what we will be doing, is naming the documents which contain the graphs(remembering that the graphs are on the same pages in each document)., stating the page numbers on which they occur (one per page), using the snapshot tool to copy the graphs
(one page at a time) from each the PDF over to the Powerpoint presentation, with the slides from each PDF being resized and placed on the saame slide in the Powerpoint show.
Whew,,,,tricky,   but stand by.

awesomejohn19Author Commented:
ok, thanks a lot
Chris Raisin(Retired Analyst/Programmer)Commented:
Just to let you know I have finally had some success.
First dlide produced with four graphs in place.
Do you want them to run in a 2X2 format, as follows:
                  1. First graph top left
                  2. Second graph top right
                  3. THird Graph bottom left
                  4. Fourth Graph bottom right.

It was not easy because unfortunately the clipboard does not save save in a recognised format by Powerpoint when copied from Acrobat (probably compression involved)  but after copying the image into a PictureBox and then saving to a file, I succeeded in importing into Powerpoint.
Let me know the format you desire, then stand by... :-)
awesomejohn19Author Commented:
Yes I want it in that format.

            1. First graph top left
                 2. Second graph top right
                 3. THird Graph bottom left
                 4. Fourth Graph bottom right.

this is correct.

thanks a lot
Chris Raisin(Retired Analyst/Programmer)Commented:
OK...almost there
I have had to copy the one file four times to test it (working with 4 files) and so the graphs appear the same on every slide.
I notice the moderator has not yet removed the first file yet. Is it possible to add three more PDF files so I can give it a full test?
Also, I have written the code in VB6. Do you have that compiler?
I also ran using Acrobat 9 as the reader. It is important that you have that reader otherwise the code needs to be changed to allow for different keystrokes. I have had to go the way of mimicking keystrokes with the Acrobat Reader because the Acrobat DLL object does not appear to have a "Snapshot" method inbuilt (probably an old version).
It seems to be working well at this end. After these last minor things are cleared up I should be ready to post the final answer.
awesomejohn19Author Commented:
Files are almost exactly the same. so each file will have the same exact structure. graph will be located at the same position. so , i believe testing one file should be allright. So, I guess under acrobat reader the the snapshot tool icon should be in the same place or are you using a shortcut?
also for vb6 compiler, can I use .net compiler (this might be a stupid question :))

thank you very much for your help
Chris Raisin(Retired Analyst/Programmer)Commented:
You cannot use the .Net compiler.
I have .Net compiler, but it might take me quite a while to convert to .Net (I am not used to it).
I could try if you like.
I will stay with the one file I have then.
The Acrobat 9 reader may NOT have the snapshot tool in the same spot (I don't know).
The keys to get to it are:   "Alt+T....Z....N"
Please advise how you want it delivered in due course. I can attempt conversion to .Net if you like, but my time is restricted because I am leaving for Queensland (a state in Australia) either this afternoon or tomorrow morning. It is a 23 hour drive (and I need to stop occasionally!). Going there for 3 days to visit my Mum for Easter then I have to drive back.
(2000 km trip one way).
awesomejohn19Author Commented:
oh dont worry. you dont have to convert it to .net. i ll figure it out. i ll really appreciate if you can post either the file here or put down the code for the vb.
thanks a lot
have a great easter.
Chris Raisin(Retired Analyst/Programmer)Commented:
OK, the VB6 Code follows below.
You will have to tweak it to show the correct paths for the executable and change the keystrokes if you are not using Acrobat Reader 9.
The components required are:
       Microsoft Common Dialogue Control
The References required are:
        VisualBasic for Applications
        Visual Basic Runtime Objects and Procedures
        Visual Basic Objects and Procedures
        Microsoft Powerpoint 11.0 Object Library

I hope it all works out OK....It took ages of testing but worked fine at this end.
When the program starts it asks you to pick ONE of the PDF files you want to include.
It then presents a FileListbox containing all the PDFs in the directory of the chosen file>
You can then "multi-select" all the files you want included by holding down the SHIFT key as you click on the required file names. After clicking on the "Process" button, the procedure
will continue on the chosen files. (Cancel will cause the program to stop).

Best not to have other programs running at the same time since this program uses "Sendkeys" extensively and does not like interference. I would have liked to avoid this, but as I said, the "Snapshot" functionality is not available through any of the Object libraries I have..

The attributes contained within the Selection box Form are also attached in a separate file
showing the settings of various objects in that Form
I will be back in seven days since I am leaving this afternoon. I will check back in about an hour (just before I leave) in case you have any other questions.

Happy Easter!

Option Explicit
'This following requires that you set a reference
'to Microsoft PowerPoint 11 Object Library in References
Public oPPTApp As PowerPoint.Application
Public nPic As Integer
Public sPresentationFile As String

Private Sub cmdCancel_Click()
  Unload Me
End Sub
Private Sub Form_Unload(Cancel As Integer)
End Sub

Private Sub cmdProcess_Click()
  Dim nPage As Integer
  Dim PP As Object
  Dim cFile As String
  Dim nPDF As Integer
  Dim nPause As Integer
  Dim bFirstTime As Boolean
  Dim x As Integer
  Dim nWnd As Long
  sPresentationFile = App.Path + "\Graphs.PPT"
  nPause = 0.75
  bFirstTime = True
  Form1.WindowState = vbMinimized
  For nPDF = 0 To (Form1.File1.ListCount - 1)
    If Form1.File1.Selected(nPDF) Then
      nWnd = Shell("C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe " + _
                    Me.File1.Path + "\" + File1.List(nPDF), vbMaximizedFocus)
      PauseFor 3, True
      If nWnd > 0 Then
        For nPage = 1 To 4
          SendKeys "%V", True
          PauseFor nPause, True
          SendKeys "G", True
          PauseFor nPause, True
          SendKeys "P", True
          PauseFor nPause, True
          SendKeys CStr(nPage), True
          PauseFor nPause, True
          SendKeys "{Enter}", True
          PauseFor nPause, True
          bFirstTime = False
          SendKeys "%T", True
          PauseFor nPause, True
          SendKeys "Z", True
          PauseFor nPause, True
          SendKeys "N", True
          PauseFor nPause, True
          SendKeys "%E", True
          PauseFor nPause, True
          SendKeys "L", True
          PauseFor nPause, True
          SendKeys "%E", True
          PauseFor nPause, True
          SendKeys "C", True
          PauseFor nPause, True
          Form1.PictureBox1.Picture = Clipboard.GetData
          nPic = nPic + 1
          SavePicture Form1.PictureBox1.Image, App.Path + "\AcroPic_" + CStr(nPic) + ".bmp"
          PauseFor nPause, True
        MsgBox "Cannot locate Adobe Reader program"
      End If
    End If
  Unload Me
  SendKeys "%F", True
  PauseFor nPause, True
  SendKeys "X", True
  nWnd = Shell("C:\Program Files\Microsoft Office\Office11\Powerpnt.exe " + sPresentationFile, vbMaximizedFocus)
  PauseFor 10
  For x = 1 To nPic
    Kill App.Path + "\AcroPic_" + CStr(x) + ".bmp"
  PauseFor 5
End Sub

Private Sub Form_Load()
Dim nFile As Integer
On Error GoTo finish
Me.CommonDialog1.CancelError = True
Me.CommonDialog1.FileName = "*.pdf"
Me.CommonDialog1.DefaultExt = ".pdf"
If Dir(Me.CommonDialog1.FileName) <> "" Then
  Me.CommonDialog1.InitDir = FileDirectory(Me.CommonDialog1.FileName)
  Me.File1.Path = Me.CommonDialog1.InitDir
  For nFile = 0 To File1.ListCount - 1
    If Me.File1.List(nFile) = Dir(Me.CommonDialog1.FileName) Then
      Me.File1.Selected(Me.File1.ListIndex) = True
    End If
  Unload Me
End If
End Sub

Public Function FileDirectory(cFile As String) As String
  Dim fs   As Object
  Set fs = CreateObject("Scripting.FileSystemObject")
  FileDirectory = fs.GetparentFoldername(cFile) + "\"
End Function

Private Sub PostToPowerpoint()
   Dim NewSlide As Slide
   Static bSetUp As Boolean
   Dim nPage As Integer
   Dim nSlides As Integer
   Dim nItem As Integer
   Dim x As Integer
   Const msoFalse = 0
   Const msoTrue = 1
   If Not bSetUp Then
     'Get a reference to PowerPoint app
     Set oPPTApp = New PowerPoint.Application
     'Just to make sure not presentations are open
     For x = 1 To oPPTApp.Presentations.Count
     ' MUST set it visible or you get errors
     oPPTApp.Visible = True
     ' minimize if you want to hide it:
     oPPTApp.WindowState = ppWindowMinimized
     oPPTApp.Presentations.Add WithWindow:=msoTrue
     oPPTApp.ActivePresentation.SaveAs sPresentationFile
     bSetUp = True
   End If
   nSlides = oPPTApp.ActivePresentation.Slides.Count
   Set NewSlide = oPPTApp.ActivePresentation.Slides.Add(nSlides + 1, ppLayoutTitle)    ' Add a new slide to the presentation.
   oPPTApp.ActivePresentation.Slides.Range(Array(nSlides + 1)).Select ' Select current slide
   For nPage = (nPic - 3) To nPic
     oPPTApp.ActivePresentation.Slides(nSlides + 1).Shapes.AddPicture App.Path + "\AcroPic_" + CStr(nPage) + ".bmp", 1, 1, 0, 0

   oPPTApp.ActivePresentation.Slides(nSlides + 1).Shapes.Item(3).Top = 0
   oPPTApp.ActivePresentation.Slides(nSlides + 1).Shapes.Item(3).Left = 0
   oPPTApp.ActivePresentation.Slides(nSlides + 1).Shapes.Item(4).Top = 0
   oPPTApp.ActivePresentation.Slides(nSlides + 1).Shapes.Item(4).Left = 360
   oPPTApp.ActivePresentation.Slides(nSlides + 1).Shapes.Item(5).Top = 292
   oPPTApp.ActivePresentation.Slides(nSlides + 1).Shapes.Item(5).Left = 0
   oPPTApp.ActivePresentation.Slides(nSlides + 1).Shapes.Item(6).Top = 292
   oPPTApp.ActivePresentation.Slides(nSlides + 1).Shapes.Item(6).Left = 360
   For x = 3 To 6
     oPPTApp.ActivePresentation.Slides(nSlides + 1).Shapes(x).LockAspectRatio = msoFalse
     oPPTApp.ActivePresentation.Slides(nSlides + 1).Shapes.Item(x).Height = 250
     oPPTApp.ActivePresentation.Slides(nSlides + 1).Shapes.Item(x).Width = 360
End Sub

Public Sub PauseFor(nPauseFor As Integer, Optional nYield As Long)

  'Note! This subroutine is OK for times less than One day
  'This routine will pause the computers processing in the current program
  'for a desired number of seconds (nPauseFor)
  'optionally every "nYield" loops through the "wait state"
  'yield to Windows to allow it to process other programs
  '(very advisable to do this - by default it is set at 1000...fairly fast)
  Dim nStartedAt As Long   'starting time of the pause

  Dim i          As Integer  'counter to determine if it is time to "yield" to Windows or not

  Dim nElapsed   As Long 'total number of seconds elapsed sofar

  On Error Resume Next 'ignore errors

  'set up a default value for nYield since it should never be zero!
  If nYield = 0 Then
    nYield = 1000
  End If

  'initialize "yield" counter
  i = 0
  'ascertain starting time of pause in program execution
  nStartedAt = Timer
  nElapsed = 0   'initialize number of seconds elapsed sofar to zero

  'while we are pausing program execution...
  Do While nElapsed < nPauseFor
    'ascertain how many seconds have elapsed since start of pause
    nElapsed = Timer - nStartedAt

    'if there is a negative value, then midnight must have been reached!
    If nElapsed < 0 Then
      nElapsed = nElapsed + 86400 ' add no. of seconds in a day
    End If

    i = i + 1 'increment "yield" flag counter

    If i Mod nYield = 0 Then    ' If loop has repeated "nYield" times.

      DoEvents   ' Yield to operating system.
      i = 0      ' Reinitialize "yield" flag back to 0
    End If


End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chris Raisin(Retired Analyst/Programmer)Commented:
I am back!
So how is everything going?
awesomejohn19Author Commented:
Many thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.