---
# System prepended metadata

title: UFT GUItest - Read PDF content
tags: [GUItest, UFT]

---

---
title: 'UFT GUItest - Read PDF content'
disqus: hackmd
---

## UFT GUItest - Read PDF content

* 讀取PDF中的內容
* Micro Focus UFT One 15.0
* REF：[FindTextInPDF](https://www.letscodelikeapro.com/automate-extract-contents-pdf-document/)、[Accessing PDF's](https://community.softwaregrp.com/dcvta86296/attachments/dcvta86296/sws-Fun_TEST_SF/9622/1/Acrobat%20Exchange%20COM%20API%20with%20QTP.pdf)、[Read PDF content](https://community.microfocus.com/t5/UFT-One-User-Discussions/Reading-PDF-files-using-QTP/td-p/254656)


## :rocket:參考程式(一)

* 本機要有 Adobe Acrobat Pro
* 取得 PDF 特定頁面的內容

* | Object        | 說明                  |
  | --------------| -------------------- | 
  | AcroExch.App  | The Acrobat application itself. This is a creatable interface. From the application layer, you may control the appearance of Acrobat, whether Acrobat appears, and the size of the application window. This object provides access to the menu bar and the toolbar, as well as the visual representation of a PDF file on the screen (via an AVDoc object).               |
  |AcroExch.AVDoc |A view of a PDF document in a window. This is a creatable interface. There is one AVDoc object per displayed document. Unlike a PDDoc object, an AVDoc object has a window associated with it. |
  | AcroExch.Rect |A rectangle, specified by the top left and bottom right points. |
* Code
``` vbscript=
Option Explicit
Dim acroApp, acroAVDoc, acroPDDoc, acroRect, PDTextSelect
Dim gPDFPath, nElem, pageNo
pageNo = 0
 
gPDFPath = "C:\test.pdf"

Set acroApp = CreateObject ("AcroExch.App")

Set acroAVDoc = CreateObject("AcroExch.AVDoc")

If acroAVDoc.Open( gPDFPath, "Accessing PDF's") Then
	
	If acroAVDoc.IsValid = False Then ExitTest()
	
	acroAVDoc.BringToFront()
	
	Call acroAVDoc.Maximize(True)
	Print"Current pdf title ---> "& acroAVDoc.GetTitle()
	
	Set acroPDDoc = acroAVDoc.GetPDDoc()
	Print"File Name ---> "& acroPDDoc.GetFileName()
	Print"Number of Pages ---> "& acroPDDoc.GetNumPages()
	
	Set acroRect = CreateObject("AcroExch.Rect")
	acroRect.Top = 750
	acroRect.Left = 50
	acroRect.Bottom = 50
	acroRect.Right = 500
	
	Set PDTextSelect = acroPDDoc.CreateTextSelect( pageNo, acroRect )
	
	If PDTextSelect Is Nothing Then
		Print"Unable to Create TextSelect object."
		ExitTest()
	End If
 
	Call acroAVDoc.SetTextSelection( PDTextSelect )
	Call acroAVDoc.ShowTextSelect()
	
	Print"Selection Page Number ---> " & PDTextSelect.GetPage()
	Print"Selection Text Elements ---> "& PDTextSelect.GetNumText()
	
	For nElem = 0 To PDTextSelect.GetNumText() - 1
		Print"Text # "& nElem &" ---> '"& PDTextSelect.GetText( nElem ) &"'"
	Next
	
	Call PDTextSelect.Destroy()
End If
	
AcroApp.CloseAllDocs()
AcroApp.Exit()
	
Set PDTextSelect = Nothing : Set acroRect = Nothing
Set AcroApp =  Nothing: Set AcroAVDoc =  Nothing
```

:::warning
此方法 **需要** Adobe Acrobat Pro 喔喔喔喔!!!
:::

## :rocket:參考程式(二)
* 使用Output CheckPoint

#### step1:
![](https://i.imgur.com/IIHBtTp.png)

#### step2:選擇檔案，設定參數
![](https://i.imgur.com/F9XUe8y.png)

![](https://i.imgur.com/W62beFV.png)

![](https://i.imgur.com/NZUuIMx.png)


#### step3:產生此code
```
FileContent("Test123").Output CheckPoint("Test123")
```

:::info
此方法 **無須** Adobe Acrobat Pro。
:::

## Appendix and FAQ

:::info
**Find this document incomplete?** Leave a comment!
:::

###### tags: `UFT`,`GUItest`
