QTP doesn’t provide a native support for Adobe pdf. So when comparing two pdf files, I would prefer other tools than can do a much better job. But if you are very sure to use QTP only for this effort, here are some of the broad guidelines to follow:

This sequence is for Adobe Reader 7.0. The steps may vary with other versions.

1) Open the pdf file in selection mode

Compare two PDF files in QTP

 

2) The opening of pdf file in selection mode can be automated by the following combination of key strokes. Alt+t+s+Down Arrow Key +Enter. Automation equivalent:

Window("regexpwndtitle:=Adobe Reader","regexpwndclass:=AdobeAcrobat").Type micAltDwn + "t" + micAltUp
Window("regexpwndtitle:=Adobe Reader","regexpwndclass:=AdobeAcrobat").Type "s"
Window("regexpwndtitle:=Adobe Reader","regexpwndclass:=AdobeAcrobat").Type micDwn
Window("regexpwndtitle:=Adobe Reader","regexpwndclass:=AdobeAcrobat").Type "Enter"

3) Select the whole text using “Select All”. Automation equivalent:

Window("regexpwndtitle:=Adobe Reader","regexpwndclass:=AdobeAcrobat").Type micCtrlDwn + “a” + micCtrlUp

4) Copy the whole selection to the clipboard. Automation equivalent:

Window("regexpwndtitle:=Adobe Reader","regexpwndclass:=AdobeAcrobat").Type micCtrlDwn + "c" + micCtrlUp

5) Using FSO with QTP write content to a text file, name it as text “File-1”

6) Repeat the above steps with second file also. name it as text “File-2”

7) Now, using File System Object with QTP –yet again-compare two files line by line. Go through the How to read content from a file? section on the given link.

You might need to create some functions above to save yourself from repeated tasks. If you have any other idea (or a better idea) to compare two pdf files, do let me know through the comments below.

Welcome new readers: Download the Free eBook!

I am Ankur Jain, the owner of LearnQTP and founder of a software organization. This site is run, maintained and updated by me and my team. Feel free to take a look around, you may want to start with What is QTP? 

You can connect with me on twitter @ajonit. 

Please enter your first name and email address below to instantly download the eBook on Optimizing QTP Scripts. In future, we will make sure you get new tips & tricks on QTP delivered direct to your email box.

You have Successfully Subscribed!

Share This