.

How to compare two pdf files using QTP

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

image

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:

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

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

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

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

   1: 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.

Share and Enjoy
  • del.icio.us
  • Facebook
  • Twitter

If you want to keep track of further articles on QTP. I recommend you to subscribe via RSS feed. You can also subscribe by Email and have new QTP articles sent directly to your inbox.

2 comments ↓

#1 Ralph Longobardi on 08.13.09 at 17:34

We regularly compare over 150-175 .pdf reports daily.
The .pdf reports are converted to .txt documents using PDF Converter tool (needed to overcome .pdf reports font subsetting). The .txt files are “cleaned” removing dates, times, user information using QTP (“Search and Replace”). When QTP is used, .txt files become Unicode format. Notepad is used to convert .txt files to ANSI format. Then .txt files are compared using QTP. Differences are reported line by line.

#2 Chandrakant Dhutadmal on 11.25.09 at 15:34

How do we compare two pdf files containing Devnagari Text ? or for that matter containing Text other than English ? How will QTP recognize these characters ?

Leave a Comment