Well i am working on a QTP project
and had this task of automating PDF using QTP.
I have had no experiences in
automating pdfs before but after some survey i find that there are so many ways
in which we can do so.I found some guidelines here and there but most of them
were misguides and asking me to purchase software/licences.
In this blog post i am sharing some
insight on the different techniques.
For basic QTP users i must first
explain what is an object creation.This would enable to understand the below
with ease.
When you want to add objects in the
object repository you just open the repository and click on the + sign.But now
you can improvise by creating objects.For that you must know the name of the
appropriate application.
Lets explain with an example of
opening internet explorer.
SystemUtil.Run ( FileName, Parameters,
Path, Operation ) OR InvokeApplication "C:\Program
Files\Internet Explorer\IEXPLORE.EXE http://www.google.com"
Now if you can create an object of
internet explorer then we can view a lot of options as dropdown.Here is the
syntax: createobject(Servername.typename) where Servername would be the
application providing the object and typename would be the type or the class to
create object for.
Set NewOBj =
createobject("InternetExplorer.Application")
NewOBj .visible=true
NewOBj .navigate"http:\\www.google.com"
NewOBj .navigate"http:\\www.google.com"
When you type .(dot) after
NewOBj you will find a lot of options to choose from.
When you have created an object of
an application you can get a lot of options to choose from.
Coming back to our case with PDF
automation,we can automate PDF in the below mentioned ways based on our
requirement.
---------------------------------------ADOBE READER-------------------------------
1.If Adobe Reader is installed in
the machine
Then we can use Set NewOBj =
createobject("AcroPDF.PDF").
Example: To Print a pdf file
Set objAcroPDF =
CreateObject("AcroPDF.PDF")
objAcroPDF.LoadFile("C:\D2\Scanner\test.pdf")
objAcroPDF.PrintAll
objAcroPDF.LoadFile("C:\D2\Scanner\test.pdf")
objAcroPDF.PrintAll
Set objAcroPDF = Nothing
This technique is limited and
contains only a very few options and can be used for purposes like printing the
pdf file.Haven't noticed anything significant about this.
----------------------------------------ADOBE ACROBAT------------------------------
2 .If Adobe Acrobat is installed in
the machine
Then we can use
a) Set oPDFDoc = CreateObject( "AcroExch.PDDoc"
)
Example To get the number
of pages of a pdf file
Set oPDFDoc = CreateObject( "AcroExch.PDDoc"
)
If oPDFDoc.Open( FileName ) Then
GetNumPagesInPDF = oPDFDoc.GetNumPages()
Set oPDFDoc = Nothing
Else
GetNumPagesInPDF = -1
End If
If oPDFDoc.Open( FileName ) Then
GetNumPagesInPDF = oPDFDoc.GetNumPages()
Set oPDFDoc = Nothing
Else
GetNumPagesInPDF = -1
End If
b) Set PdfForm =
CreateObject("AFormAut.App")--to manipulate from pdf forms
c) Set objAcrApp
= CreateObject("AcroExch.App")--creating acrobat application object
d) Set objAVDoc =
CreateObject("AcroExch.AVDoc")--we have to create one avdoc object
per displayed document.
Example:
To open a pdf file display it for sometime and then close it.
Set objAcrApp =
CreateObject("AcroExch.App")
objAcrApp.Show()
Set objAVDoc =
CreateObject("AcroExch.AVDoc")
objAVDoc.open "PATH of
PDF","Title"
wait(200)
objAVDoc.CloseAllDocs
objAVDoc.exit
Set objAVDoc=nothing
Set objAVDoc=nothing
We can use
objAVDoc.FindText("text") before closing,if we want to find if a text
is present or not.
--------------------------- LEARNQUICKTEST.MANIPULATEPDF.DLL-----------
3. If you have do not have Adobe
Acrobat but only have the Adobe Reader,then you can download a copy of an
API from this link http://www.learnqtp.com/learnquicktestpdf-api-manipulating-pdfs-in-qtp/
The instruction for the download and
usage is given
Once it is installed on the system
then you can create an object of the DLL file LearnQuickTest.ManipulatePDF.dll
Note:This Dll file can also be
installed alternatively by registering it in the RegAsm.exe.
Search for the RegAsm.exe file in
your system.Once found goto Run and type cmd.Once the command screen opens type
"PATH of RegAsm.exe\RegAsm.exe" "PATH of Dll File\LearnQuickTest.ManipulatePDF.dll"
Set oPDF=createobject("LearnQuickTest.ManipulatePDF")
You will get a dropdown option after
you type oPDF.
----------------------------------- PLUG-IN ADOBE APTT----------------------------------
4. If you want QTP to read PDF files and add objects directly then
all you need is to download ADOBE APTT plugin.If you install ADOBE APTT plugin,
QTP starts identifying the objects in PDF.This can be downloaded from
the link http://labs.adobe.com/technologies/aptt/
--------------------------------------------------------N.B---------------------------------------------------------------------
The following will be needed to grasp a better understanding
1)How to install/uninstall DLL files(explained above in case #3)
2) If qtp is not installed but you want to test codes
Ans) write the codes in text file.save the file in .vbs fromat.Then double click this file for autorun without QTP
3)How to know the names of applications of which we can create an object of.
Ans)Goto Run.Type regedit.Registry editor will open and you can view all the registry files.Typical names like AcroExch.PDDoc can be found under adobe or you can manually search for all applications under adobe acrobat.
Hope this benefits those involved in PDF QTP projects.Thanks ....
nice job. Really impressive.
ReplyDeleteWell done, and very helpful as we prepare test scripts for PDFs that result from data entered into a GUI regarding financial products that could be available.
ReplyDeleteHi , i have to read a PDF File and get the data from it . i have QTP 12 and reader11 . please help
DeleteRespect and I have a tremendous give: Whole House Renovation Cost Calculator home reno costs
ReplyDelete