Forum Discussion

nimishbhuta's avatar
nimishbhuta
Frequent Contributor
6 years ago

How to Save PDF file to text format

Hi All, 

 

I need to use TestComplete to save the PDF file into text format. The scenario is as follow :

 

Scenario 

1) It is a web based application. In the application there is button,when I click on the button it will show dialog box below.

 

 

2) I am able to open the PDF file by clicking on the PDF button. 

3) PDF file open in Adobe Reader, now I need to Save the PDF as text format by going to File - SaveAsOther and select the Text option 

4) I tried the recording this part, but it is not working as well not reliable. Also tried using shell script with the send keys but it is not Saving it. 

I am not sure what is the issue.For the sendkeys my assumption is that it is not able to work on the PDF file,but then I tried activating and also maximizing it but it does not work. Please let me know if you have better or reliable solution 

 

Below is my code :-

 

Function func_SavePDFToText(arg_FolderPath)

'Aliases.browser.BrowserWindow.FrameNotificationBar.Wa
'Click on the open button to open the PDF File
If Aliases.browser.BrowserWindow.FrameNotificationBar.Exists Then
Call Aliases.browser.BrowserWindow.FrameNotificationBar.Click 'this statment to have the focus on the notificaton bar
Call Aliases.browser.BrowserWindow.FrameNotificationBar.Item.buttonOpen.ClickButton
End If 

If Sys.WaitProcess("AcroRd32 *32",1000).Exists Then 

Call Aliases.AcroRd323.wndAcrobatSDIWindow.Activate
Call Aliases.AcroRd323.wndAcrobatSDIWindow.Maximize
'Save the PDF file to Text
Set oShell = CreateObject("WScript.Shell")
oShell.SendKeys("%Fhx")
Delay(500)
strFileName=Aliases.browser.dlgSaveAs.DUIViewWndClassName.Explorer_Pane.FloatNotifySink.ComboBox.Edit.wText
oShell.SendKeys(arg_FolderPath&"\"&strFileName&func_CreateDateTimeStamp()&".txt")
Delay(500)
oShell.SendKeys"{ENTER}"
oShell.SendKeys("^%Fx")
func_SavePDFToText=strFileName
End If

 

  • Hi nimishbhuta 

     


    nimishbhuta wrote:

    Also tried using shell script with the send keys but it is not Saving it. 


     

    Try simply clicking somewhere inside a pdf file to activate the window and call the SendKeys method.

     

    If this doesn't work, could you please explain what you mean by "Also tried using shell script with the send keys but it is not Saving it. "? if you get errors, give us their text.

     

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi nimishbhuta 

     


    nimishbhuta wrote:

    Also tried using shell script with the send keys but it is not Saving it. 


     

    Try simply clicking somewhere inside a pdf file to activate the window and call the SendKeys method.

     

    If this doesn't work, could you please explain what you mean by "Also tried using shell script with the send keys but it is not Saving it. "? if you get errors, give us their text.

     

    • nimishbhuta's avatar
      nimishbhuta
      Frequent Contributor

      Hi Tanya, 

       

      1st Approach: I recorded the saving of the PDF file using Keyword Test but when I ran the test again it was failing the reason been that the Acorbat Reader object was changing the index no. I tried using regular expression but somehow it was not working. 

       

      2nd Approach :- I used the shell script and it is now able to save the file but the thing is if the PDF file open slightly late then the shell command are run on the browser. Most of the time it works when the PDF open in a timely manner. I have a put the delay of 1 second and it works but it is not good approach as the PDF may take more time that I expected. We require some dynamic wait option but somehow the PDF window is change dynamically changing it's index and it is not working for me. If you have better solution then let me know to have consistent results. 

       

      Regards,

       

      Nimish