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

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.
Have you downloaded the FREE Optimizing QTP eBook yet? Get It Now!
I'm sure you have already subscribed to our feed but just in case not. I recommend you to subscribe via RSS feed. You can also subscribe by Email and have new QTP articles sent directly to your inbox.




4 comments ↓
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.
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 ?
The best way is to use the API. The API comes free with the reader version, the only difference being that you can just perform readonly functions with this API while for editing functions you need the full version Adobe API. The declaration for this reader API is different from the one for full version API i.e “acroexch.app”. The API declaration for the reader API can be found on Adobe’s site. I am not able to recall it right now.
Hi,
I am using below code to compare Excel FIles. But when i am running, it comes yup with Error message ‘File location not found’ (even though file exists in the location). Could you please help me.
I have copied below code in QTP >> File ‘Test’ and changed the location paths and try to run.
Please help, do i need to do any thing else before?
Set objExcel = CreateObject(“Excel.Application”)
objExcel.Visible = True
Set objWorkbook1= objExcel.Workbooks.Open(“C:\result\lotexpt.xls”)
Set objWorkbook2= objExcel.Workbooks.Open(“C:\result\lotact.xls”)
set newWorkbook=objExcel.Workbooks.Add
Set objWorksheet1= objWorkbook1.Worksheets(1)
Set objWorksheet2= objWorkbook2.Worksheets(1)
Set objNewWorksheet= newWorkbook.Worksheets(1)
For Each cell In objWorksheet1.UsedRange
If cell.Value objWorksheet2.Range(cell.Address).Value Then
objNewWorksheet.Range(cell.Address).Value=cell.Value
objNewWorksheet.Range(cell.Address).Interior.ColorIndex = 3′ Highlights in red color if any changes in cells’
else
objNewWorksheet.Range(cell.Address).Interior.ColorIndex=0
End If
Next
set objExcel=nothing
Leave a Comment